本文整理汇总了Python中rdflib.ConjunctiveGraph.subject_objects方法的典型用法代码示例。如果您正苦于以下问题:Python ConjunctiveGraph.subject_objects方法的具体用法?Python ConjunctiveGraph.subject_objects怎么用?Python ConjunctiveGraph.subject_objects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.ConjunctiveGraph
的用法示例。
在下文中一共展示了ConjunctiveGraph.subject_objects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_graph_from_sparql_results
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import subject_objects [as 别名]
def get_graph_from_sparql_results(sparql_json, named_graph=None):
if len(sparql_json['results']['bindings']) == 0:
return ConjunctiveGraph(), 0
sparql_vars = sparql_json['head']['vars']
if 'g' in sparql_vars:
if not named_graph:
named_graph = sparql_json['results']['bindings'][0]['g']['value']
sparql_vars.remove('g')
triple_levels = RDFModel.get_context_triples(sparql_json['head']['vars'])
nr_levels = len(triple_levels)
if named_graph:
named_graph = URIRef(named_graph)
graph = ConjunctiveGraph(identifier=named_graph)
graph.namespace_manager = namespace_manager
for binding in sparql_json['results']['bindings']:
binding_levels = RDFModel.get_context_levels(len(binding.keys()))
for s, p, o in triple_levels[:binding_levels]:
subject = URIRef(binding[s]['value'])
if binding[s]['type'] == 'bnode':
subject = BNode(binding[s]['value'])
predicate = URIRef(binding[p]['value'])
obj = RDFModel.get_object_from_sparql_result(binding[o])
graph.add((subject, predicate, obj))
# materialize inferences
for subject, obj in graph.subject_objects(
predicate=URIRef("http://www.openarchives.org/ore/terms/isAggregatedBy")):
graph.add((obj, URIRef("http://www.openarchives.org/ore/terms/aggregates"), subject))
graph.remove((subject, URIRef("http://www.openarchives.org/ore/terms/isAggregatedBy"), obj))
return graph, nr_levels
示例2: blogs
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import subject_objects [as 别名]
def blogs():
g = ConjunctiveGraph("Sleepycat")
g.open("store")
for person, blog in g.subject_objects(predicate=w.Blog):
name = g.value(subject=person, predicate=w.Name)
for title, feed_url in discover_feeds(blog):
if title:
title = "%s (%s)" % (name, title)
else:
title = name
logging.info("found %s <%s>" % (title, feed_url))
yield title, feed_url
g.close()
示例3: pprint
# 需要导入模块: from rdflib import ConjunctiveGraph [as 别名]
# 或者: from rdflib.ConjunctiveGraph import subject_objects [as 别名]
pprint(list(primer))
# just think .whatever((s, p, o))
# here we report on what we know
pprint(list(primer.subjects()))
pprint(list(primer.predicates()))
pprint(list(primer.objects()))
# and other things that make sense
# what do we know about pat?
pprint(list(primer.predicate_objects(myNS.pat)))
# who is what age?
pprint(list(primer.subject_objects(myNS.age)))
# Okay, so lets now work with a bigger
# dataset from the example, and start
# with a fresh new graph.
primer = ConjunctiveGraph()
# Lets start with a verbatim string straight from the primer text:
mySource = """
@prefix : <http://www.w3.org/2000/10/swap/Primer#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .