[sparql] fix type inference (test_dctitle_both_project_cwuser) and support for <http://www.w3.org/1999/02/22-rdf-syntax-ns#type tag (test_base_rdftype)
--- a/spa2rql.py Tue Jun 01 08:35:09 2010 +0200
+++ b/spa2rql.py Tue Jun 01 08:54:40 2010 +0200
@@ -15,9 +15,8 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
-"""SPARQL -> RQL translator
+"""SPARQL -> RQL translator"""
-"""
from logilab.common import make_domains
from rql import TypeResolverException
from fyzz.yappsparser import parse
@@ -98,8 +97,8 @@
modified = True
# restrict predicates according to allowed subject var types
if subjvar in self.possible_types:
- yams_predicates = [(s, r, o) for s, r, o in yams_predicates
- if s == '*' or s in self.possible_types[subjvar]]
+ yams_predicates[:] = [(s, r, o) for s, r, o in yams_predicates
+ if s == '*' or s in self.possible_types[subjvar]]
if isinstance(obj, ast.SparqlVar):
# make a valid rql var name
objvar = obj.name.upper()
@@ -111,8 +110,8 @@
modified = True
# restrict predicates according to allowed object var types
if objvar in self.possible_types:
- yams_predicates = [(s, r, o) for s, r, o in yams_predicates
- if o == '*' or o in self.possible_types[objvar]]
+ yams_predicates[:] = [(s, r, o) for s, r, o in yams_predicates
+ if o == '*' or o in self.possible_types[objvar]]
# ensure this still make sense
if not yams_predicates:
raise TypeResolverException()
@@ -197,7 +196,8 @@
raise UnsupportedQuery()
# make a valid rql var name
subjvar = subj.name.upper()
- if predicate == ('', 'a'):
+ if predicate in [('', 'a'),
+ ('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'type')]:
# special 'is' relation
if not isinstance(obj, tuple):
raise UnsupportedQuery()
--- a/test/unittest_spa2rql.py Tue Jun 01 08:35:09 2010 +0200
+++ b/test/unittest_spa2rql.py Tue Jun 01 08:54:40 2010 +0200
@@ -188,7 +188,7 @@
WHERE {
?project a doap:Project;
dc:title ?title.
- }''', 'Any PROJECT,TITLE WHERE PROJECT name TITLE, PROJECT is Project')
+ }''', 'Any PROJECT, TITLE WHERE PROJECT name TITLE, PROJECT is Project')
# # Two elements in the group
# PREFIX : <http://example.org/ns#>
--- a/xy.py Tue Jun 01 08:35:09 2010 +0200
+++ b/xy.py Tue Jun 01 08:54:40 2010 +0200
@@ -15,9 +15,7 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
-"""map standard cubicweb schema to xml vocabularies
-
-"""
+"""map standard cubicweb schema to xml vocabularies"""
from yams import xy