本文整理汇总了Python中rdflib.BNode方法的典型用法代码示例。如果您正苦于以下问题:Python rdflib.BNode方法的具体用法?Python rdflib.BNode怎么用?Python rdflib.BNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib
的用法示例。
在下文中一共展示了rdflib.BNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_entity
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def parse_entity(self, term):
if isinstance(term, rdf.Literal):
return Entity(id=str(term), cls="_Literal")
elif isinstance(term, rdf.BNode):
return None
entstr = str(term)
if entstr.startswith(self.entity_prefix):
inst = entstr[len(self.entity_prefix):]
if self.d_entity.match(inst):
cls = 'd'
elif self.bond_entity.match(inst):
cls = 'bond'
else:
cls = None
return Entity(id=inst, cls=cls)
else:
return None
示例2: stringify_node
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def stringify_node(graph, node, ns_manager=None, recursion=0):
if ns_manager is None:
ns_manager = graph.namespace_manager
if isinstance(ns_manager, rdflib.Graph):
#json-ld loader can set namespace_manager to the conjunctive graph itself.
ns_manager = ns_manager.namespace_manager
ns_manager.bind("sh", SH, override=False, replace=False)
if isinstance(node, rdflib.Literal):
return stringify_literal(graph, node, ns_manager=ns_manager)
if isinstance(node, rdflib.BNode):
if isinstance(graph, (rdflib.ConjunctiveGraph, rdflib.Dataset)):
graph = find_node_named_graph(graph, node)
return stringify_blank_node(graph, node, ns_manager=ns_manager,
recursion=recursion+1)
if isinstance(node, rdflib.URIRef):
return node.n3(namespace_manager=ns_manager)
else:
node_string = str(node)
return node_string
示例3: _node_to_sparql_text
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def _node_to_sparql_text(cls, node):
if isinstance(node, rdflib.Literal):
if isinstance(node.value, str):
node_text = "\"{}\"".format(node.value)
else:
node_text = str(node.value)
if node.language:
node_text = "{}@{}".format(
node_text, str(node.language))
elif node.datatype:
node_text = "{}^^{}".format(
node_text, cls._node_to_sparql_text(node.datatype))
return node_text
elif isinstance(node, rdflib.URIRef):
return "<{}>".format(str(node))
elif isinstance(node, rdflib.BNode):
# I think this works to convert a BNode to its internal id.
return str(node)
elif isinstance(node, str):
return node
raise NotImplementedError("Cannot turn that kind of node into text.")
示例4: get_nodes_from_node_expression
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def get_nodes_from_node_expression(self, expr, focus_node, data_graph):
if expr == SH_this:
return [focus_node]
elif isinstance(expr, (rdflib.URIRef, rdflib.Literal)):
return [expr]
elif isinstance(expr, rdflib.BNode):
path_nodes = set(self.shape.sg.objects(expr, SH_path))
if len(path_nodes) > 0:
path_results = []
for p in path_nodes:
vals = self.shape.value_nodes_from_path(self.shape.sg, focus_node, p, data_graph)
path_results.extend(vals)
return path_results
else:
raise NotImplementedError("Unsupported expression s, p, or o, in SHACL TripleRule")
else:
raise NotImplementedError("Unsupported expression s, p, or o, in SHACL TripleRule")
示例5: _evaluate_string_rule
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def _evaluate_string_rule(self, r, target_graph, f_v_dict):
reports = []
non_conformant = False
assert isinstance(r, rdflib.Literal)
min_len = int(r.value)
if min_len < 0:
raise ReportableRuntimeError("Minimum length cannot be less than zero!")
for f, value_nodes in f_v_dict.items():
for v in value_nodes:
flag = False
if min_len == 0:
flag = True # min len zero always passes
elif isinstance(v, rdflib.BNode):
# blank nodes cannot pass minLen validation
pass
else:
v_string = self.value_node_to_string(v)
flag = len(v_string) >= min_len
if not flag:
non_conformant = True
rept = self.make_v_result(target_graph, f, value_node=v)
reports.append(rept)
return non_conformant, reports
示例6: evaluate
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def evaluate(self, target_graph, focus_value_nodes, _evaluation_path):
"""
:type focus_value_nodes: dict
:type target_graph: rdflib.Graph
"""
reports = []
non_conformant = False
for lt in iter(self.property_compare_set):
if isinstance(lt, rdflib.Literal) or\
isinstance(lt, rdflib.BNode):
raise ReportableRuntimeError(
"Value of sh:lessThan MUST be a URI Identifier.")
_nc, _r = self._evaluate_less_than(lt, target_graph, focus_value_nodes)
non_conformant = non_conformant or _nc
reports.extend(_r)
return (not non_conformant), reports
示例7: _ExpandObservationDimensionValue
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def _ExpandObservationDimensionValue(self, dim, data, row_id, row):
node_id = rdflib.BNode()
self.graph.add((row_id, SCHEMA.dimensionValue, node_id))
self.graph.add((node_id, rdflib.RDF.type, SCHEMA.DimensionValue))
self.graph.add((node_id, SCHEMA.dimension, data['id']))
for dim_type in data['type']:
if dim_type.endswith('CategoricalDimension'):
for type_id in data['types']:
self.graph.add((node_id, rdflib.RDF.type, type_id))
self.graph.add((node_id, SCHEMA.codeValue, rdflib.Literal(row[dim])))
else:
if data['types']:
self.graph.add(
(node_id, SCHEMA.value,
rdflib.Literal(row[dim],
datatype=rdflib.URIRef(data['types'][0]))))
else:
self.graph.add((node_id, SCHEMA.value, rdflib.Literal(row[dim])))
示例8: _object_value_int
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def _object_value_int(self, subject, predicate):
'''
Given a subject and a predicate, returns the value of the object as an
integer
Both subject and predicate must be rdflib URIRef or BNode objects
If the value can not be parsed as intger, returns None
'''
object_value = self._object_value(subject, predicate)
if object_value:
try:
return int(object_value)
except ValueError:
pass
return None
示例9: _contact_details
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def _contact_details(self, subject, predicate):
'''
Returns a dict with details about a vcard expression
Both subject and predicate must be rdflib URIRef or BNode objects
Returns keys for uri, name and email with the values set to
None if they could not be found
'''
contact = {}
for agent in self.g.objects(subject, predicate):
contact['uri'] = (unicode(agent) if isinstance(agent,
rdflib.term.URIRef) else None)
contact['name'] = self._object_value(agent, VCARD.fn)
contact['email'] = self._object_value(agent, VCARD.hasEmail)
return contact
示例10: test_dataset_license_from_distribution_by_title
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def test_dataset_license_from_distribution_by_title(self):
# license_id retrieved from dct:title of dcat:license object
g = Graph()
dataset = URIRef("http://example.org/datasets/1")
g.add((dataset, RDF.type, DCAT.Dataset))
distribution = URIRef("http://example.org/datasets/1/ds/1")
g.add((distribution, RDF.type, DCAT.Distribution))
g.add((dataset, DCAT.distribution, distribution))
license = BNode()
g.add((distribution, DCT.license, license))
g.add((license, DCT.title, Literal("Creative Commons Attribution")))
p = RDFParser(profiles=['euro_dcat_ap'])
p.g = g
dataset = [d for d in p.datasets()][0]
eq_(dataset['license_id'], 'cc-by')
示例11: test_contact_details_maintainer
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def test_contact_details_maintainer(self):
dataset = {
'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
'name': 'test-dataset',
'maintainer': 'Example Maintainer',
'maintainer_email': 'dep@example.com',
'author': 'Example Author',
'author_email': 'ped@example.com',
}
s = RDFSerializer()
g = s.g
dataset_ref = s.graph_from_dataset(dataset)
contact_details = self._triple(g, dataset_ref, DCAT.contactPoint, None)[2]
assert contact_details
assert_true(isinstance(contact_details, BNode))
assert self._triple(g, contact_details, VCARD.fn, dataset['maintainer'])
assert self._triple(g, contact_details, VCARD.hasEmail, dataset['maintainer_email'])
示例12: test_contact_details_author
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def test_contact_details_author(self):
dataset = {
'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
'name': 'test-dataset',
'author': 'Example Author',
'author_email': 'ped@example.com',
}
s = RDFSerializer()
g = s.g
dataset_ref = s.graph_from_dataset(dataset)
contact_details = self._triple(g, dataset_ref, DCAT.contactPoint, None)[2]
assert contact_details
assert_true(isinstance(contact_details, BNode))
assert self._triple(g, contact_details, VCARD.fn, dataset['author'])
assert self._triple(g, contact_details, VCARD.hasEmail, dataset['author_email'])
示例13: test_publisher_no_uri
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def test_publisher_no_uri(self):
dataset = {
'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
'name': 'test-dataset',
'extras': [
{'key': 'publisher_name', 'value': 'Example Publisher'},
]
}
extras = self._extras(dataset)
s = RDFSerializer()
g = s.g
dataset_ref = s.graph_from_dataset(dataset)
publisher = self._triple(g, dataset_ref, DCT.publisher, None)[2]
assert publisher
assert_true(isinstance(publisher, BNode))
assert self._triple(g, publisher, RDF.type, FOAF.Organization)
assert self._triple(g, publisher, FOAF.name, extras['publisher_name'])
示例14: test_spatial_bad_json_no_wkt
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def test_spatial_bad_json_no_wkt(self):
dataset = {
'id': '4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6',
'name': 'test-dataset',
'extras': [
{'key': 'spatial', 'value': 'NotJSON'},
]
}
extras = self._extras(dataset)
s = RDFSerializer()
g = s.g
dataset_ref = s.graph_from_dataset(dataset)
spatial = self._triple(g, dataset_ref, DCT.spatial, None)[2]
assert spatial
assert_true(isinstance(spatial, BNode))
# Geometry in GeoJSON
assert self._triple(g, spatial, LOCN.geometry, extras['spatial'], GEOJSON_IMT)
# Geometry in WKT
eq_(len([t for t in g.triples((spatial, LOCN.geometry, None))]), 1)
示例15: _add_agent
# 需要导入模块: import rdflib [as 别名]
# 或者: from rdflib import BNode [as 别名]
def _add_agent(self, _dict, ref, basekey, _type):
''' Stores the Agent in this format:
<dct:publisher rdf:resource="http://dati.gov.it/resource/Amministrazione/r_liguri"/>
<dcatapit:Agent rdf:about="http://dati.gov.it/resource/Amministrazione/r_liguri">
<rdf:type rdf:resource="&foaf;Agent"/>
<dct:identifier>r_liguri</dct:identifier>
<foaf:name>Regione Liguria</foaf:name>
</dcatapit:Agent>
Returns the ref to the agent node
'''
agent_name = self._get_dict_value(_dict, basekey + '_name', 'N/A')
agent_id = self._get_dict_value(_dict, basekey + '_identifier','N/A')
agent = BNode()
self.g.add((agent, RDF['type'], DCATAPIT.Agent))
self.g.add((agent, RDF['type'], FOAF.Agent))
self.g.add((ref, _type, agent))
self.g.add((agent, FOAF.name, Literal(agent_name)))
self.g.add((agent, DCT.identifier, Literal(agent_id)))
return agent