[tests] update tests against dbpedia to make them pass (hopefully more permanently)
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Sun, 23 Nov 2014 18:59:29 +0100
changeset 482 2cf6218df07a
parent 481 92422ce60b21
child 483 57db633dd297
[tests] update tests against dbpedia to make them pass (hopefully more permanently)
test/test_dataio.py
test/test_ner.py
--- a/test/test_dataio.py	Thu Nov 20 11:26:29 2014 +0100
+++ b/test/test_dataio.py	Sun Nov 23 18:59:29 2014 +0100
@@ -149,23 +149,39 @@
 
     def test_sparql_query(self):
         results = sparqlquery(u'http://dbpedia.org/sparql',
-                              u'''SELECT DISTINCT ?uri
-                                  WHERE{
-                                  ?uri rdfs:label "Python"@en .
-                                  ?uri rdf:type ?type}''')
-        self.assertEqual(results, [['http://dbpedia.org/resource/Python'],
-                                   ['http://sw.opencyc.org/2008/06/10/concept/en/Python_ProgrammingLanguage'],
-                                   ['http://sw.opencyc.org/2008/06/10/concept/Mx4r74UIARqkEdac2QACs0uFOQ']])
+                              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"))
+                                  }''')
+        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']])
 
     def test_sparql_execute(self):
         rawresults = _sparqlexecute(u'http://dbpedia.org/sparql',
-                                    u'''SELECT DISTINCT ?uri
-                                    WHERE{
-                                    ?uri rdfs:label "Python"@en .
-                                    ?uri rdf:type ?type}''')
-        self.assertEqual(rawresults, {u'head': {u'link': [], u'vars': [u'uri']},
-                                      u'results': {u'distinct': False, u'bindings': [{u'uri': {u'type': u'uri', u'value': u'http://dbpedia.org/resource/Python'}}, {u'uri': {u'type': u'uri', u'value': u'http://sw.opencyc.org/2008/06/10/concept/en/Python_ProgrammingLanguage'}}, {u'uri': {u'type': u'uri', u'value': u'http://sw.opencyc.org/2008/06/10/concept/Mx4r74UIARqkEdac2QACs0uFOQ'}}],
-                                                   u'ordered': True}})
+                                    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"))
+                                        }''')
+        self.assertEqual(rawresults,
+                         {'head': {'link': [], 'vars': ['uri', 'designer']},
+                          'results': {
+                              'bindings': [
+                                  {'designer': {'type': 'uri',
+                                                'value': 'http://dbpedia.org/resource/Guido_van_Rossum'},
+                                   'uri': {'type': 'uri',
+                                           'value': 'http://dbpedia.org/resource/Python_(programming_language)'}},
+                                  {'designer': {'type': 'uri',
+                                                'value': 'http://dbpedia.org/resource/Guido_van_Rossum'},
+                                   'uri': {'type': 'uri',
+                                           'value': 'http://dbpedia.org/resource/Python_for_S60'}}],
+                              'distinct': False,
+                              'ordered': True}})
 
     def test_sparql_execute_no_raise_on_error(self):
         rawresults = _sparqlexecute(u'http://dbpedia.org/sparql',
@@ -186,20 +202,17 @@
 
     def test_sparql_json(self):
         results = sparqljson(u'http://dbpedia.org/sparql',
-                             u'''SELECT DISTINCT ?uri
-                             WHERE{
-                             ?uri rdfs:label "Python"@en .
-                             ?uri rdf:type ?type}''')
-        self.assertEqual(results, {u'uri': set([u'http://sw.opencyc.org/2008/06/10/concept/Mx4r74UIARqkEdac2QACs0uFOQ', u'http://sw.opencyc.org/2008/06/10/concept/en/Python_ProgrammingLanguage', u'http://dbpedia.org/resource/Python'])})
-
-    def test_sparql_json2(self):
-        results = sparqljson(u'http://dbpedia.org/sparql',
-                             u'''SELECT DISTINCT ?uri ?label
-                             WHERE{
-                             ?uri rdfs:label "Python"@en .
-                             ?uri rdfs:label ?label .
-                             ?uri rdf:type ?type}''')
-        self.assertEqual(results, {u'uri': set([u'http://sw.opencyc.org/2008/06/10/concept/Mx4r74UIARqkEdac2QACs0uFOQ', u'http://sw.opencyc.org/2008/06/10/concept/en/Python_ProgrammingLanguage', u'http://dbpedia.org/resource/Python']), u'label': u'Python'})
+                             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"))
+                                 }''')
+        self.assertEqual(results,
+                         {'designer': set(['http://dbpedia.org/resource/Guido_van_Rossum']),
+                          'uri': set(['http://dbpedia.org/resource/Python_(programming_language)',
+                                      'http://dbpedia.org/resource/Python_for_S60'])})
 
     def test_sparql_autocast(self):
         alignset = sparqlquery('http://dbpedia.inria.fr/sparql',
--- a/test/test_ner.py	Thu Nov 20 11:26:29 2014 +0100
+++ b/test/test_ner.py	Sun Nov 23 18:59:29 2014 +0100
@@ -57,14 +57,16 @@
     def test_sparql_source(self):
         """ Test sparql source """
         source = NerSourceSparql(u'http://dbpedia.org/sparql',
-                                 u'''SELECT DISTINCT ?uri
-                                     WHERE{
-                                     ?uri rdfs:label "%(word)s"@en .
-                                     ?uri rdf:type ?type}''')
+                             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"))
+                                 }''')
         self.assertEqual(source.query_word('Python'),
-                         [u'http://dbpedia.org/resource/Python',
-                          u'http://sw.opencyc.org/2008/06/10/concept/en/Python_ProgrammingLanguage',
-                          u'http://sw.opencyc.org/2008/06/10/concept/Mx4r74UIARqkEdac2QACs0uFOQ'])
+                         ['http://dbpedia.org/resource/Python_(programming_language)',
+                          'http://dbpedia.org/resource/Python_for_S60'])
 
     @unittest.skipUnless(NLTK_AVAILABLE, 'nltk is not available')
     def test_ner_process(self):