olaf.repository.serialiser.rdf_owl_serialisers package¶
Submodules¶
olaf.repository.serialiser.rdf_owl_serialisers.base_owl_serialiser module¶
- class olaf.repository.serialiser.rdf_owl_serialisers.base_owl_serialiser.BaseOWLSerialiser(base_uri: str, metarelation_map: Dict[str, Namespace] | None = None, keep_all_labels: bool | None = True)[source]¶
Bases:
object
Serialize KnowledgeRepresentation data into an RDF graph following the OWL language.
This class provides methods to build an RDF graph following the OWL language from a KnowledgeRepresentation (KR) instance and export it in various RDF formats. It allows users to represent concepts, relations, and metarelations as RDF triples based on a specified base URI.
Attributes¶
- base_uriURIRef
The base URI to be used for constructing RDF URIs.
- graphGraph
An RDFlib Graph for storing the RDF triples.
- metarelation_mapDict[str, Namespace], optional
A dictionary mapping metarelation labels to RDF namespaces, by default None. If not provided, it uses a default mapping for “is_generalised_by” metarelations.
- keep_all_labelsbool, optional
A boolean indicating whether to to include all labels for concepts and their different linguistic realisations as SKOS altLabels, by default True.
Notes¶
This class is designed to serialize KR data into RDF following the OWL language as follow: - All concepts will be considered OWL classes. - All relations will be considered OWL object properties. - All metarelations will be considered OWL object properties unless they have a mapping
specified in the metarelation_map attribute.
- build_concept_uri(concept: Concept) URIRef [source]¶
Build a URI for a concept based on its label.
Parameters¶
- conceptConcept
The concept instance for which to build a URI.
Returns¶
- URIRef
The constructed URI for the concept.
- build_graph(kr: KnowledgeRepresentation) None [source]¶
Build the RDF graph from a KnowledgeRepresentation instance.
Parameters¶
- krKnowledgeRepresentation
The KnowledgeRepresentation instance containing concepts, relations, and metarelations.
- build_metarelation_uri(metarelation: Metarelation) URIRef [source]¶
Build a URI for a metarelation based on its label.
Parameters¶
- metarelationMetarelation
The metarelation instance for which to build a URI.
Returns¶
- URIRef
The constructed URI for the metarelation.
- build_relation_uri(relation: Relation) URIRef [source]¶
Build a URI for a relation based on its label.
Parameters¶
- relationRelation
The relation instance for which to build a URI.
Returns¶
- URIRef
The constructed URI for the relation.
- export_graph(file_path: str, rdf_format: str = 'turtle') None [source]¶
Export the RDF graph to a specified file path and RDF format. Available formats are the ones defined in RDFlib, see: <https://rdflib.readthedocs.io/en/stable/plugin_serializers.html>
Parameters¶
- file_pathstr
The file path where the RDF graph will be exported.
- rdf_formatstr, optional
The RDF serialization format, e.g., ‘turtle’, ‘xml’, ‘json-ld’, by default ‘turtle’.
olaf.repository.serialiser.rdf_owl_serialisers.base_rdf_serialiser module¶
- class olaf.repository.serialiser.rdf_owl_serialisers.base_rdf_serialiser.BaseRDFserialiser(base_uri: str)[source]¶
Bases:
object
Serialize KnowledgeRepresentation data into RDF graph.
This class provides methods to build an RDF graph from a KnowledgeRepresentation (KR) instance and export it in various RDF formats. It allows users to represent concepts, relations, and metarelations as RDF triples based on a specified base URI.
Attributes¶
- base_uriURIRef
The base URI to be used for constructing RDF URIs.
- graphGraph
An RDFlib Graph for storing the RDF triples.
- build_concept_uri(concept: Concept) URIRef [source]¶
Build a URI for a concept based on its label.
Parameters¶
- conceptConcept
The concept instance for which to build a URI.
Returns¶
- URIRef
The constructed URI for the concept.
- build_graph(kr: KnowledgeRepresentation) None [source]¶
Build the RDF graph from a KnowledgeRepresentation instance.
Parameters¶
- krKnowledgeRepresentation
The KnowledgeRepresentation instance containing concepts, relations, and metarelations.
- build_metarelation_uri(metarelation: Metarelation) URIRef [source]¶
Build a URI for a metarelation based on its label.
Parameters¶
- metarelationMetarelation
The metarelation instance for which to build a URI.
Returns¶
- URIRef
The constructed URI for the metarelation.
- build_relation_uri(relation: Relation) URIRef [source]¶
Build a URI for a relation based on its label.
Parameters¶
- relationRelation
The relation instance for which to build a URI.
Returns¶
- URIRef
The constructed URI for the relation.
- export_graph(file_path: str, rdf_format: str = 'turtle') None [source]¶
Export the RDF graph to a specified file path and RDF format. Available formats are the ones defined in RDFlib, see: <https://rdflib.readthedocs.io/en/stable/plugin_serializers.html>
Parameters¶
- file_pathstr
The file path where the RDF graph will be exported.
- rdf_formatstr, optional
The RDF serialization format, e.g., ‘turtle’, ‘xml’, ‘json-ld’, by default ‘turtle’.
olaf.repository.serialiser.rdf_owl_serialisers.domain_range_owl_serialiser module¶
- class olaf.repository.serialiser.rdf_owl_serialisers.domain_range_owl_serialiser.DomainRangeOWLSerialiser(base_uri: str, metarelation_map: Dict[str, Namespace] | None = None, keep_all_labels: bool = True)[source]¶
Bases:
BaseOWLSerialiser
Serialize KnowledgeRepresentation data into an RDF graph following the OWL language.
This class provides methods to build an RDF graph following the OWL language from a KnowledgeRepresentation (KR) instance and export it in various RDF formats. It allows users to represent concepts, relations, and metarelations as RDF triples based on a specified base URI. This serialiser makes sure relations have source and destination concepts as domain and range.
Attributes¶
- base_uriURIRef
The base URI to be used for constructing RDF URIs.
- graphGraph
An RDFlib Graph for storing the RDF triples.
- metarelation_mapDict[str, Namespace], optional
A dictionary mapping metarelation labels to RDF namespaces, by default None. If not provided, it uses a default mapping for “is_generalised_by” metarelations.
- keep_all_labelsbool, optional
A boolean indicating whether to to include all labels for concepts and their different linguistic realisations as SKOS altLabels, by default True.
Notes¶
This class is designed to serialize KR data into RDF following the OWL language as follow: - All concepts will be considered OWL classes. - All relations will be considered OWL object properties. - All relations will have the source concept class as RDFS domain - All relations will have the destination concept class as RDFS range - All metarelations will be considered OWL object properties unless they have a mapping
specified in the metarelation_map attribute.