本文整理汇总了Python中rdflib.graph.ConjunctiveGraph.objects方法的典型用法代码示例。如果您正苦于以下问题:Python ConjunctiveGraph.objects方法的具体用法?Python ConjunctiveGraph.objects怎么用?Python ConjunctiveGraph.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdflib.graph.ConjunctiveGraph
的用法示例。
在下文中一共展示了ConjunctiveGraph.objects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import objects [as 别名]
def main():
parser = argparse.ArgumentParser(
description='OMIA integration test',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument(
'--input', '-i', type=str, required=True,
help='Location of input ttl file')
args = parser.parse_args()
graph = ConjunctiveGraph()
graph.parse(args.input, format=rdflib_util.guess_format(args.input))
model_of = URIRef('http://purl.obolibrary.org/obo/RO_0003301')
models = graph.subject_objects(model_of)
model_len = len(list(models))
if model_len < EXPECTED_PAIRS:
logger.error("Not enough model_of predicates in graph:"
" {} expected {} check omia log for"
" warnings".format(model_len, EXPECTED_PAIRS))
exit(1)
omim_diseases = graph.objects(
subject=URIRef('https://monarchinitiative.org/model/OMIA-breed:18'),
predicate=model_of
)
if list(omim_diseases) != [URIRef('http://purl.obolibrary.org/obo/OMIM_275220')]:
logger.error("Missing breed to omim triple for {}".format('OMIA-breed:18'))
exit(1)
logger.info("PASSED")
示例2: update_list
# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import objects [as 别名]
def update_list():
"""
Reads the triple store looking for twitter usernames and adds
them to the dev8d list.
"""
g = ConjunctiveGraph("Sleepycat")
g.open("store")
# get oauth client in order
credentials = get_credentials()
consumer = oauth.Consumer(credentials['key'], credentials['secret'])
client = oauth.Client(consumer, credentials['access_token'])
list_update_url = 'http://api.twitter.com/1/%s/%s/members.json' % \
(credentials['list_owner'], credentials['list_name'])
# create the list if necessary
create_list(credentials['list_owner'], credentials['list_name'], client)
# look at all the twitter usernames and add them to the list
for twitter_username in g.objects(predicate=w['Twitter']):
id = twitter_user_id(twitter_username, client)
if id:
logging.info("adding %s (%s) to list" % (twitter_username, id))
body = "id=%s" % id
resp, content = client.request(list_update_url, 'POST', body=body)
else:
logging.error("unable to get twitter id for %s" % twitter_username)
g.close()
示例3: TestSparqlOPT_FILTER
# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import objects [as 别名]
class TestSparqlOPT_FILTER(unittest.TestCase):
def setUp(self):
self.graph = ConjunctiveGraph()
self.graph.load(StringIO(testContent), format='n3')
def test_OPT_FILTER(self):
xd3Objs = [o for o in self.graph.objects(subject=exNS.xd3,
predicate=exNS.p)]
self.failUnless(xd3Objs[0].datatype == XSD.double,
"Expecting %r, got instead : %r"%(double1, xd3Objs[0]))
示例4: main
# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import objects [as 别名]
def main():
parser = argparse.ArgumentParser(
description='OMIA integration test',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument(
'--input', '-i', type=str, required=True, help='Location of input ttl file')
args = parser.parse_args()
graph = ConjunctiveGraph()
graph.parse(args.input, format=rdflib_util.guess_format(args.input))
# "is model of": "RO:0003301"
# is_model_of = URIRef('OBO:RO_0003301')
is_model_of = URIRef('http://purl.obolibrary.org/obo/RO_0003301')
# if we curie_map & globaltt here we could ...
# (pfx lcl) = globaltt["is model of"].split(':')
# iri = curie_map[pfx] + '_'.join((pfx, lcl))
# is_model_of = URIRef(iri)
models = graph.subject_objects(is_model_of)
model_len = len(set(list(models)))
if model_len < EXPECTED_PAIRS:
LOG.error(
"Not enough <RO:is model of> predicates in graph: found {}, "
"expected {} check omia log for warnings".format(
model_len, EXPECTED_PAIRS))
exit(1)
# else:
# LOG.info(
# "Found {} model_of predicates in graph, expected at least: {}".format(
# model_len, EXPECTED_PAIRS))
breed = 'https://monarchinitiative.org/model/OMIA-breed:758'
disease = 'http://omim.org/entry/305100'
omim_diseases = graph.objects(
subject=URIRef(breed),
predicate=is_model_of
)
if list(omim_diseases) != [URIRef(disease)]:
LOG.error("Missing breed to omim triple for %s", breed)
LOG.error(list(omim_diseases))
exit(1)
LOG.info("PASSED")
示例5: generictest
# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import objects [as 别名]
def generictest(testFile):
func_name = __name__ = __doc__ = id = 'test_sparql.' + \
os.path.splitext(testFile)[0][8:].translate(
maketrans('-/','__'))
store = plugin.get(STORE,Store)()
bootStrapStore(store)
store.commit()
prefix = testFile.split('.rq')[-1]
manifestPath = '/'.join(testFile.split('/')[:-1]+['manifest.n3'])
manifestPath2 = '/'.join(testFile.split('/')[:-1]+['manifest.ttl'])
queryFileName = testFile.split('/')[-1]
store = plugin.get(STORE,Store)()
store.open(configString,create=False)
assert len(store) == 0
manifestG=ConjunctiveGraph(store)
if not os.path.exists(manifestPath):
assert os.path.exists(manifestPath2)
manifestPath = manifestPath2
manifestG.default_context.parse(open(manifestPath),
publicID=URIRef(TEST_BASE),
format='n3')
manifestData = manifestG.query(
MANIFEST_QUERY,
processor='sparql',
initBindings={'query' : TEST_BASE[queryFileName]},
initNs=manifestNS,
DEBUG = False)
store.rollback()
store.close()
for source,testCaseName,testCaseComment,expectedRT in manifestData:
if expectedRT:
expectedRT = '/'.join(testFile.split('/')[:-1] + \
[expectedRT.replace(TEST_BASE,'')])
if source:
source = '/'.join(testFile.split('/')[:-1] + \
[source.replace(TEST_BASE,'')])
testCaseName = testCaseComment and testCaseComment or testCaseName
# log.debug("## Source: %s ##"%source)
# log.debug("## Test: %s ##"%testCaseName)
# log.debug("## Result: %s ##"%expectedRT)
#Expected results
if expectedRT:
store = plugin.get(STORE,Store)()
store.open(configString,create=False)
resultG=ConjunctiveGraph(store).default_context
log.debug("###"*10)
log.debug("parsing: %s" % open(expectedRT).read())
log.debug("###"*10)
assert len(store) == 0
# log.debug("## Parsing (%s) ##"%(expectedRT))
if not trialAndErrorRTParse(resultG,expectedRT,DEBUG):
log.debug(
"Unexpected result format (for %s), skipping" % \
(expectedRT))
store.rollback()
store.close()
continue
log.debug("## Done .. ##")
rtVars = [rtVar for rtVar in
resultG.objects(None,RESULT_NS.resultVariable)]
bindings = []
resultSetNode = resultG.value(predicate=RESULT_NS.value,
object=RESULT_NS.ResultSet)
for solutionNode in resultG.objects(resultSetNode,
RESULT_NS.solution):
bindingDict = dict([(key,None) for key in rtVars])
for bindingNode in resultG.objects(solutionNode,
RESULT_NS.binding):
value = resultG.value(subject=bindingNode,
predicate=RESULT_NS.value)
name = resultG.value(subject=bindingNode,
predicate=RESULT_NS.variable)
bindingDict[name] = value
rbinds = [bindingDict[vName] for vName in rtVars]
# print("Rbinds", rbinds)
if len(rbinds) > 1 and (
isinstance(rbinds, list) or isinstance(rbinds, tuple)):
bindings.append(frozenset(rbinds))
elif len(rbinds) == 1 and (
isinstance(rbinds, list) or isinstance(rbinds, tuple)):
bindings.append(rbinds[0])
else:
bindings.append(rbinds)
# bindings.append(tuple([bindingDict[vName] for vName in rtVars]))
log.debug(open(expectedRT).read())
store.rollback()
store.close()
if testFile in tests2Skip.keys():
log.debug("Skipping test (%s) %s\n" % \
(testFile, tests2Skip[testFile]))
raise SkipTest("Skipping test (%s) %s\n" % \
(testFile, tests2Skip[testFile]))
query = open(testFile).read()
log.debug("### %s (%s) ###" % (testCaseName,testFile))
log.debug(query)
p = parse(query)#,DEBUG_PARSE)
log.debug(p)
if EVALUATE and source:
log.debug("### Source Graph: ###")
log.debug(open(source).read())
#.........这里部分代码省略.........
示例6: Namespace
# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import objects [as 别名]
#!/usr/bin/env python
from rdflib.graph import ConjunctiveGraph
from rdflib.namespace import Namespace
dct = Namespace('http://purl.org/dc/terms/')
g = ConjunctiveGraph('Sleepycat')
g.open('store')
subjects = {}
for o in g.objects(predicate=dct['subject']):
sub = o.split('/')[-1]
subjects[sub] = subjects.get(sub, 0) + 1
sorted_keys = subjects.keys()
sorted_keys.sort(lambda a, b: cmp(subjects[b], subjects[a]))
for subject in sorted_keys:
print subject, "\t", subjects[subject]
示例7: pprint
# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import objects [as 别名]
# Now, with just that, lets see how the system
# recorded *way* too many details about what
# you just asserted as fact.
#
from pprint import pprint
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.