[pypy-svn] r34625 - in pypy/dist/pypy/lib/pyontology: . test

ale at codespeak.net ale at codespeak.net
Wed Nov 15 13:29:36 CET 2006


Author: ale
Date: Wed Nov 15 13:29:34 2006
New Revision: 34625

Added:
   pypy/dist/pypy/lib/pyontology/test/testinconst.rdf
   pypy/dist/pypy/lib/pyontology/test/testont2.rdf
Modified:
   pypy/dist/pypy/lib/pyontology/pyontology.py
   pypy/dist/pypy/lib/pyontology/test/test_ontology.py
   pypy/dist/pypy/lib/pyontology/test/test_sparql.py
Log:
Added more tests and fixes to SPARQL 


Modified: pypy/dist/pypy/lib/pyontology/pyontology.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/pyontology.py	(original)
+++ pypy/dist/pypy/lib/pyontology/pyontology.py	Wed Nov 15 13:29:34 2006
@@ -467,6 +467,8 @@
             self.store_path = py.path.local().join("db").strpath
         self.variables = {}
         self.constraints = []
+        self.variables['owl_Thing'] = Thing('owl_Thing')
+        self.variables['owl_Literal'] = Literal('owl_Literal')
         self.seen = {}
         self.var2ns ={}
         self.nr_of_triples = 0
@@ -514,6 +516,9 @@
                 constraint.narrow(self.variables)
 #                except ConsistencyFailure, e:
 #                    print "FAilure", e
+        things = self.variables['owl_Thing'].getValues()
+        things += self.variables['owl_Literal'].getValues()
+        self.variables['owl_Thing'].setValues(things)
 
     def _sparql(self, query):
         qe = SP.Query.parseString(query)
@@ -585,9 +590,13 @@
                     raise ConsistencyFailure
             elif case == 1:
                 # Add a HasValue constraint
-                var = self.make_var(Restriction, URIRef(trip[0]))
-                self.onProperty(var, URIRef(trip[1]))
-                self.hasValue(var, trip[2])
+                ns,pred = trip[1].split("#")
+                if ns in namespaces.values():
+                    self.consider_triple(trip)
+                else:
+                    var = self.make_var(Restriction, URIRef(trip[0]))
+                    self.onProperty(var, URIRef(trip[1]))
+                    self.hasValue(var, trip[2])
             elif case == 2:
                 #  for all p's return p if p[0]==s and p[1]==o
 
@@ -640,28 +649,33 @@
             elif case == 5:
                 #  return the values of p
                 prop = self.make_var(Property, URIRef(trip[1]))
+                query_dom[prop] = self.variables[prop]
                 p_vals = self.variables[prop].getValues()
-                var = self.make_var(Thing, trip[0])
-                self.variables[var].setValues([v[0] for v in p_vals])
-                p_vals = self.variables[prop].getValues()
-                var = self.make_var(Thing, trip[2])
-                self.variables[var].setValues([v[1] for v in p_vals])
+                sub = self.make_var(Thing, trip[0])
+                self.variables[sub].setValues([v[0] for v in p_vals])
+                obj = self.make_var(Thing, trip[2])
+                self.variables[obj].setValues([v[1] for v in p_vals])
+                con = Expression([sub,prop,obj], "%s == (%s, %s)" %(prop, sub, obj))
+                query_constr.append(con)
+
             elif case == 6:
-                #  for all p's return p[1] if p[0]==s  
+# 6     bound           var             var    ; for all p's return p[1] if p[0]==s
+                #  for all p's return p[1] if p[0]==s 
+                prop = self.make_var(Property, URIRef(trip[1]))
+
                 pass
             elif case == 7:
                 #  for all p's return p.getvalues
                 p_vals = []
                 for p in self.variables['rdf_Property'].getValues():
                     p_vals += self.variables[p].getValues()
-                
-                things = self.variables['owl_Thing'].getValues()
-                things += self.variables['owl_Literal'].getValues()
+                    
                 prop = self.make_var(Property, URIRef(trip[1]))
                 self.variables[prop].setValues(p_vals)
                 sub = self.make_var(Thing, trip[0])
-                self.variables[sub].setValues(things)
                 obj = self.make_var(Thing, trip[2])
