distinct / reduced support
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 22 Jul 2009 19:42:35 +0200
changeset 2427 3e0ef847a546
parent 2426 0209d9bc45a8
child 2428 a3e10e6a2461
distinct / reduced support
spa2rql.py
test/unittest_spa2rql.py
--- a/spa2rql.py	Wed Jul 22 19:42:10 2009 +0200
+++ b/spa2rql.py	Wed Jul 22 19:42:35 2009 +0200
@@ -45,6 +45,8 @@
                 unions = zip(*make_domains([unions, thisunions]))
         baserql = 'Any %s WHERE %s' % (', '.join(self.selection),
                                        ', '.join(self.restrictions))
+        if self.sparqlst.distinct:
+            baserql = 'DISTINCT ' + baserql
         if not unions:
             return baserql
         rqls = ['(%s, %s)' % (baserql, ', '.join(unionrestrs))
--- a/test/unittest_spa2rql.py	Wed Jul 22 19:42:10 2009 +0200
+++ b/test/unittest_spa2rql.py	Wed Jul 22 19:42:35 2009 +0200
@@ -41,6 +41,24 @@
               doap:created ?created.
     }''', 'Any CREATED WHERE PROJECT creation_date CREATED, PROJECT is Project')
 
+    def test_base_attr_sel_distinct(self):
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT DISTINCT ?name
+    WHERE  {
+      ?project a doap:Project;
+              doap:name ?name.
+    }''', 'DISTINCT Any NAME WHERE PROJECT name NAME, PROJECT is Project')
+
+    def test_base_attr_sel_reduced(self):
+        self._test('''
+    PREFIX doap: <http://usefulinc.com/ns/doap#>
+    SELECT REDUCED ?name
+    WHERE  {
+      ?project a doap:Project;
+              doap:name ?name.
+    }''', 'Any NAME WHERE PROJECT name NAME, PROJECT is Project')
+
 
     def test_base_any_attr_sel(self):
         self._test('''