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


Python ConjunctiveGraph.query方法代码示例

本文整理汇总了Python中rdflib.graph.ConjunctiveGraph.query方法的典型用法代码示例。如果您正苦于以下问题:Python ConjunctiveGraph.query方法的具体用法?Python ConjunctiveGraph.query怎么用?Python ConjunctiveGraph.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdflib.graph.ConjunctiveGraph的用法示例。


在下文中一共展示了ConjunctiveGraph.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GraphAggregates2

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class GraphAggregates2(unittest.TestCase):
    # known_issue = True

    def setUp(self):
        memStore = plugin.get("SQLAlchemy", Store)(identifier="rdflib_test", configuration=Literal("sqlite://"))
        self.graph1 = Graph(memStore, URIRef("http://example.com/graph1"))
        self.graph2 = Graph(memStore, URIRef("http://example.com/graph2"))
        self.graph3 = Graph(memStore, URIRef("http://example.com/graph3"))

        for n3Str, graph in [(testGraph1N3, self.graph1), (testGraph2N3, self.graph2), (testGraph3N3, self.graph3)]:
            graph.parse(StringIO(n3Str), format="n3")
        self.graph4 = Graph(memStore, RDFS.uri)
        self.graph4.parse(RDFS.uri)
        self.G = ConjunctiveGraph(memStore)

    def testAggregateSPARQL(self):
        raise SkipTest("known_issue with SELECT from NAMED")
        rt = self.G.query(sparqlQ)
        assert len(rt) > 1
        rt = self.G.query(sparqlQ2, initBindings={u"?graph": URIRef(u"http://example.com/graph3")})
        try:
            import json

            assert json
        except ImportError:
            import simplejson as json
        res = json.loads(rt.serialize(format="json").decode("utf-8"))
        assert len(res["results"]["bindings"]) == 20, len(res["results"]["bindings"])
开发者ID:RDFLib,项目名称:rdflib-sqlalchemy,代码行数:30,代码来源:test_aggregate_graphs.py

示例2: Query

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class Query(unittest.TestCase):

    def setUp(self):
        self.graph = ConjunctiveGraph()
        self.graph.parse(StringIO(test_data), format="n3")
    
    def test1(self):
        r=list(self.graph.query(test_query1))
        self.assertEqual(len(r), 1)

    def test2(self):
        r=list(self.graph.query(test_query2))
        self.assertEqual(len(r), 1)

    def test3(self):
        r=list(self.graph.query(test_query3))
        self.assertEqual(len(r), 1)

    def test4(self):
        r=list(self.graph.query(test_query4))
        self.assertEqual(len(r), 1)

    def test5(self):
        r=list(self.graph.query(test_query5))
        self.assertEqual(len(r), 0)
开发者ID:pombredanne,项目名称:rdfextras,代码行数:27,代码来源:test_lang_tags.py

示例3: GraphAggregates2

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class GraphAggregates2(unittest.TestCase):

    known_issue = True
    sparql = True

    def setUp(self):
        memStore = plugin.get('IOMemory',Store)()
        self.graph1 = Graph(memStore,URIRef("http://example.com/graph1"))
        self.graph2 = Graph(memStore,URIRef("http://example.com/graph2"))
        self.graph3 = Graph(memStore,URIRef("http://example.com/graph3"))
    
        for n3Str,graph in [(testGraph1N3,self.graph1),
                            (testGraph2N3,self.graph2),
                            (testGraph3N3,self.graph3)]:
            graph.parse(StringIO(n3Str),format='n3')
    
        self.graph4 = Graph(memStore,RDFS)
        self.graph4.parse(RDFS.uri)
        self.G = ConjunctiveGraph(memStore)

    def testAggregateSPARQL(self):    
        print sparqlQ
        rt =  self.G.query(sparqlQ)
        assert len(rt) > 1
        #print rt.serialize(format='xml')
        LOG_NS = Namespace(u'http://www.w3.org/2000/10/swap/log#')
        rt=self.G.query(sparqlQ2,initBindings={u'?graph' : URIRef("http://example.com/graph3")})
        #print rt.serialize(format='json')
        assert rt.serialize('python')[0] == LOG_NS.N3Document,repr(list(rt.serialize('python')))
