rdflib.namespace package¶
Module contents¶
Namespace Utilities¶
RDFLib provides mechanisms for managing Namespaces.
In particular, there is a Namespace
class
that takes as its argument the base URI of the namespace.
>>> from rdflib.namespace import Namespace
>>> RDFS = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
Fully qualified URIs in the namespace can be constructed either by attribute or by dictionary access on Namespace instances:
>>> RDFS.seeAlso
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#seeAlso')
>>> RDFS['seeAlso']
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#seeAlso')
Automatic handling of unknown predicates¶
As a programming convenience, a namespace binding is automatically
created when rdflib.term.URIRef
predicates are added to the graph.
Importable namespaces¶
The following namespaces are available by directly importing from rdflib:
BRICK
CSVW
DC
DCAT
DCMITYPE
DCTERMS
DCAM
DOAP
FOAF
ODRL2
ORG
OWL
PROF
PROV
QB
RDF
RDFS
SDO
SH
SKOS
SOSA
SSN
TIME
VANN
VOID
XSD
- class rdflib.namespace.ClosedNamespace(uri, terms)[source]¶
Bases:
rdflib.namespace.Namespace
A namespace with a closed list of members
Trying to create terms not listed is an error
- __contains__(ref)[source]¶
Allows to check if a URI is within (starts with) this Namespace.
>>> from rdflib import URIRef >>> namespace = Namespace('http://example.org/') >>> uri = URIRef('http://example.org/foo') >>> uri in namespace True >>> person_class = namespace['Person'] >>> person_class in namespace True >>> obj = URIRef('http://not.example.org/bar') >>> obj in namespace False
- __module__ = 'rdflib.namespace'¶
- property uri¶
- class rdflib.namespace.Namespace(value)[source]¶
Bases:
str
Utility class for quickly generating URIRefs with a common prefix
>>> from rdflib.namespace import Namespace >>> n = Namespace("http://example.org/") >>> n.Person # as attribute rdflib.term.URIRef('http://example.org/Person') >>> n['first-name'] # as item - for things that are not valid python identifiers rdflib.term.URIRef('http://example.org/first-name') >>> n.Person in n True >>> n2 = Namespace("http://example2.org/") >>> n.Person in n2 False
- __annotations__ = {}¶
- __contains__(ref)[source]¶
Allows to check if a URI is within (starts with) this Namespace.
>>> from rdflib import URIRef >>> namespace = Namespace('http://example.org/') >>> uri = URIRef('http://example.org/foo') >>> uri in namespace True >>> person_class = namespace['Person'] >>> person_class in namespace True >>> obj = URIRef('http://not.example.org/bar') >>> obj in namespace False
- __dict__ = mappingproxy({'__module__': 'rdflib.namespace', '__doc__': '\n Utility class for quickly generating URIRefs with a common prefix\n\n >>> from rdflib.namespace import Namespace\n >>> n = Namespace("http://example.org/")\n >>> n.Person # as attribute\n rdflib.term.URIRef(\'http://example.org/Person\')\n >>> n[\'first-name\'] # as item - for things that are not valid python identifiers\n rdflib.term.URIRef(\'http://example.org/first-name\')\n >>> n.Person in n\n True\n >>> n2 = Namespace("http://example2.org/")\n >>> n.Person in n2\n False\n ', '__new__': <staticmethod object>, 'title': <property object>, 'term': <function Namespace.term>, '__getitem__': <function Namespace.__getitem__>, '__getattr__': <function Namespace.__getattr__>, '__repr__': <function Namespace.__repr__>, '__contains__': <function Namespace.__contains__>, '__dict__': <attribute '__dict__' of 'Namespace' objects>, '__weakref__': <attribute '__weakref__' of 'Namespace' objects>, '__annotations__': {}})¶
- __module__ = 'rdflib.namespace'¶
- __weakref__¶
list of weak references to the object (if defined)
- property title¶
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- class rdflib.namespace.NamespaceManager(graph)[source]¶
Bases:
object
Class for managing prefix => namespace mappings
Sample usage from FuXi …
ruleStore = N3RuleStore(additionalBuiltins=additionalBuiltins) nsMgr = NamespaceManager(Graph(ruleStore)) ruleGraph = Graph(ruleStore,namespace_manager=nsMgr)
and …
>>> import rdflib >>> from rdflib import Graph >>> from rdflib.namespace import Namespace, NamespaceManager >>> exNs = Namespace('http://example.com/') >>> namespace_manager = NamespaceManager(Graph()) >>> namespace_manager.bind('ex', exNs, override=False) >>> g = Graph() >>> g.namespace_manager = namespace_manager >>> all_ns = [n for n in g.namespace_manager.namespaces()] >>> assert ('ex', rdflib.term.URIRef('http://example.com/')) in all_ns >>>
- __dict__ = mappingproxy({'__module__': 'rdflib.namespace', '__doc__': "\n\n Class for managing prefix => namespace mappings\n\n Sample usage from FuXi ...\n\n .. code-block:: python\n\n ruleStore = N3RuleStore(additionalBuiltins=additionalBuiltins)\n nsMgr = NamespaceManager(Graph(ruleStore))\n ruleGraph = Graph(ruleStore,namespace_manager=nsMgr)\n\n\n and ...\n\n .. code-block:: pycon\n\n >>> import rdflib\n >>> from rdflib import Graph\n >>> from rdflib.namespace import Namespace, NamespaceManager\n >>> exNs = Namespace('http://example.com/')\n >>> namespace_manager = NamespaceManager(Graph())\n >>> namespace_manager.bind('ex', exNs, override=False)\n >>> g = Graph()\n >>> g.namespace_manager = namespace_manager\n >>> all_ns = [n for n in g.namespace_manager.namespaces()]\n >>> assert ('ex', rdflib.term.URIRef('http://example.com/')) in all_ns\n >>>\n\n ", '__init__': <function NamespaceManager.__init__>, '__contains__': <function NamespaceManager.__contains__>, 'reset': <function NamespaceManager.reset>, 'store': <property object>, 'qname': <function NamespaceManager.qname>, 'qname_strict': <function NamespaceManager.qname_strict>, 'normalizeUri': <function NamespaceManager.normalizeUri>, 'compute_qname': <function NamespaceManager.compute_qname>, 'compute_qname_strict': <function NamespaceManager.compute_qname_strict>, 'bind': <function NamespaceManager.bind>, 'namespaces': <function NamespaceManager.namespaces>, 'absolutize': <function NamespaceManager.absolutize>, '__dict__': <attribute '__dict__' of 'NamespaceManager' objects>, '__weakref__': <attribute '__weakref__' of 'NamespaceManager' objects>, '__annotations__': {}})¶
- __module__ = 'rdflib.namespace'¶
- __weakref__¶
list of weak references to the object (if defined)
- bind(prefix, namespace, override=True, replace=False)[source]¶
bind a given namespace to the prefix
if override, rebind, even if the given namespace is already bound to another prefix.
if replace, replace any existing prefix with the new namespace
- normalizeUri(rdfTerm) str [source]¶
Takes an RDF Term and ‘normalizes’ it into a QName (using the registered prefix) or (unlike compute_qname) the Notation 3 form for URIs: <…URI…>
- property store¶