Module base
Module graphdb
GraphDBKnowledgeGraph Objects
class GraphDBKnowledgeGraph(BaseKnowledgeGraph)
Knowledge graph store that runs on a GraphDB instance
__init__
| __init__(host: str = "localhost", port: int = 7200, username: str = "", password: str = "", index: Optional[str] = None, prefixes: str = "")
Init the knowledge graph by defining the settings to connect with a GraphDB instance
Arguments:
host
: address of server where the GraphDB instance is runningport
: port where the GraphDB instance is runningusername
: username to login to the GraphDB instance (if any)password
: password to login to the GraphDB instance (if any)index
: name of the index (also called repository) stored in the GraphDB instanceprefixes
: definitions of namespaces with a new line after each namespace, e.g., PREFIX hp: https://deepset.ai/harry_potter/
create_index
| create_index(config_path: Path)
Create a new index (also called repository) stored in the GraphDB instance
Arguments:
config_path
: path to a .ttl file with configuration settings, details: https://graphdb.ontotext.com/documentation/free/configuring-a-repository.html#configure-a-repository-programmatically
delete_index
| delete_index()
Delete the index that GraphDBKnowledgeGraph is connected to. This method deletes all data stored in the index.
import_from_ttl_file
| import_from_ttl_file(index: str, path: Path)
Load an existing knowledge graph represented in the form of triples of subject, predicate, and object from a .ttl file into an index of GraphDB
Arguments:
index
: name of the index (also called repository) in the GraphDB instance where the imported triples shall be storedpath
: path to a .ttl containing a knowledge graph
get_all_triples
| get_all_triples(index: Optional[str] = None)
Query the given index in the GraphDB instance for all its stored triples. Duplicates are not filtered.
Arguments:
index
: name of the index (also called repository) in the GraphDB instance
Returns:
all triples stored in the index
get_all_subjects
| get_all_subjects(index: Optional[str] = None)
Query the given index in the GraphDB instance for all its stored subjects. Duplicates are not filtered.
Arguments:
index
: name of the index (also called repository) in the GraphDB instance
Returns:
all subjects stored in the index
get_all_predicates
| get_all_predicates(index: Optional[str] = None)
Query the given index in the GraphDB instance for all its stored predicates. Duplicates are not filtered.
Arguments:
index
: name of the index (also called repository) in the GraphDB instance
Returns:
all predicates stored in the index
get_all_objects
| get_all_objects(index: Optional[str] = None)
Query the given index in the GraphDB instance for all its stored objects. Duplicates are not filtered.
Arguments:
index
: name of the index (also called repository) in the GraphDB instance
Returns:
all objects stored in the index
query
| query(sparql_query: str, index: Optional[str] = None)
Execute a SPARQL query on the given index in the GraphDB instance
Arguments:
sparql_query
: SPARQL query that shall be executedindex
: name of the index (also called repository) in the GraphDB instance
Returns:
query result