frex.services package
Subpackages
Submodules
frex.services.domain_kg_query_service module
- class frex.services.domain_kg_query_service.DomainKgQueryService(**kwargs)[source]
Bases:
frex.services._graph_query_service._GraphQueryService
DomainKgQueryService is a basic implementation for a querying service over a knowledge graph. The functions implemented here do not consider any optimization or complicated queries, but rather it provides the most basic baseline to get triples directly connected to a given target URI and convert the results into the appropriate domain model.
- get_all_objects_by_class(*, target_class_uri: rdflib.term.URIRef, object_type: Type[frex.services.domain_kg_query_service.T]) Generator[frex.services.domain_kg_query_service.T, None, None] [source]
Query the KG for all entities of a specified class, then convert them to their corresponding python objects and return them.
- Parameters
target_class_uri – The URI of the target class for which you want to retrieve all entities
object_type – The type of the domain object that you want to return.
- Returns
a generator that produces DomainObjects of the specified type for all entities of the specified class
- get_object_by_uri(*, target_uri: rdflib.term.URIRef, object_type: Type[frex.services.domain_kg_query_service.T]) frex.services.domain_kg_query_service.T [source]
Query the KG for a target URI, and return a python object corresponding to the result of that query.
The implementation for automatically going from a query result to python object relies on a dictionary of property URIs and their corresponding argument names in to populate in the DomainObject dataclass. This dictionary is produced by the ClassGenerator utility. If the class for your domain objects were made by hand, the corresponding methods for converting the results into an appropriate form should probably also be implemented manually as well.
- Parameters
target_uri – The URI of the target object for which you want to retrieve information
object_type – The type of the domain object that you want to return.
- Returns
a DomainObject, of type specified by the input arguments, corresponding to the target URI.