+                things = self.variables['owl_Thing'].getValues()
+                things += self.variables['owl_Literal'].getValues()
                 self.variables[obj].setValues(things)
                 con = Expression([sub,prop,obj], "%s[0] == %s and %s[1] == %s" %(prop, sub, prop, obj))
                 query_constr.append(con)
@@ -672,10 +686,12 @@
         # Build a repository with the variables in the query
         dom = dict([(self.mangle_name(v),self.variables[self.mangle_name(v)])
                      for v in vars])
+
         dom.update(query_dom)
+        print dom
         # solve the repository and return the solution
         rep = Repository(dom.keys(), dom, query_constr)
-        res_s = Solver().solve(rep)
+        res_s = Solver().solve(rep, 3)
         #res_s = self.solve()
         res = []
         for d in res_s:

Modified: pypy/dist/pypy/lib/pyontology/test/test_ontology.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/test/test_ontology.py	(original)
+++ pypy/dist/pypy/lib/pyontology/test/test_ontology.py	Wed Nov 15 13:29:34 2006
@@ -28,6 +28,12 @@
     ont.rest(own,  URIRef(namespaces['rdf']+'#nil'))
     return owllist
 
+def test_equivalentProperty_inconst():
+    O = Ontology()
+    O.add_file("testinconst.rdf")
+    O.attach_fd()
+    raises(ConsistencyFailure, O.consistency)
+
 def test_XMLSchema_string():
     O = Ontology()
     a = URIRef(u'A')

Modified: pypy/dist/pypy/lib/pyontology/test/test_sparql.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/test/test_sparql.py	(original)
+++ pypy/dist/pypy/lib/pyontology/test/test_sparql.py	Wed Nov 15 13:29:34 2006
@@ -161,7 +161,6 @@
 
 def test_case_7():
     """ for all p's return p[1] if p[0]==s """
-    #py.test.skip("Doesn't work yet")
 
     query = qt_proto % ('?x ?y ?z', '?x ?y ?z .')
     O = Ontology()
@@ -172,6 +171,49 @@
     assert list(O.variables['query_x_'].getValues())[0].uri == u'http://example.org/ns#sub' 
     assert res[0]['query_x_'] == u'http://example.org/ns#sub' 
  
+query1 = """
+        PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
+        PREFIX owl : <http://www.w3.org/2002/07/owl#>
+        SELECT ?person ?activity
+                WHERE {
+                                ?activity owl:subClassOf ltw:Active_Project .
+                                ?person_obj owl:subClassOf ltw:Active_Person .
+                                ?activity ltw:hasParticipant ?person_obj .
+                                ?person_obj ltw:personName ?person .
+                                }
+                ORDER BY ?person"""
+#how many projects have been funded by BMBF in 2006
+query2 = """
+        PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
+        PREFIX owl : <http://www.w3.org/2002/07/owl#>
+        SELECT ?project
+                WHERE {
+                        ?project ltw:funded_by ltw:BMBF .
+                        ?project ltw:date_begin ?date_begin .
+                        ?project ltw:date_end ?date_end .
+                                FILTER ( ?date_begin  < 2007 ) .
+                FILTER ( ?date_end >= 2006) .
+                                }"""
+#which project is funded in a technological area (i.e. Semantic web),
+query3 = """
+        PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
+        PREFIX owl : <http://www.w3.org/2002/07/owl#>
+        SELECT ?project
+                WHERE {
+                                ?project owl:subClassOf ltw:Active_Project .
+                                ?project owl:subClassOf ltw:Semantic_Web .
+                                ?project ltw:supportedby ?x .
+                                }"""
+
+def test_query1():
+    O = Ontology()
+    O.add_file("testont2.rdf")
+    O.attach_fd()
+
+    res = O.sparql(query1)
+    assert len(res) == 1
+    assert res[0]['query_activity_'] == u'http://www.lt-world.org/ltw.owl#obj_59754' 
+    assert res[0]['query_person_'] == u'\nKlara Vicsi' 
 
 import xmlrpclib, socket, os, signal
 
@@ -198,7 +240,6 @@
         os.kill(self.shell.pid, signal.SIGTERM)
 
     def test_xmlrpc(self):
