class documentation

class RdfLibHandler(SemanticHandler):

Constructor: RdfLibHandler()

View In Hierarchy

A SemanticHandler implementation for the rdflib library.

Note

Only the in-memory storage method is supported.

Method __init__ Initializer for the RdfLibHandler class.
Method addDescription Add a semantic description to the graph store.
Method addParentID Add the parent ID to a resource's graph.
Method getAggregatedGraph Return an aggregated graph with all the triple for the individuel graphs for the list of resources indicated by their resource IDs.
Method getFormat Return a representation of a semantic format supported by the graph framework.
Method getGraph Find and return the stored graph with the given identifier.
Method query Run a SPARQL query against a graph.
Method removeDescription Remove a description from the graph store.
Method reset Reset the handler, remove all graphs etc.
Method updateDescription Update a description in the graph store.
Method validateDescription Validate a semantic description.
Class Variable __slots__ Slots for RdfLibHandler class.
Class Variable storeIdentifier The identifier for the graph stores.
Class Variable supportedFormats A map between the SemanticFormat enum and the rdflib string representation. Only the supported formats are listed here.
Instance Variable graph The root graph for the CSE.
Instance Variable store The store that stores the graphs. Only the in-memory storage method is supported.
Method _openStore Open the graph store.
def __init__(self):

Initializer for the RdfLibHandler class.

def addDescription(self, description: str, format: SemanticFormat, id: str):

Add a semantic description to the graph store.

Parameters
description:strA string with the semantic description.
format:SemanticFormatThe format of the string in description. It must be a supported format.
id:strIdentifier for the graph. It should be a resouce identifier.
Returns
A Result object. The query result is returned in its data attribute.
def addParentID(self, id: str, pi: str):

Add the parent ID to a resource's graph.

Parameters
id:strIdentifier for the graph. It should be a resouce identifier.
pi:strParent ID to add.
def getAggregatedGraph(self, ids: Sequence[str]) -> rdflib.Dataset | None:

Return an aggregated graph with all the triple for the individuel graphs for the list of resources indicated by their resource IDs.

Parameters
ids:Sequence[str]List of <semanticDescriptor> resource Identifiers.
Returns
rdflib.Dataset | NoneReturn a DataSet object with the aggregated graph, or None.
def getFormat(self, format: SemanticFormat) -> str | None:

Return a representation of a semantic format supported by the graph framework.

Parameters
format:SemanticFormatThe semantic format.
Returns
str | NoneA string representation of the format that is supported, or None if unsupported.
def getGraph(self, id: str) -> rdflib.Graph | None:

Find and return the stored graph with the given identifier.

Parameters
id:strThe graph's identifier.
Returns
rdflib.Graph | NoneA Graph object, or None.
def query(self, query: str, ids: Sequence[str], format: str) -> Result:

Run a SPARQL query against a graph.

Parameters
query:strSPARQL query.
ids:Sequence[str]List of resource / graph identifiers used to build the graph for the query.
format:strDesired serialization format for the result. It must be supported.
Returns
ResultResult object. The serialized query result is stored in data.
def removeDescription(self, id: str):

Remove a description from the graph store.

Parameters
id:strIdentifier for the graph. It should be a resouce identifier.
Returns
A Result object indicating success or error.
def reset(self):

Reset the handler, remove all graphs etc.

def updateDescription(self, description: str, format: SemanticFormat, id: str):

Update a description in the graph store.

Parameters
description:strA string with the semantic description.
format:SemanticFormatThe format of the string in description. It must be a supported format.
id:strIdentifier for the graph. It should be a resouce identifier.
Returns
A Result object indicating success or error.
def validateDescription(self, description: str, format: SemanticFormat):

Validate a semantic description.

Parameters
description:strA string with the semantic description.
format:SemanticFormatThe format of the string in description. It must be supported.
Returns
A Result object indicating a valid description, or with an error status.
__slots__: tuple[str, ...] =

Slots for RdfLibHandler class.

storeIdentifier: str =

The identifier for the graph stores.

supportedFormats =

A map between the SemanticFormat enum and the rdflib string representation. Only the supported formats are listed here.

graph =

The root graph for the CSE.

store =

The store that stores the graphs. Only the in-memory storage method is supported.

def _openStore(self):

Open the graph store.