diff --git a/ovos_plugin_manager/templates/triples.py b/ovos_plugin_manager/templates/triples.py new file mode 100644 index 00000000..44055179 --- /dev/null +++ b/ovos_plugin_manager/templates/triples.py @@ -0,0 +1,14 @@ +import abc + +from typing import Tuple, List, Iterable + + +class TriplesExtractor: + + def __init__(self, config=None): + self.config = config or {} + self.first_person_token = self.config.get("first_person_token", "USER") + + @abc.abstractmethod + def extract_triples(self, documents: List[str]) -> Iterable[Tuple[str, str, str]]: + """Extract semantic triples from a list of documents.""" diff --git a/ovos_plugin_manager/triples.py b/ovos_plugin_manager/triples.py new file mode 100644 index 00000000..4cd47074 --- /dev/null +++ b/ovos_plugin_manager/triples.py @@ -0,0 +1,40 @@ +from ovos_plugin_manager.templates.triples import TriplesExtractor +from ovos_plugin_manager.utils import PluginTypes, PluginConfigTypes + + +def find_triples_plugins() -> dict: + """ + Find all installed plugins + @return: dict plugin names to entrypoints + """ + from ovos_plugin_manager.utils import find_plugins + return find_plugins(PluginTypes.COREFERENCE_SOLVER) + + +def load_triples_plugin(module_name: str) -> type(TriplesExtractor): + """ + Get an uninstantiated class for the requested module_name + @param module_name: Plugin entrypoint name to load + @return: Uninstantiated class + """ + from ovos_plugin_manager.utils import load_plugin + return load_plugin(module_name, PluginTypes.COREFERENCE_SOLVER) + + +def get_triples_configs() -> dict: + """ + Get valid plugin configurations by plugin name + @return: dict plugin names to list of dict configurations + """ + from ovos_plugin_manager.utils.config import load_configs_for_plugin_type + return load_configs_for_plugin_type(PluginTypes.TRIPLES) + + +def get_triples_module_configs(module_name: str) -> dict: + """ + Get valid configuration for the specified plugin + @param module_name: plugin to get configuration for + @return: dict configuration (if provided) + """ + from ovos_plugin_manager.utils.config import load_plugin_configs + return load_plugin_configs(module_name, PluginConfigTypes.TRIPLES, True) diff --git a/ovos_plugin_manager/utils/__init__.py b/ovos_plugin_manager/utils/__init__.py index 8972c4bf..a07e6902 100644 --- a/ovos_plugin_manager/utils/__init__.py +++ b/ovos_plugin_manager/utils/__init__.py @@ -22,6 +22,7 @@ class PluginTypes(str, Enum): + TRIPLES = "opm.triples" PIPELINE = "opm.pipeline" EMBEDDINGS = "opm.embeddings" FACE_EMBEDDINGS = "opm.embeddings.face" @@ -64,6 +65,7 @@ class PluginTypes(str, Enum): class PluginConfigTypes(str, Enum): + TRIPLES = "opm.triples.config" PIPELINE = "opm.pipeline.config" EMBEDDINGS = "opm.embeddings.config" FACE_EMBEDDINGS = "opm.embeddings.face.config"