-        #py.test.skip("WIP")
         print "test_xmlrpc"
         server = xmlrpclib.ServerProxy("http://localhost:9000", allow_none=True)
         result = server.sparql(qt_proto % ('?x', 'ns:sub ns:p ?x .'))

Added: pypy/dist/pypy/lib/pyontology/test/testinconst.rdf
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/pyontology/test/testinconst.rdf	Wed Nov 15 13:29:34 2006
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rdf:RDF 
+    xmlns:p1="http://protege.stanford.edu/plugins/owl/protege#" 
+    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
+    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
+    xmlns:owl="http://www.w3.org/2002/07/owl#" 
+    xmlns="http://www.lt-world.org/ltw.owl#" 
+    xmlns:daml="http://www.daml.org/2001/03/daml+oil#" 
+    xmlns:dc="http://purl.org/dc/elements/1.1/" 
+    xmlns:reg="http://registry.dfki.de#" xml:base="http://www.lt-world.org/ltw.owl">
+<owl:FunctionalProperty rdf:ID="Prop1"/>
+<owl:ObjectProperty rdf:ID="Prop2">
+<owl:equivalentProperty rdf:resource ="#Prop1"/>
+</owl:ObjectProperty>
+
+<owl:Thing rdf:ID ="Indi1">
+    <Prop2>"Text 1"</Prop2>
+    <Prop2>"Text 22</Prop2>
+</owl:Thing>
+</rdf:RDF>

