本文整理匯總了Python中rdflib.Graph.ConjunctiveGraph.value方法的典型用法代碼示例。如果您正苦於以下問題:Python ConjunctiveGraph.value方法的具體用法?Python ConjunctiveGraph.value怎麽用?Python ConjunctiveGraph.value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rdflib.Graph.ConjunctiveGraph
的用法示例。
在下文中一共展示了ConjunctiveGraph.value方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testBasic
# 需要導入模塊: from rdflib.Graph import ConjunctiveGraph [as 別名]
# 或者: from rdflib.Graph.ConjunctiveGraph import value [as 別名]
def testBasic(DEBUG = False):
from glob import glob
from sre import sub
for testFile in glob('data/examples/*.rq'):#glob('data/*/*.rq'):
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=TEST_BASE,format='n3')
manifestData = \
manifestG.query(
PARSED_MANIFEST_QUERY,
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
print "## Source: %s ##"%source
print "## Test: %s ##"%testCaseName
print "## Result: %s ##"%expectedRT
#Expected results
if expectedRT:
store = plugin.get(STORE,Store)()
store.open(configString,create=False)
resultG=ConjunctiveGraph(store).default_context
# if DEBUG:
# print "###"*10
# print "parsing: ", open(expectedRT).read()
# print "###"*10
assert len(store) == 0
print "## Parsing (%s) ##"%(expectedRT)
if not trialAndErrorRTParse(resultG,expectedRT,DEBUG):
if DEBUG:
print "Unexpected result format (for %s), skipping"%(expectedRT)
store.rollback()
store.close()
continue
if DEBUG:
print "## 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
bindings.append(tuple([bindingDict[vName] for vName in rtVars]))
if DEBUG:
print "Expected bindings: ", bindings
print open(expectedRT).read()
store.rollback()
store.close()
if testFile.startswith('data/NegativeSyntax'):
try:
query = open(testFile).read()
p = Parse(query,DEBUG)
except:
continue
else:
raise Exception("Test %s should have failed!"%testFile)
if testFile in tests2Skip:
print "Skipping test (%s)"%testCaseName
continue
query = open(testFile).read()
print "### %s (%s) ###"%(testCaseName,testFile)
print query
p = Parse(query,DEBUG_PARSE)
if DEBUG:
print p
if EVALUATE and source:
if DEBUG:
print "### Source Graph: ###"
print open(source).read()
store = plugin.get(STORE,Store)()
store.open(configString,create=False)
g=ConjunctiveGraph(store)
#.........這裏部分代碼省略.........