开发者ID:alcides,项目名称:rdflib,代码行数:31,代码来源:test_aggregate_graphs.py

示例4: TestSparqlASK

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class TestSparqlASK(unittest.TestCase):
    def setUp(self):
        self.graph = Graph()

        io = StringIO("""
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <http://goonmill.org/2007/skill.n3#> .

:Foo a rdfs:Class .

:bar a :Foo .
""")

        
        self.graph.load(io, format='n3')

        self.compliance_setting, algebra.DAWG_DATASET_COMPLIANCE = algebra.DAWG_DATASET_COMPLIANCE, False

    def tearDown(self):
        algebra.DAWG_DATASET_COMPLIANCE = self.compliance_setting

    def test_ask_true(self):
        """
        Ask for a triple that exists, assert that the response is True.
        """
        res = self.graph.query('ASK { <http://goonmill.org/2007/skill.n3#bar> a <http://goonmill.org/2007/skill.n3#Foo> } ')
        self.assertEquals(res.askAnswer, True, "The answer should have been that the triple was found")

    def test_ask_false(self):
        """
        Ask for a triple that does not exist, assert that the response is False.
        """
        res = self.graph.query('ASK { <http://goonmill.org/2007/skill.n3#baz> a <http://goonmill.org/2007/skill.n3#Foo> } ')
        self.assertEquals(res.askAnswer, False, "The answer should have been that the triple was not found")
开发者ID:pombredanne,项目名称:rdfextras,代码行数:36,代码来源:test_issue_45.py

示例5: TestIssue06

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class TestIssue06(unittest.TestCase):
    debug = False
    sparql = True

    def setUp(self):
        self.graph = ConjunctiveGraph()
        self.graph.parse(data=testgraph, publicID="testgraph")

    def test_issue_6(self):
        query = """
        PREFIX ex: <http://temp.example.org/terms/>
        PREFIX loc: <http://simile.mit.edu/2005/05/ontologies/location#>
        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
        PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

        SELECT *
        WHERE {
            {?event ex:date ?date .
            FILTER (xsd:date(?date) >= xsd:date("2007-12-31") && xsd:date(?date) <= xsd:date("2008-01-11"))}

            UNION

            {?event ex:starts ?start; ex:finishes ?end .
             FILTER (xsd:date(?start) >= xsd:date("2008-01-02") && xsd:date(?end) <= xsd:date("2008-01-10"))}
        }
        ORDER BY ?event
        """
        self.graph.query(query, DEBUG=False)
开发者ID:RDFLib,项目名称:rdfextras,代码行数:30,代码来源:test_issue_06.py

示例6: GraphAggregates2

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class GraphAggregates2(unittest.TestCase):
    def setUp(self):
        memStore = plugin.get('SQLAlchemy', Store)(
            identifier="rdflib_test", configuration=Literal("sqlite://"))
        self.graph1 = Graph(memStore, URIRef("http://example.com/graph1"))
        self.graph2 = Graph(memStore, URIRef("http://example.com/graph2"))
        self.graph3 = Graph(memStore, URIRef("http://example.com/graph3"))

        for n3Str,graph in [(testGraph1N3, self.graph1),
                            (testGraph2N3, self.graph2),
                            (testGraph3N3, self.graph3)]:
            graph.parse(StringIO(n3Str), format='n3')

        self.graph4 = Graph(memStore, RDFS.uri)
        self.graph4.parse(RDFS.uri)
        self.G = ConjunctiveGraph(memStore)

    def testAggregateSPARQL(self):
        rt =  self.G.query(sparqlQ)
        assert len(rt) > 1
        rt = self.G.query(sparqlQ2, initBindings={u'?graph' : URIRef(u"http://example.com/graph3")})
        try:
            import json
        except ImportError:
            import simplejson as json
        res = json.loads(rt.serialize(format='json'))
        assert len(res['results']['bindings']) == 20, len(res['results']['bindings'])
