-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add base class for handling triples extraction from text
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters