spotterbase.rdf package
Submodules
spotterbase.rdf.bnode module
Provides RDF blank nodes.
spotterbase.rdf.from_rdflib module
spotterbase.rdf.literal module
- class spotterbase.rdf.literal.HtmlFragment(value: _Element | str, wrapped_in_div: bool | None = None)
Bases:
objectValue corresponding to rdf:HTML.
This is still somewhat improvised. One requirement is that, unlike rdflib, I want to support lxml. Another requirement is that I want this to be lazy. I don’t think lxml supports document fragments very much, so as a work-around, we will wrap the fragment into a <div> (as is also done e.g. by lxml.html.diff.[parse_html/serialize_html_fragment]).
- get_literal_string() str
- get_wrapped_lxml_element() _Element
spotterbase.rdf.namespace_collection module
- class spotterbase.rdf.namespace_collection.NameSpaceCollection(namespaces: list[NameSpace] | None = None)
Bases:
object- classmethod from_turtle(turtle: str) NameSpaceCollection
This extracts name spaces from the @prefix directives in a turtle string.
Note: It only supports a “reasonable” subset of turtle.
- namespacify(uri: str | Uri | URIRef | Path | VocabularyMeta) Uri
spotterbase.rdf.serializer module
- class spotterbase.rdf.serializer.FileSerializer(path: Path | str, append: bool = False)
Bases:
Serializer- close()
- flush()
- write_comment(s: str)
- class spotterbase.rdf.serializer.NTriplesSerializer(fp: TextIO)
Bases:
Serializer- write_comment(s: str)
- class spotterbase.rdf.serializer.PickleSerializer(fp: BinaryIO)
Bases:
Serializer
- class spotterbase.rdf.serializer.TurtleSerializer(fp: TextIO, buffer_size: int = 1024, fixed_prefixes: Iterable[NameSpace] | None = None, write_prefixes: bool = True)
Bases:
Serializer- flush()
- write_comment(s: str)
- spotterbase.rdf.serializer.triples_from_pickle(file: BinaryIO | Path) Iterable[tuple[Uri | BlankNode, Uri, Uri | BlankNode | Literal]]
spotterbase.rdf.to_rdflib module
This module provides a converter for converting to rdflib.
This is largely trivial, but it makes the conversion a more convenient. It also maintains a state to make sure that a blank node is always mapped to the same blank node.
Since rdflib.term.Node accepts a value argument, we might actually be able to do the whole thing without maintaining a state…
spotterbase.rdf.types module
spotterbase.rdf.uri module
- class spotterbase.rdf.uri.NameSpace(uri: Uri | str, prefix: str | None = None)
Bases:
object- property prefix: str | None
- class spotterbase.rdf.uri.Uri(uri: str | Uri | URIRef | Path | VocabularyMeta, namespace: NameSpace | None = None)
Bases:
object- classmethod maybe(uri: str | Uri | URIRef | Path | VocabularyMeta | None) Uri | None
- sha256_as_int() int
- to_rdflib() URIRef
- class spotterbase.rdf.uri.VocabularyMeta
Bases:
type
spotterbase.rdf.visualize module
- spotterbase.rdf.visualize.rdf_node_to_string(rdfnode: Uri | BlankNode | Literal, namespacecollection: NameSpaceCollection | None, relaxed_labels: bool) str
spotterbase.rdf.vocab module
Commonly used RDF vocabularies (automatically generated)
- class spotterbase.rdf.vocab.AS
Bases:
VocabularyGenerated from https://raw.githubusercontent.com/w3c/activitystreams/master/vocabulary/activitystreams2.owl
- class spotterbase.rdf.vocab.DC
Bases:
VocabularyGenerated from https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_elements.ttl
- class spotterbase.rdf.vocab.DCAM
Bases:
VocabularyGenerated from https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_abstract_model.ttl
- class spotterbase.rdf.vocab.DCTERMS
Bases:
VocabularyGenerated from http://dublincore.org/2020/01/20/dublin_core_terms.ttl
- class spotterbase.rdf.vocab.DCTYPES
Bases:
VocabularyGenerated from https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_type.ttl
- class spotterbase.rdf.vocab.DCTerms
Bases:
VocabularyGenerated from https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_terms.nt
- class spotterbase.rdf.vocab.DCTypes
Bases:
VocabularyGenerated from https://www.dublincore.org/specifications/dublin-core/dcmi-terms/dublin_core_type.nt
- class spotterbase.rdf.vocab.FOAF
Bases:
VocabularyGenerated from http://xmlns.com/foaf/0.1/index.rdf
- class spotterbase.rdf.vocab.OWL
Bases:
VocabularyGenerated from http://www.w3.org/2002/07/owl#
- class spotterbase.rdf.vocab.RDF
Bases:
VocabularyGenerated from http://www.w3.org/1999/02/22-rdf-syntax-ns#
- class spotterbase.rdf.vocab.RDFS
Bases:
VocabularyGenerated from http://www.w3.org/2000/01/rdf-schema#
- class spotterbase.rdf.vocab.SKOS
Bases:
VocabularyGenerated from https://www.w3.org/2009/08/skos-reference/skos.rdf
- class spotterbase.rdf.vocab.XSD
Bases:
Vocabulary
spotterbase.rdf.vocabulary_from_ontology module
A very hacky script to generate classes for commonly used vocabularies.
- spotterbase.rdf.vocabulary_from_ontology.create_from(ontology: str, namespace: str)
- spotterbase.rdf.vocabulary_from_ontology.main()
- spotterbase.rdf.vocabulary_from_ontology.result_rows(query_result: Result) list[ResultRow]
needed to make mypy happy
Module contents
- spotterbase.rdf.as_uri(uri: str | Uri | URIRef | Path | VocabularyMeta, namespace_collection: NameSpaceCollection = StandardNameSpaces) Uri