当前位置: 首页>>代码示例>>Python>>正文


Python ConjunctiveGraph.value方法代码示例

本文整理汇总了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)
#.........这里部分代码省略.........
开发者ID:AuroraSkywalker,项目名称:watchdog,代码行数:103,代码来源:test.py


注:本文中的rdflib.Graph.ConjunctiveGraph.value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。