[tests, dataio] Add a missing prefix in a sparql query
authorSimon Chabot <simon.chabot@logilab.fr>
Tue, 01 Oct 2019 10:14:52 +0200
changeset 568 e34db1c9be44
parent 567 d5f2a4fdb810
child 569 ac9b70c9a253
[tests, dataio] Add a missing prefix in a sparql query
test/test_dataio.py
test/test_ner.py
--- a/test/test_dataio.py	Tue Oct 01 10:09:47 2019 +0200
+++ b/test/test_dataio.py	Tue Oct 01 10:14:52 2019 +0200
@@ -150,27 +150,34 @@
 
     @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_query(self):
-        results = sparqlquery(u'http://dbpedia.org/sparql',
-                              u'''SELECT DISTINCT ?uri ?designer
-                                  WHERE {
-                                  ?uri rdf:type <http://dbpedia.org/ontology/ProgrammingLanguage> ;
-                                       rdfs:label ?label ;
-                                       dbpedia-owl:designer ?designer .
-                                  FILTER(regex(?label, "^Python"))
-                                  }''')
+        results = sparqlquery(
+            'http://dbpedia.org/sparql',
+            '''\
+            PREFIX dbpedia-owl:<http://dbpedia.org/ontology/>
+            SELECT DISTINCT ?uri ?designer
+            WHERE {
+                ?uri rdf:type <http://dbpedia.org/ontology/ProgrammingLanguage> ;
+                rdfs:label ?label ;
+                dbpedia-owl:designer ?designer .
+            FILTER(regex(?label, "^Python"))
+            }''')
         self.assertEqual(results, [['http://dbpedia.org/resource/Python_(programming_language)', 'http://dbpedia.org/resource/Guido_van_Rossum'],
                                    ['http://dbpedia.org/resource/Python_for_S60', 'http://dbpedia.org/resource/Guido_van_Rossum']])
 
     @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_execute(self):
-        rawresults = _sparqlexecute(u'http://dbpedia.org/sparql',
-                                    u'''SELECT DISTINCT ?uri ?designer
-                                        WHERE {
-                                        ?uri rdf:type <http://dbpedia.org/ontology/ProgrammingLanguage> ;
-                                             rdfs:label ?label ;
-                                             dbpedia-owl:designer ?designer .
-                                        FILTER(regex(?label, "^Python"))
-                                        }''')
+        rawresults = _sparqlexecute(
+            'http://dbpedia.org/sparql',
+            '''\
+            PREFIX dbpedia-owl:<http://dbpedia.org/ontology/>
+            SELECT DISTINCT ?uri ?designer
+            WHERE {
+            ?uri rdf:type <http://dbpedia.org/ontology/ProgrammingLanguage> ;
+                 rdfs:label ?label ;
+                 dbpedia-owl:designer ?designer .
+            FILTER(regex(?label, "^Python"))
+            }''',
+        )
         self.assertEqual(rawresults,
                          {'head': {'link': [], 'vars': ['uri', 'designer']},
                           'results': {
@@ -207,14 +214,18 @@
 
     @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_json(self):
-        results = sparqljson(u'http://dbpedia.org/sparql',
-                             u'''SELECT DISTINCT ?uri ?designer
-                                 WHERE {
-                                 ?uri rdf:type <http://dbpedia.org/ontology/ProgrammingLanguage> ;
-                                      rdfs:label ?label ;
-                                      dbpedia-owl:designer ?designer .
-                                 FILTER(regex(?label, "^Python"))
-                                 }''')
+        results = sparqljson(
+            'http://dbpedia.org/sparql',
+            '''\
+            PREFIX dbpedia-owl:<http://dbpedia.org/ontology/>
+            SELECT DISTINCT ?uri ?designer
+            WHERE {
+            ?uri rdf:type <http://dbpedia.org/ontology/ProgrammingLanguage> ;
+                 rdfs:label ?label ;
+                 dbpedia-owl:designer ?designer .
+            FILTER(regex(?label, "^Python"))
+            }''',
+        )
         self.assertEqual(results,
                          {'designer': set(['http://dbpedia.org/resource/Guido_van_Rossum']),
                           'uri': set(['http://dbpedia.org/resource/Python_(programming_language)',
--- a/test/test_ner.py	Tue Oct 01 10:09:47 2019 +0200
+++ b/test/test_ner.py	Tue Oct 01 10:14:52 2019 +0200
@@ -59,14 +59,18 @@
     @unittest.skipUnless(SPARQL_ENABLED, 'python-sparqlwrapper is not installed')
     def test_sparql_source(self):
         """ Test sparql source """
-        source = NerSourceSparql(u'http://dbpedia.org/sparql',
-                                 u'''SELECT DISTINCT ?uri
-                                 WHERE {
-                                 ?uri rdf:type <http://dbpedia.org/ontology/ProgrammingLanguage> ;
-                                      dbpedia-owl:designer <http://dbpedia.org/resource/Guido_van_Rossum> ;
-                                      rdfs:label ?label.
-                                 FILTER(regex(?label, "^%(word)s"))
-                                 }''')
+        source = NerSourceSparql(
+            'http://dbpedia.org/sparql',
+            '''\
+            PREFIX dbpedia-owl:<http://dbpedia.org/ontology/>
+            SELECT DISTINCT ?uri
+            WHERE {
+            ?uri rdf:type <http://dbpedia.org/ontology/ProgrammingLanguage> ;
+                 dbpedia-owl:designer <http://dbpedia.org/resource/Guido_van_Rossum> ;
+                 rdfs:label ?label.
+            FILTER(regex(?label, "^%(word)s"))
+            }''',
+        )
         self.assertEqual(source.query_word('Python'),
                          ['http://dbpedia.org/resource/Python_(programming_language)',
                           'http://dbpedia.org/resource/Python_for_S60'])