Skip to content

Commit

Permalink
feat/triples_plugins (#257)
Browse files Browse the repository at this point in the history
add base class for handling triples extraction from text
  • Loading branch information
JarbasAl authored Sep 10, 2024
1 parent 78de153 commit de19fb3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ovos_plugin_manager/templates/triples.py
Original file line number Diff line number Diff line change
@@ -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."""
40 changes: 40 additions & 0 deletions ovos_plugin_manager/triples.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions ovos_plugin_manager/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


class PluginTypes(str, Enum):
TRIPLES = "opm.triples"
PIPELINE = "opm.pipeline"
EMBEDDINGS = "opm.embeddings"
FACE_EMBEDDINGS = "opm.embeddings.face"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit de19fb3

Please sign in to comment.