SparqlClient
PySparqlClient ¶
PySparqlClient(query_endpoint: str, update_endpoint: str, kg_user: str = None, kg_password: str = None, fs_url: str = None, fs_user: str = None, fs_pwd: str = None)
The purpose of this class is to provide a Python interface to the Java-based RemoteStoreClient for querying and updating the knowledge graph (triplestore).
Attributes:
Name | Type | Description |
---|---|---|
jpsBaseLib_view |
JVM
|
The module view for the JpsBaseLib |
kg_client |
RemoteStoreClient
|
The Java-based uk.ac.cam.cares.jps.base.query.RemoteStoreClient object |
query_endpoint |
str
|
The SPARQL query endpoint of the knowledge graph |
update_endpoint |
str
|
The SPARQL update endpoint of the knowledge graph |
fs_url |
str
|
The URL of the fileserver |
fs_auth |
str
|
The authentication information for the fileserver |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_endpoint
|
str
|
The SPARQL query endpoint of the knowledge graph |
required |
update_endpoint
|
str
|
The SPARQL update endpoint of the knowledge graph |
required |
kg_user
|
str
|
The username for the knowledge graph |
None
|
kg_password
|
str
|
The password for the knowledge graph |
None
|
fs_url
|
str
|
The URL of the fileserver |
None
|
fs_user
|
str
|
The username for the fileserver |
None
|
fs_pwd
|
str
|
The password for the fileserver |
None
|
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
check_instance_class ¶
This method checks if the given instance is instantiated from the given instance class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance
|
str
|
IRI of an instance |
required |
instance_class
|
str
|
IRI of the instance class to be checked against |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the instance is instantiated from the given instance class, False otherwise |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
get_amount_of_triples ¶
get_amount_of_triples() -> int
This method returns the total number of triples in the knowledge graph.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The total number of triples in the knowledge graph |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
perform_query ¶
perform_update ¶
perform_update(update: str) -> None
This function performs SPARQL Update to knowledge graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
update
|
str
|
SPARQL Update string |
required |
get_all_instances_of_class ¶
This function returns all instances of the given class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_iri
|
str
|
IRI of the class |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of IRIs of all instances of the given class |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
upload_ontology ¶
upload_ontology(file_path: str) -> None
This function uploads ontology to knowledge graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The file path of ontology to be uploaded |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
upload_file ¶
This function uploads the file at the given local file path to file server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_file_path
|
str
|
The local file path of the file to be uploaded |
required |
filename_with_subdir
|
str
|
The filename with subdirectory in the file server |
None
|
Returns:
Type | Description |
---|---|
Tuple[str, float]
|
Tuple[str, float]: The remote file path and the timestamp when the file was uploaded |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
download_file ¶
This function downloads a file given the remote file path and the local file path to store the downloaded file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_file_path
|
str
|
The remote file path of the file to be downloaded |
required |
downloaded_file_path
|
str
|
The local file path to store the downloaded file |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
upload_graph ¶
This function uploads the given graph to the knowledge graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
Graph
|
The rdflib.Graph object to be uploaded |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
delete_graph ¶
This function deletes the triples in the graph provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
Graph
|
The rdflib.Graph object to be deleted |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
delete_and_insert_graphs ¶
This function deletes the triples in the first graph and inserts the triples in the second graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g_to_delete
|
Graph
|
The rdflib.Graph object to be deleted |
required |
g_to_insert
|
Graph
|
The rdflib.Graph object to be inserted |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
check_if_triple_exist ¶
This function checks if the given triple exists in the knowledge graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Subject IRI |
required |
p
|
str
|
Predicate IRI |
required |
o
|
Any
|
Object IRI or literal value |
required |
data_type
|
str
|
Data type of the object literal |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the triple exists, False otherwise |
Source code in JPS_BASE_LIB/python_wrapper/twa/kg_operations/sparql_client.py
get_outgoing_and_attributes ¶
This function returns the outgoing edges and attributes of the given nodes in the knowledge graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_iris
|
Set[str]
|
The set of IRIs of the nodes |
required |
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, Set[Any]]]
|
Dict[str, Dict[str, Set[Any]]]: The dictionary of the outgoing edges and attributes of the given nodes, where the key is the node IRI |