Derivation
Derivation ¶
Wrapper class for uk.ac.cam.cares.jps.base.derivation.Derivation.java
.
This class provides a simplified interface for interacting with the Derivation object returned when creating synchronous derivations for new information.
Only two methods are provided here, all other methods in Java can be accessed via self.derivation.nameOfJavaMethod(args)
.
Methods:
Name | Description |
---|---|
getIri |
Returns the IRI of the Derivation instance |
getBelongsToIris |
Returns the IRIs of the entities that belong to the Derivation instance |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
derivation_java
|
The Java derivation object |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
getIri ¶
getIri() -> str
Returns the IRI of the Derivation instance.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
IRI of the Derivation instance |
getBelongsToIris ¶
Returns the IRIs of the entities that belongsTo the Derivation instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputRdfType
|
str
|
IRI of the rdf:type of the entities that belongsTo the Derivation instance |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of IRIs of the entities that belongsTo the Derivation instance |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
DerivationInputs ¶
Wrapper class for uk.ac.cam.cares.jps.base.derivation.DerivationInputs.java
.
This class provides methods to handle derivations within Python derivation agents, referencing to the corresponding methods in the Java class. For implementation details, please refer to the Java code.
Methods:
Name | Description |
---|---|
getDerivationIRI |
Returns the IRI of the derivation. |
getInputs |
Returns the inputs of the derivation as a dictionary. |
getIris |
Returns the IRIs of the inputs of the specified rdf:type. |
get_inputs_ogm_by_rdf_type |
Returns the inputs as objects of the specified rdf:type. |
get_inputs_ogm |
Returns the inputs as objects of the specified class. |
get_inputs_ogm_assume_one |
Returns a single input object of the specified class. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
derivationInputs
|
The Java DerivationInputs object |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
getDerivationIRI ¶
getDerivationIRI() -> str
getInputs ¶
getIris ¶
Returns the IRIs of the inputs of the specified rdf:type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rdfType
|
str
|
IRI of the rdf:type of the inputs |
required |
Returns:
Type | Description |
---|---|
Union[List[str], None]
|
List[str]: List of IRIs of the inputs, or None if no inputs are found |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
get_inputs_ogm_by_rdf_type ¶
get_inputs_ogm_by_rdf_type(rdf_type: str, sparql_client, recursive_depth: int = 0) -> List[BaseClass]
Returns the inputs as objects of the specified rdf:type (when using object graph mapper).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rdf_type
|
str
|
IRI of the rdf:type |
required |
sparql_client
|
The SPARQL client to query the knowledge graph |
required | |
recursive_depth
|
int
|
The depth of recursive queries (default is 0) |
0
|
Returns:
Type | Description |
---|---|
List[BaseClass]
|
List[BaseClass]: List of objects of the specified rdf:type |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
get_inputs_ogm ¶
Returns the inputs as objects of the specified class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clz
|
Type[_T]
|
The class of the objects to return |
required |
sparql_client
|
The SPARQL client to query the knowledge graph |
required | |
recursive_depth
|
int
|
The depth of recursive queries (default is 0) |
0
|
Returns:
Type | Description |
---|---|
List[_T]
|
List[_T]: List of objects of the specified class |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
get_inputs_ogm_assume_one ¶
Returns a single input object of the specified class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clz
|
Type[_T]
|
The class of the object to return |
required |
sparql_client
|
The SPARQL client to query the knowledge graph |
required | |
recursive_depth
|
int
|
The depth of recursive queries (default is 0) |
0
|
Raises:
Type | Description |
---|---|
Exception
|
If the number of objects found is not exactly one |
Returns:
Name | Type | Description |
---|---|---|
_T |
_T
|
The single object of the specified class |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
DerivationOutputs ¶
Wrapper class for uk.ac.cam.cares.jps.base.derivation.DerivationOutputs.java
.
This class provides methods to handle derivations within Python derivation agents, referencing to the corresponding methods in the Java class. For implementation details, please refer to the Java code.
Methods:
Name | Description |
---|---|
createNewEntity |
Creates a new entity with the given IRI and rdf:type. |
createNewEntityWithBaseUrl |
Creates a new entity with a base URL and rdf:type. |
addTriple |
Adds a triple to the derivation outputs. |
addLiteral |
Adds a literal to the derivation outputs. |
addLiteralWithDataType |
Adds a literal with a specified data type to the derivation outputs. |
addGraph |
Adds a whole rdflib.Graph to the derivation outputs. |
add_outputs_ogm |
Adds objects of a specified class to the derivation outputs. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
derivationOutputs
|
The Java DerivationOutputs object |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
createNewEntity ¶
createNewEntityWithBaseUrl ¶
Creates a new entity with the given base URL and rdf:type, adds the new entity to derivation outputs, then returns the initialised IRI.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
baseUrl
|
str
|
Base URL for the new entity |
required |
rdfType
|
str
|
IRI of the rdf:type of the new entity |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
IRI of the newly created entity. |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
addTriple ¶
Adds a triple to the derivation outputs. Note that only one addTriple function is provided here, the two functions taking TriplePattern is NOT provided for simplicity of java-python data structure conversion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Subject of the triple |
required |
p
|
str
|
Predicate of the triple |
required |
o
|
str
|
Object of the triple |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
addLiteral ¶
Adds a literal to the derivation outputs. Note that only one addLiteral is provided here as the correct method to use will be decided by java automatically.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Subject of the triple |
required |
p
|
str
|
Predicate of the triple |
required |
o
|
Union[str, Literal]
|
Literal object of the triple |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
addLiteralWithDataType ¶
Adds a literal with a specified data type to the derivation outputs.
Note that this method corresponds to addLiteral(String, String, String, String) in DerivationOutputs.java
,
but renamed in python due to limitations of overloading in python.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
str
|
Subject of the triple |
required |
p
|
str
|
Predicate of the triple |
required |
o
|
str
|
Literal object of the triple |
required |
dataType
|
str
|
Data type of the literal |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
addGraph ¶
Adds a whole rdflib.Graph to the derivation outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
Graph
|
The graph to add to the derivation outputs |
required |
Source code in JPS_BASE_LIB/python_wrapper/twa/data_model/derivation.py
add_outputs_ogm ¶
Adds objects of a specified class to the derivation outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objects
|
Union[BaseClass, List[BaseClass]]
|
The objects to add to the derivation outputs |
required |