本文整理汇总了Python中rdflib.Namespace方法的典型用法代码示例。如果您正苦于以下问题:Python rdflib.Namespace方法的具体用法?Python rdflib.Namespace怎么用?Python rdflib.Namespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib
的用法示例。
在下文中一共展示了rdflib.Namespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def __init__(self, user, repo):
"""Default constructor.
Keyword arguments:
user -- Github user.
repo -- Github repo.
"""
self.user = user
self.repo = repo
self.prov_g = Graph()
prov_uri = URIRef("http://www.w3.org/ns/prov#")
self.prov = Namespace(prov_uri)
self.prov_g.bind('prov', self.prov)
self.agent = URIRef("http://{}".format(static.SERVER_NAME))
self.entity_d = URIRef("http://{}/api/{}/{}/spec".format(static.SERVER_NAME, self.user, self.repo))
self.activity = URIRef(self.entity_d + "-activity")
self.init_prov_graph()
示例2: bind
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def bind(self, prefix, namespace):
"""
Bind a prefix to a namespace.
:param str prefix: Namespace prefix.
:param rdflib.URIRef namespace: Fully qualified URI of namespace.
"""
prefix = prefix.encode()
namespace = namespace.encode()
if self.is_txn_rw:
# FIXME DB labels should be constants but there are problems
# imprting them from the Cython module.
self.put(prefix, namespace, b'pfx:ns_')
self.put(namespace, prefix, b'ns:pfx_')
else:
#logger.debug('Opening RW transaction.')
with self.txn_ctx(write=True) as wtxn:
self.put(prefix, namespace, b'pfx:ns_')
self.put(namespace, prefix, b'ns:pfx_')
示例3: verify_rdf
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def verify_rdf(rdf_output):
ids_ns = Namespace("http://foo.example.org/CSV/People-IDs/")
ages_ns = Namespace("http://foo.example.org/CSV/People-Ages/")
g = ConjunctiveGraph()
g.parse(data=rdf_output, format="turtle")
all_subjects = {x for x in g.subjects()}
assert len(all_subjects) == 2
bob_subj = ids_ns['1']
joe_subj = ids_ns['2']
assert bob_subj in all_subjects
assert joe_subj in all_subjects
# Bob's details
assert len([g.triples((bob_subj, ids_ns.id, Literal(1)))]) == 1
assert len([g.triples((bob_subj, ids_ns.name, Literal("Bob")))]) == 1
assert len([g.triples((bob_subj, ages_ns.age, Literal(34)))]) == 1
# Joe's details
assert len([g.triples((joe_subj, ids_ns.id, Literal(2)))]) == 1
assert len([g.triples((joe_subj, ids_ns.name, Literal("Joe")))]) == 1
assert len([g.triples((joe_subj, ages_ns.age, Literal(54)))]) == 1
示例4: __init__
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def __init__(self, are_bnodes_skized=True, identifier=None):
# print("in RDFGraph with id: ", identifier)
super().__init__('IOMemory', identifier)
self.are_bnodes_skized = are_bnodes_skized
# Can be removed when this is resolved
# https://github.com/RDFLib/rdflib/issues/632
for pfx in ('OBO',): # , 'ORPHA'):
self.bind(pfx, Namespace(self.curie_map[pfx]))
# try adding them all
# self.bind_all_namespaces() # too much
示例5: _getnode
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def _getnode(self, curie): # convention is lowercase names
"""
This is a wrapper for creating a URIRef or Bnode object
with a given a curie or iri as a string.
If an id starts with an underscore, it assigns it to a BNode, otherwise
it creates it with a standard URIRef.
Alternatively, self.skolemize_blank_node is True,
it will skolemize the blank node
:param curie: str identifier formatted as curie or iri
:return: node: RDFLib URIRef or BNode object
"""
node = None
if curie[0] == '_':
if self.are_bnodes_skized is True:
node = self.skolemizeBlankNode(curie)
else: # delete the leading underscore to make it cleaner
node = BNode(re.sub(r'^_:|^_', '', curie, 1))
# Check if curie string is actually an IRI
elif curie[:4] == 'http' or curie[:3] == 'ftp' or curie[:4] == 'jdbc':
node = URIRef(curie)
else:
iri = RDFGraph.curie_util.get_uri(curie)
if iri is not None:
node = URIRef(RDFGraph.curie_util.get_uri(curie))
# Bind prefix map to graph
prefix = curie.split(':')[0]
if prefix not in self.namespace_manager.namespaces():
mapped_iri = self.curie_map[prefix]
self.bind(prefix, Namespace(mapped_iri))
else:
LOG.error("couldn't make URI for %s", curie)
# get a sense of where the CURIE-ish? thing is comming from
# magic number here is "steps up the call stack"
for call in range(3, 0, -1):
LOG.warning(
'\t%sfrom: %s', '\t' * call, sys._getframe(call).f_code.co_name)
return node
示例6: bind_all_namespaces
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def bind_all_namespaces(self):
"""
Results in the RDF @prefix directives for every ingest
being added to this ingest.
"""
for prefix in self.curie_map.keys():
iri = self.curie_map[prefix]
self.bind(prefix, Namespace(iri))
return
# serialize() conflicts between rdflib & Graph.serialize abstractmethod
# GraphUtils expects the former. (too bad there is no multiple dispatch)
示例7: define_namespace
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def define_namespace(self):
"""
Method used to set standard names (dbr stands for dbpediaresource, dbp for dbpediaproperty,
dbo for dbpediaontology)
:return:
"""
if self.chapter != 'en':
self.dbr = rdflib.Namespace("http://" + self.chapter + ".dbpedia.org/resource/")
else:
self.dbr = rdflib.Namespace("http://dbpedia.org/resource/")
self.dbo = rdflib.Namespace("http://dbpedia.org/ontology/")
self.dbp = rdflib.Namespace("http://dbpedia.org/property/")
示例8: namespace
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def namespace(self, prefix):
"""
Get the namespace for a prefix.
:param str prefix: Namespace prefix.
"""
ns = self.get_data(prefix.encode(), b'pfx:ns_')
return Namespace(ns.decode()) if ns is not None else None
示例9: prefix
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def prefix(self, namespace):
"""
Get the prefix associated with a namespace.
**Note:** A namespace can be only bound to one prefix in this
implementation.
:param rdflib.Namespace namespace: Fully qualified namespace.
:rtype: str or None
"""
prefix = self.get_data(str(namespace).encode(), b'ns:pfx_')
return prefix.decode() if prefix is not None else None
示例10: namespaces
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def namespaces(self):
"""Get an iterator of all prefix: namespace bindings.
:rtype: Iterator(tuple(str, rdflib.Namespace))
"""
for pfx, ns in self.all_namespaces():
yield (pfx, Namespace(ns))
示例11: bindings
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def bindings(self):
return (
('ns1', Namespace('http://test.org/ns#')),
('ns2', Namespace('http://my_org.net/ns#')),
('ns3', Namespace('urn:test:')),
('ns4', Namespace('info:myinst/graph#')),
)
示例12: __init__
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def __init__(self, builder, logger):
self.logger = logger
self.doap_namespace = Namespace('http://usefulinc.com/ns/doap#')
self.spdx_namespace = Namespace("http://spdx.org/rdf/terms#")
self.builder = builder
示例13: __init__
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def __init__(self, document, out):
self.document = document
self.out = out
self.doap_namespace = Namespace('http://usefulinc.com/ns/doap#')
self.spdx_namespace = Namespace("http://spdx.org/rdf/terms#")
self.graph = Graph()
示例14: __init__
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def __init__(self,
empty=False,
version='1.0.2',
brick_file='brick/Brick_1_0_2.ttl',
brickframe_file='brick/BrickFrame_1_0_2.ttl',
triplestore_type=RDFLIB
):
self.triplestore_type = triplestore_type
self._brick_version = version
if self.triplestore_type == RDFLIB:
self.base_package = rdflib_wrapper
elif self.triplestore_type == VIRTUOSO:
self.base_package = virtuoso_wrapper
self.g = self.base_package.init_graph(empty, brick_file,
brickframe_file)
self.BRICK = Namespace('https://brickschema.org/schema/{0}/Brick#'
.format(self._brick_version))
self.BF = Namespace('https://brickschema.org/schema/{0}/BrickFrame#'
.format(self._brick_version))
self.BASE = Namespace('http://example.com#')
self.sparql_prefix = """
prefix brick: <{0}>
prefix rdf: <{1}>
prefix rdfs: <{2}>
prefix base: <{3}>
prefix bf: <{4}>
prefix owl: <{5}>
""".format(str(self.BRICK), RDF, RDFS, self.BASE, str(self.BF), OWL)
示例15: get_prefixes
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import Namespace [as 别名]
def get_prefixes(version):
BRICK = Namespace('https://brickschema.org/schema/{0}/Brick#'.format(version))
BRICKFRAME = Namespace('https://brickschema.org/schema/{0}/BrickFrame#'.format(version))
BRICKTAG = Namespace('https://brickschema.org/schema/{0}/BrickTag#'.format(version))
return {
'brick': BRICK,
'bf': BRICKFRAME,
'tag': BRICKTAG,
'rdfs': rdflib.RDFS,
'rdf': rdflib.RDF,
'owl': rdflib.OWL,
}