Source code for ordf.namespace

Namespace Declarations

In addition to the following RDF namespace declarations, this module
conveniently works around some refactoring that `RDFLib`_ has experienced
to make importing the :class:`~rdflib.namespace.Namespace` class more

.. autofunction:: bind_ns
.. autofunction:: register_ns

.. data:: namespaces

A dictionary containing all of the namespaces defined here. The keys are the
names of the namespaces and the values are the namespaces themselves.

.. data:: BIBO
.. data:: BIO
.. data:: CS
.. data:: DBPPROP
.. data:: DCES
.. data:: DC
.. data:: DCAM
.. data:: DOAP
.. data:: FOAF
.. data:: FRBR
.. data:: FRESNEL
.. data:: GND
.. data:: GR
.. data:: LIST
.. data:: LOG
.. data:: OPMV
.. data:: ORDF
.. data:: ORE
.. data:: OWL
.. data:: RDAGR2
.. data:: RDARELGR2
.. data:: SCOVO
.. data:: SKOS
.. data:: TRIG
.. data:: VOID
.. data:: WOT
.. data:: UUID

.. _RDFLib:

    from rdflib.namespace import Namespace, RDF, RDFS, XSD
except ImportError:
    from rdflib import Namespace
    RDF = Namespace('')
    RDFS = Namespace('')
    XSD = Namespace('')

BIBO = Namespace("")
BIO = Namespace("")
CS = Namespace("")
DBPPROP = Namespace("")
DCES = Namespace("")
DC = Namespace("")
DCAM = Namespace("")
DOAP = Namespace("")
FOAF = Namespace("")
FRBR = Namespace("")
FRESNEL = Namespace("")
GND = Namespace("")
GR = Namespace("")
ICAL = Namespace("")
LIST = Namespace("")
LOG = Namespace("")
OPMV = Namespace("")
ORDF = Namespace("")
ORE = Namespace("")
OWL = Namespace("")
RDAGR2 = Namespace("")
RDARELGR2 = Namespace("")
RDFG = Namespace("")
RELATIONSHIP = Namespace("")
REV = Namespace("")
SCOVO = Namespace("")
SIOC = Namespace("")
SKOS = Namespace("")
TIME = Namespace("")
VOID = Namespace("")
WOT = Namespace("")

UUID = Namespace("urn:uuid:")

namespaces = {
    "rdf": RDF,
    "rdfs": RDFS,
    "bibo": BIBO,
    "bio": BIO,
    "cs": CS,
    "dbpprop": DBPPROP,
    "dces": DCES,
    "dc": DC,
    "dcam": DCAM,
    "doap": DOAP,
    "foaf": FOAF,
    "frbr": FRBR,
    "fresnel": FRESNEL,
    "gnd": GND,
    "gr": GR,
    "ical": ICAL,
    "list": LIST,
    "log": LOG,
    "opmv": OPMV,
    "ordf": ORDF,
    "ore": ORE,
    "owl": OWL,
    "rdaGr2": RDAGR2,
    "rdaRelGr2": RDARELGR2,
    "rdfg": RDFG,
    "relationship": RELATIONSHIP,
    "rev": REV,
    "scovo": SCOVO,
    "sioc": SIOC,
    "skos": SKOS,
    "time": TIME,
    "uuid": UUID,
    "void": VOID,
    "wot": WOT,
    "xsd": XSD

[docs]def bind_ns(g, namespaces=namespaces): """ Given an :class:`~rdflib.graph.Graph`, bind the namespaces present in the dictionary in this module to it for more readable serialisations. :param g: an instance of :class:`rdflib.graph.Graph`. """ try: [g.bind(*x) for x in namespaces.items()] except: ### XXX sometimes gives errors with rdflib sleepycat !? pass
[docs]def register_ns(prefix, ns): """ Register a namespace for use by ORDF :param prefix: the namespace prefix that should be used :param namespace: an instance of ordf.namespace.Namespace """ from ordf import namespace from logging import getLogger log = getLogger("ordf.namespace") ns = Namespace(str(ns)) if hasattr(namespace, prefix.upper()): log.warning("Registering %s: <%s> prefix already exists" % (prefix, ns)) log.debug("Registering %s: <%s>" % (prefix, ns)) setattr(namespace, prefix.upper().replace("-", "_"), ns) namespaces[prefix] = ns
def _init_ns(): import pkg_resources for entrypoint in pkg_resources.iter_entry_points(group="ordf.namespace"): init_ns = entrypoint.load() init_ns() register_ns("sdmx", Namespace("")) register_ns("sdmxconcept", Namespace("")) register_ns("sdmxdim", Namespace("")) register_ns("sdmxattr", Namespace("")) register_ns("sdmxmeasure", Namespace("")) register_ns("sdmxcode", Namespace("")) register_ns("sdmxsubject", Namespace("")) register_ns("wdrs", Namespace(""))