Example #1
0
 def testQueryRdfDataAsk(self):
     class testOptions(object):
         verbose        = False
         rdf_data       = ["test1.rdf", "test2.rdf"]
         prefix         = None
         format_rdf_in  = None
     options  = testOptions()
     prefixes = asqc.getPrefixes(options)+"PREFIX ex: <http://example.org/test#>\n"
     bindings = (
             { "head":    { "vars": ["s", "p", "o"] }
             , "results": 
               { "bindings": 
                 [ { 's': rdflib.URIRef("http://example.org/test#s1")
                   }
                 , { 's': rdflib.URIRef("http://example.org/test#s2")
                   , 'o': rdflib.URIRef("http://example.org/test#o4")
                   }
                 , { 's': rdflib.URIRef("http://example.org/test#s3")
                   , 'p': rdflib.URIRef("http://example.org/test#p5")
                   }
                 ]
               }
             })
     query = "ASK { ?s ?p ?o }"
     (status,result) = asqc.queryRdfData("test", options, prefixes, query, bindings)
     assert status == 0, "queryRdfData ASK with data status"
     assert result == {'head': {}, 'boolean': True}
     query = "ASK { ex:nonesuch ?p ?o }"
     (status,result) = asqc.queryRdfData("test", options, prefixes, query, bindings)
     assert status == 1, "queryRdfData ASK with no data status"
     assert result == {'head': {}, 'boolean': False}
     return
Example #2
0
 def testQueryRdfDataConstruct(self):
     class testOptions(object):
         verbose        = False
         rdf_data       = ["test1.rdf", "test2.rdf"]
         prefix         = None
         format_rdf_in  = None
     options  = testOptions()
     prefixes = asqc.getPrefixes(options)+"PREFIX ex: <http://example.org/test#>\n"
     bindings = (
             { "head":    { "vars": ["s", "p", "o"] }
             , "results": 
               { "bindings": 
                 [ { 's': rdflib.URIRef("http://example.org/test#s1")
                   }
                 , { 's': rdflib.URIRef("http://example.org/test#s2")
                   , 'o': rdflib.URIRef("http://example.org/test#o4")
                   }
                 , { 's': rdflib.URIRef("http://example.org/test#s3")
                   , 'p': rdflib.URIRef("http://example.org/test#p5")
                   }
                 ]
               }
             })
     query    = "CONSTRUCT {?s ?p ?o } WHERE { ?s ?p ?o }"
     (status,result)   = asqc.queryRdfData("test", options, prefixes, query, bindings)
     assert status == 0, "queryRdfData CONSTRUCT with data status"
     assert len(result) == 4, "queryRdfData triple count"
     assert ( rdflib.URIRef("http://example.org/test#s1"),
              rdflib.URIRef("http://example.org/test#p1"),
              rdflib.URIRef("http://example.org/test#o1") ) in result
     query    = "CONSTRUCT { <http://example.org/nonesuch> ?p ?o } WHERE { <http://example.org/nonesuch> ?p ?o }"
     (status,result)   = asqc.queryRdfData("test", options, prefixes, query, bindings)
     assert status == 1, "queryRdfData CONSTRUCT with no data status"
     assert len(result) == 0, "queryRdfData triple count"
     return
Example #3
0
 def testQueryRdfDataSelect(self):
     class testOptions(object):
         verbose        = False
         rdf_data       = ["test1.rdf", "test2.rdf"]
         prefix         = None
         format_rdf_in  = None
     options  = testOptions()
     prefixes = asqc.getPrefixes(options)+"PREFIX ex: <http://example.org/test#>\n"
     bindings = (
             { "head":    { "vars": ["s", "p", "o"] }
             , "results": 
               { "bindings": 
                 [ { 's': rdflib.URIRef("http://example.org/test#s1")
                   }
                 , { 's': rdflib.URIRef("http://example.org/test#s2")
                   , 'o': rdflib.URIRef("http://example.org/test#o4")
                   }
                 , { 's': rdflib.URIRef("http://example.org/test#s3")
                   , 'p': rdflib.URIRef("http://example.org/test#p5")
                   }
                 ]
               }
             })
     query = "SELECT * WHERE { ?s ?p ?o }"
     (status,result) = asqc.queryRdfData("test", options, prefixes, query, bindings)
     assert status == 0, "queryRdfData SELECT with data status"
     assert len(result["results"]["bindings"]) == 4, "queryRdfData result count"
     assert { 's': { 'type': "uri", 'value': "http://example.org/test#s1" }
            , 'p': { 'type': "uri", 'value': "http://example.org/test#p1" }
            , 'o': { 'type': "uri", 'value': "http://example.org/test#o1" }
            } in result["results"]["bindings"], "queryRdfData result 1"
     assert { 's': { 'type': "uri", 'value': "http://example.org/test#s1" }
            , 'p': { 'type': "uri", 'value': "http://example.org/test#p2" }
            , 'o': { 'type': "uri", 'value': "http://example.org/test#o2" }
            } in result["results"]["bindings"], "queryRdfData result 2"
     assert { 's': { 'type': "uri", 'value': "http://example.org/test#s2" }
            , 'p': { 'type': "uri", 'value': "http://example.org/test#p4" }
            , 'o': { 'type': "uri", 'value': "http://example.org/test#o4" }
            } in result["results"]["bindings"], "queryRdfData result 3"
     assert { 's': { 'type': "uri", 'value': "http://example.org/test#s3" }
            , 'p': { 'type': "uri", 'value': "http://example.org/test#p5" }
            , 'o': { 'type': "uri", 'value': "http://example.org/test#o5" }
            } in result["results"]["bindings"], "queryRdfData result 4"
     query = "SELECT * WHERE { <http://example.org/nonesuch> ?p ?o }"
     (status,result) = asqc.queryRdfData("test", options, prefixes, query, bindings)
     assert status == 1, "queryRdfData SELECT with no data status"
     assert len(result["results"]["bindings"]) == 0, "queryRdfData result count"
     return