Added: pypy/dist/pypy/lib/pyontology/test/testont2.rdf
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/pyontology/test/testont2.rdf	Wed Nov 15 13:29:34 2006
@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<rdf:RDF xmlns:p1="http://protege.stanford.edu/plugins/owl/protege#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns="http://www.lt-world.org/ltw.owl#" xmlns:daml="http://www.daml.org/2001/03/daml+oil#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:reg="http://registry.dfki.de#" xml:base="http://www.lt-world.org/ltw.owl">
+<Active_Project rdf:ID="obj_59773">
+<hasParticipant rdf:resource="#obj_59772"/>
+<hasParticipant rdf:resource="#obj_59771"/>
+<hasParticipant rdf:resource="#obj_59770"/>
+<hasParticipant rdf:resource="#obj_59769"/>
+<hasParticipant rdf:resource="#obj_59768"/>
+<coordinatedBy rdf:resource="#obj_59772"/>
+<supportedBy rdf:resource="#obj_59717"/>
+<lt_technologicalMethod rdf:resource="#obj_59820"/>
+<lt_linguality rdf:resource="#lt-world_Individual_712"/>
+<lt_language rdf:resource="#lt-world_Individual_105"/>
+<lt_language rdf:resource="#lt-world_Individual_112"/>
+<lt_language rdf:resource="#lt-world_Individual_80"/>
+<lt_technologicalApplication rdf:resource="#KB_901071_Individual_73"/>
+<lt_technologicalApplication rdf:resource="#KB_901071_Individual_79"/>
+<dc_language rdf:resource="#lt-world_Individual_105"/>
+<lt_linguisticArea rdf:resource="#lt-world_Individual_808"/>
+<lt_linguisticArea rdf:resource="#lt-world_Individual_819"/>
+<lt_linguisticArea rdf:resource="#lt-world_Individual_816"/>
+<lt_linguisticArea rdf:resource="#lt-world_Individual_806"/>
+<homepageURL>
+http://sites.univ-lyon2.fr/langues_promodiinar/Accueil.htm</homepageURL>
+<projectTheme>
+The aim of DIINAR-MBS is to create a multilingual lexical database based on a large corpus of linguistic data</projectTheme>
+<contact>
+joseph.dichy at univ-lyon2.fr</contact>
+<contact>
+joseph.dichy at univ-lyon2.fr</contact>
+<contact>
+joseph.dichy at univ-lyon2.fr</contact>
+<dc_keyword>
+NLP!Natural Language Processing!MT</dc_keyword>
+<dateEnd>
+2000-08-01</dateEnd>
+<dateStart>
+1998-02-01</dateStart>
+<dc_source>
+http://www.hltcentral.org/projects</dc_source>
+<dc_source>
+http://www.hltcentral.org/projects</dc_source>
+<projectName>
+Electronic Arab Dictionary - Multilingual Corpus</projectName>
+<projectNameVariant>
+Electronic Arab Dictionary - Multilingual Corpus</projectNameVariant>
+<projectNameAcronym>
+DIINAR-MBS</projectNameAcronym>
+<name>
+DIINAR-MBS</name>
+<projectNameVariant>
+DIINAR-MBS</projectNameVariant>
+</Active_Project>
+<Active_Project rdf:ID="obj_59754">
+<lt_technologicalMethod rdf:resource="#obj_60513"/>
+<lt_technologicalMethod rdf:resource="#obj_60889"/>
+<lt_technologicalMethod rdf:resource="#obj_60120"/>
+<supportedBy rdf:resource="#obj_59717"/>
+<hasParticipant rdf:resource="#obj_59750"/>
+<hasParticipant rdf:resource="#obj_59751"/>
+<hasParticipant rdf:resource="#obj_59752"/>
+<hasParticipant rdf:resource="#obj_59753"/>
+<hasParticipant rdf:resource="#obj_59749"/>
+<coordinatedBy rdf:resource="#obj_59750"/>
+<lt_language rdf:resource="#lt-world_Individual_105"/>
+<lt_language rdf:resource="#lt-world_Individual_188"/>
+<lt_language rdf:resource="#lt-world_Individual_125"/>
+<lt_language rdf:resource="#lt-world_Individual_193"/>
+<dc_language rdf:resource="#lt-world_Individual_105"/>
+<lt_technologicalApplication rdf:resource="#KB_788599_Individual_85"/>
+<lt_technologicalApplication rdf:resource="#KB_562804_Individual_61"/>
+<lt_technologicalApplication rdf:resource="#KB_788599_Individual_72"/>
+<lt_technologicalApplication rdf:resource="#KB_901071_Individual_79"/>
+<lt_linguality rdf:resource="#lt-world_Individual_712"/>
+<dateStart>
+1998-09-01</dateStart>
+<projectName>
+A Multimedia Multilingual Teaching and Training System for Speech Handicapped Children</projectName>
+<projectNameVariant>
+A Multimedia Multilingual Teaching and Training System for Speech Handicapped Children</projectNameVariant>
+<projectTheme>
+Development of a new audio-visual pronunciation teaching and training method and a software system for hearing and speech-handicapped persons to help them to control their speech production</projectTheme>
+<deadlinkURL>
+http://luna.ttt.bme.hu/speech/speco1.htm</deadlinkURL>
+<contact>
+vicsi at ttt-202.ttt.bme.hu</contact>
+<dc_source>
+http://www.hltcentral.org/projects</dc_source>
+<dateEnd>
+2001-08-31</dateEnd>
+<homepageURL>
+http://www.hltcentral.org/projects/detail.php?acronym=SPECO</homepageURL>
+<projectNameAcronym>
+SPECO</projectNameAcronym>
+<name>
+SPECO</name>
+<projectNameVariant>
+SPECO</projectNameVariant>
+</Active_Project>
+<Active_Person rdf:ID="obj_59750">
+<participatedIn rdf:resource="#obj_59754"/>
+<affiliatedWith rdf:resource="#obj_68035"/>
+<subaffiliatedWith rdf:resource="#obj_68644"/>
+<dc_language rdf:resource="#lt-world_Individual_105"/>
+<personName>
+Klara Vicsi</personName>
+<name>
+Klara Vicsi</name>
+<personNameVariant>
+Klara Vicsi</personNameVariant>
+<personEmail>
+vicsi at alpha.ttt.bme.hu</personEmail>
+<personFirstname1>
+Klara</personFirstname1>
+<personLastname>
+Vicsi</personLastname>
+<personTitle>
+Dr.</personTitle>
+</Active_Person>
+<Monitoring_Person rdf:ID="obj_59767">
+<participatedIn rdf:resource="#obj_59773"/>
+<dc_language rdf:resource="#lt-world_Individual_105"/>
+<personName>
+Abdelkader Fassi Fehri</personName>
+<name>
+Abdelkader Fassi Fehri</name>
+<personNameVariant>
+Abdelkader Fassi Fehri</personNameVariant>
+</Monitoring_Person>
+</rdf:RDF>



More information about the Pypy-commit mailing list