开发者ID:pebbie,项目名称:rdflib-sqlalchemy,代码行数:29,代码来源:test_aggregate_graphs.py

示例7: testLimit2

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
 def testLimit2(self):
     graph = ConjunctiveGraph(plugin.get("IOMemory", Store)())
     graph.parse(StringIO(test_data2), format="n3")
     results = list(graph.query(test_query2, DEBUG=True))
     print graph.query(test_query2).serialize(format="xml")
     self.failUnless(len(results) == 1)
     for title, price in results:
         self.failUnless(title in [Literal("Java Tutorial"), Literal("COBOL Tutorial")])
开发者ID:janaya,项目名称:pubsubsemhub,代码行数:10,代码来源:sparql_limit.py

示例8: TestSparqlJsonResults

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class TestSparqlJsonResults(unittest.TestCase):

    def setUp(self):
        self.graph = ConjunctiveGraph()
        self.graph.parse(StringIO(test_data), format="n3")

    def _query_result_contains(self, query, correct):
        results = self.graph.query(query)
        result_json = json.loads(results.serialize(format='json').decode('utf-8'))

        msg = "Expected:\n %s \n- to contain:\n%s" % (result_json, correct)
        self.assertEqual(sorted(result_json["head"], key=repr),
                         sorted(correct["head"], key=repr), msg)

        # Sort by repr - rather a hack, but currently the best way I can think
        # of to ensure the results are in the same order.
        result_bindings = sorted(result_json["results"]["bindings"], key=repr)
        correct_bindings = sorted(correct["results"]["bindings"], key=repr)
        msg = "Expected:\n %s \n- to contain:\n%s" % (result_bindings, correct_bindings)
        self.failUnless(result_bindings==correct_bindings, msg)

    testOptional = make_method('optional')

    testWildcard = make_method('wildcard')

    testUnion = make_method('union')

    testUnion3 = make_method('union3')

    testSelectVars = make_method('select_vars')
    
    testWildcardVars = make_method('wildcard_vars')
开发者ID:RDFLib,项目名称:rdfextras,代码行数:34,代码来源:test_sparql_json_results.py

示例9: TestSparqlJsonResults

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class TestSparqlJsonResults(unittest.TestCase):

    def setUp(self):
        self.graph = ConjunctiveGraph()
        self.graph.parse(StringIO(test_data), format="n3")

    def _query_result_contains(self, query, correct):
        results = self.graph.query(query)
        result_json = json.loads(results.serialize(format='json'))

        msg = "Expected:\n %s \n- to contain:\n%s" % (result_json, correct)
        self.failUnless(result_json["head"]==correct["head"], msg)

        result_bindings = sorted(result_json["results"]["bindings"])
        correct_bindings = sorted(correct["results"]["bindings"])
        msg = "Expected:\n %s \n- to contain:\n%s" % (result_bindings, correct_bindings)
        self.failUnless(result_bindings==correct_bindings, msg)

    testOptional = make_method('optional')

    testWildcard = make_method('wildcard')

    testUnion = make_method('union')

    testUnion3 = make_method('union3')

    testSelectVars = make_method('select_vars')
    
    testWildcardVars = make_method('wildcard_vars')
开发者ID:pombredanne,项目名称:rdfextras,代码行数:31,代码来源:test_sparql_json_results.py

示例10: test4_DAWG_DATASET_COMPLIANCE_is_True

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
 def test4_DAWG_DATASET_COMPLIANCE_is_True(self):
     raise SkipTest("known DAWG_DATATSET_COMPLIANCE SPARQL issue")
     graph = Graph()
     graph.parse(data=test4data, format='n3')
     res = graph.query(test4query, dSCompliance=True)
     # print("json", res.serialize(format='json'))
     assert len(res) == 2
