[pypy-svn] r42512 - pypy/dist/pypy/lib/pyontology/test
ale at codespeak.net
ale at codespeak.net
Tue May 1 08:55:46 CEST 2007
Author: ale
Date: Tue May 1 08:55:44 2007
New Revision: 42512
Modified:
pypy/dist/pypy/lib/pyontology/test/test_sparql.py
Log:
Changed and added test for SPARQL.
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 Tue May 1 08:55:44 2007
@@ -69,7 +69,7 @@
assert len(res[0]) == len(res[1]) == 4
assert res[0][1] in ['http://example.org/ns#p', 'http://example.org/ns#q']
assert res[1][1] in ['http://example.org/ns#p', 'http://example.org/ns#q']
- assert result[3][0] == 'x<2'
+ assert result[3].formula == 'query_x<2'
# There are 8 ways of having the triples in the query, if predicate is not a builtin owl predicate
#
@@ -113,6 +113,7 @@
O.attach_fd()
O.finish()
res = O.sparql(query)
+ assert len(res) == 1
assert res[0]['x'] == u'http://example.org/ns#sub'
def test_case_2():
@@ -166,7 +167,6 @@
res = O.sparql(query)
assert res[0]['x'] == u'http://example.org/ns#sub'
assert res[0]['y'] == 123
- assert res[0]['x'] == u'http://example.org/ns#sub'
def test_case_6():
""" return the values of p """
@@ -202,7 +202,88 @@
O.finish()
res = O.sparql(query)
assert res[0]['y'] == 123
+
+query_x = """
+ PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
+ PREFIX owl : <http://www.w3.org/2002/07/owl#>
+ PREFIX rdf : <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+ SELECT ?x
+ WHERE {
+ ?x rdf:type ltw:Active_FundingOrganisation .
+ ?x ltw:organisationNameAbbreviation 'BMBF' .
+ }"""
+
+def test_queryx():
+ O = Ontology()
+ O.add_file(datapath("testont2.rdf"), 'xml')
+ O.attach_fd()
+
+ res = O.sparql(query_x)
+ assert len(res) == 1
+ assert res[0]['x'] == u'http://www.lt-world.org/ltw.owl#obj_61128'
+
+query_y = """
+ PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
+ PREFIX owl : <http://www.w3.org/2002/07/owl#>
+ PREFIX rdf : <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
+ SELECT ?project
+ WHERE {
+ ?project ltw:dateStart ?date_begin .
+ ?project ltw:dateEnd ?date_end .
+ FILTER ( ?date_begin < "2007-01-01T00:00:00Z"^^xsd:dateTime
+ && ?date_end >= "2006-01-01T00:00:00Z"^^xsd:dateTime) .
+ }"""
+
+
+def test_queryy():
+ py.test.skip("Needs special care for dateTime type")
+ O = Ontology()
+ O.add_file(datapath("testont2.rdf"), 'xml')
+ O.attach_fd()
+
+ res = O.sparql(query_y)
+ assert len(res) == 1
+ assert res[0]['project'] == u'http://www.lt-world.org/ltw.owl#obj_61128'
+
+
+query1_a = """
+ PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
+ PREFIX owl : <http://www.w3.org/2002/07/owl#>
+ PREFIX rdf : <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+ SELECT ?person ?activity
+ WHERE {
+ ?activity rdf:type ltw:Active_Project .
+ ?person rdf:type ltw:Active_Person .
+ }
+ ORDER BY ?person"""
+query1_b = """
+ PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
+ PREFIX owl : <http://www.w3.org/2002/07/owl#>
+ PREFIX rdf : <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+ SELECT ?person ?activity
+ WHERE {
+ ?activity ltw:hasParticipant ?person_obj .
+ ?person_obj ltw:personName ?person .
+ }
+ ORDER BY ?person"""
+def test_query1_a():
+ O = Ontology()
+ O.add_file(datapath("testont2.rdf"), 'xml')
+ O.attach_fd()
+
+ res = O.sparql(query1_a)
+ assert len(res) == 1
+
+def test_query1_b():
+ O = Ontology()
+ O.add_file(datapath("testont2.rdf"), 'xml')
+ O.attach_fd()
+
+ res = O.sparql(query1_b)
+ assert len(res) == 1
+
query1 = """
PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
PREFIX owl : <http://www.w3.org/2002/07/owl#>
@@ -219,19 +300,22 @@
query2 = """
PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
PREFIX owl : <http://www.w3.org/2002/07/owl#>
- SELECT ?project ?date_begin
+ PREFIX rdf : <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+ SELECT ?project ?date_begin ?x
WHERE {
- ?project ltw:supportedBy ltw:BMBF .
+ ?project ltw:supportedBy ?x .
+ ?x rdf:type ltw:Active_FundingOrganisation .
+ ?x ltw:organisationNameAbbreviation 'BMBF' .
?project ltw:dateStart ?date_begin .
?project ltw:dateEnd ?date_end .
FILTER ( ?date_begin < 2007 && ?date_end >= 2006) .
}"""
#which project is funded in a technological area (i.e. Semantic web),
-query3 = """
+query_3 = """
PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
PREFIX owl : <http://www.w3.org/2002/07/owl#>
PREFIX rdf : <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
- SELECT ?project
+ SELECT ?project ?x ?y
WHERE {
?project rdf:type ltw:Active_Project .
?project ltw:lt_technologicalMethod ?y .
@@ -239,7 +323,47 @@
?project ltw:supportedBy ?x .
}"""
-def test_query1():
+query3a = """
+ PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
+ PREFIX owl : <http://www.w3.org/2002/07/owl#>
+ PREFIX rdf : <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+ SELECT ?project ?x ?y
+ WHERE {
+ ?project rdf:type ltw:Active_Project .
+ ?project ltw:lt_technologicalMethod ?y .
+ }"""
+
+query3b = """
+ PREFIX ltw : <http://www.lt-world.org/ltw.owl#>
+ PREFIX owl : <http://www.w3.org/2002/07/owl#>
+ PREFIX rdf : <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+ SELECT ?project ?x ?y
+ WHERE {
+ ?y rdf:type ltw:Semantic_Web .
+ ?project ltw:supportedBy ?x .
+ }"""
+
+def test_query3a():
+ py.test.skip("WIP")
+ O = Ontology()
+ O.add_file(datapath("testont2.rdf"), 'xml')
+ O.attach_fd()
+
+ res = O.sparql(query3a)
+ assert len(res) == 1
+ assert res[0]['project'] == u'http://www.lt-world.org/ltw.owl#obj_59773'
+
+def test_query3b():
+ py.test.skip("WIP")
+ O = Ontology()
+ O.add_file(datapath("testont2.rdf"), 'xml')
+ O.attach_fd()
+
+ res = O.sparql(query3a)
+ assert len(res) == 1
+ assert res[0]['project'] == u'http://www.lt-world.org/ltw.owl#obj_59773'
+
+def test_query_1():
O = Ontology()
O.add_file(datapath("testont2.rdf"), 'xml')
O.attach_fd()
@@ -249,27 +373,26 @@
assert res[0]['activity'] == u'http://www.lt-world.org/ltw.owl#obj_59754'
assert res[0]['person'] == u'\nKlara Vicsi'
-def test_query2():
-# py.test.skip("Doesn't work yet")
+def test_query_2():
+ py.test.skip("Needs special care for dateTime type")
O = Ontology()
O.add_file(datapath("testont2.rdf"), 'xml')
O.attach_fd()
res = O.sparql(query2)
- assert len(res) == 2
+ assert len(res) == 1
assert res[0]['project'] == u'http://www.lt-world.org/ltw.owl#obj_59754'
assert res[0]['date_begin'] == datetime.date(1998,9,1)
-def test_query3():
- #py.test.skip("Doesn't work yet")
+def test_query_3():
+ py.test.skip("WIP")
O = Ontology()
O.add_file(datapath("testont2.rdf"), 'xml')
O.attach_fd()
- res = O.sparql(query3)
+ res = O.sparql(query_3)
assert len(res) == 1
- assert res[0]['activity'] == u'http://www.lt-world.org/ltw.owl#obj_59754'
- assert res[0]['person'] == u'\nKlara Vicsi'
+ assert res[0]['project'] == u'http://www.lt-world.org/ltw.owl#obj_59773'
import xmlrpclib, socket, os, signal
More information about the pypy-svn
mailing list