开发者ID:RDFLib,项目名称:rdfextras,代码行数:9,代码来源:test_DAWG_DATASET_COMPLIANCE_flag.py

示例11: TestSparqlEquals

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class TestSparqlEquals(unittest.TestCase):

    PREFIXES = {
        'rdfs': "http://www.w3.org/2000/01/rdf-schema#"
    }

    def setUp(self):
        testContent = """
            @prefix rdfs: <%(rdfs)s> .
            <http://example.org/doc/1> rdfs:label "Document 1"@en .
            <http://example.org/doc/2> rdfs:label "Document 2"@en .
            <http://example.org/doc/3> rdfs:label "Document 3"@en .
        """ % self.PREFIXES
        self.graph = ConjunctiveGraph()
        self.graph.load(StringIO(testContent), format='n3')

    def test_uri_equals(self):
        uri = URIRef("http://example.org/doc/1")
        query = ("""
            PREFIX rdfs: <%(rdfs)s>

            SELECT ?uri WHERE {
                ?uri rdfs:label ?label .
                FILTER( ?uri = <"""+uri+"""> )
            }
        """) % self.PREFIXES
        res = self.graph.query(query)
        expected = [(uri,)]
        self.assertEqual(list(res),expected)
开发者ID:pombredanne,项目名称:rdfextras,代码行数:31,代码来源:test_sparql_equals.py

示例12: testLimit2

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
 def testLimit2(self):
     graph = ConjunctiveGraph(plugin.get('IOMemory',Store)())
     graph.parse(data=test_data2, format="n3")
     results = list(graph.query(test_query2,DEBUG=False))
     self.assertEqual(len(results), 1)
     for title,price in results:    
         self.assertTrue(title in [Literal("Java Tutorial"),
                                   Literal("COBOL Tutorial")])    
开发者ID:RDFLib,项目名称:rdfextras,代码行数:10,代码来源:test_sparql_limit.py

示例13: TestSparqlOPT_FILTER

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class TestSparqlOPT_FILTER(unittest.TestCase):
    def setUp(self):
        self.graph = ConjunctiveGraph()
        self.graph.load(StringIO(testContent), format="n3")

    def test_OPT_FILTER(self):
        results = self.graph.query(QUERY, DEBUG=False, initBindings={"?label": RDFS.label})
        print results.vars
        self.failUnless(list(results) == [(doc2,)], "expecting : %s, got %s" % (repr([(doc2,)]), repr(list(results))))
开发者ID:RDFLib,项目名称:rdfextras,代码行数:11,代码来源:test_sparql_naf.py

示例14: TestSparqlOPT_FILTER2

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class TestSparqlOPT_FILTER2(unittest.TestCase):
    def setUp(self):
        self.graph = ConjunctiveGraph()
        self.graph.load(StringIO(testContent), format="n3")

    def test_OPT_FILTER(self):
        results = self.graph.query(QUERY, DEBUG=False).serialize(format="python")
        results = list(results)
        self.failUnless(results == [doc1], "expecting : %s .  Got: %s" % ([doc1], repr(results)))
开发者ID:janaya,项目名称:pubsubsemhub,代码行数:11,代码来源:test_sparql_graph_graph_pattern.py

示例15: TestSparqlOPT_FILTER

# 需要导入模块: from rdflib.graph import ConjunctiveGraph [as 别名]
# 或者: from rdflib.graph.ConjunctiveGraph import query [as 别名]
class TestSparqlOPT_FILTER(unittest.TestCase):
    def setUp(self):
        self.graph = ConjunctiveGraph()
        self.graph.load(StringIO(testContent), format='n3')
    def test_OPT_FILTER(self):
        results = self.graph.query(QUERY,
                                   DEBUG=False,
                                   initBindings={'?label':RDFS.label}).serialize(format='python')
        self.failUnless(list(results) == [doc2],
                "expecting : %s"%repr([doc2]))
开发者ID:alcides,项目名称:rdflib,代码行数:12,代码来源:test_sparql_naf.py


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