Example #1
0
 def test_empty_chain_length_5(self):
     DC = get(Namespace, 'dc')
     TMP = create(Namespace, 'tmp', 'http://tmp/tmp#')
     TMQ = create(Namespace, 'tmq', 'http://tmq/tmq#')
     C, D, E, F, G = create(
         (Concept, TMP, 'C'), (Concept, TMP, 'D'), (Concept, TMP, 'E'), 
         (Concept, TMQ, 'F'), (Concept, TMQ, 'G'))
     one_one = Cardinality.objects.get(domain='1', range='1') # IGNORE:E1101
     P = create(Predicate, TMP, 'P', domain=C, range=D, cardinality=one_one)
     Q = create(Predicate, TMP, 'Q', domain=D, range=E, cardinality=one_one)
     R = create(Predicate, TMQ, 'R', domain=E, range=F, cardinality=one_one)
     S = create(Predicate, TMQ, 'S', domain=F, range=G, cardinality=one_one)
     rqs = SPARQLQuerySet().rdql(u'''
         select c.rdf:about, e.dc:title, g.dc:description 
         from tmp:C c, tmp:D d, tmp:E e, tmq:F f, tmq:G g
         where c tmp:P d
           and d tmp:Q e 
           and e tmq:R f
           and f tmq:S g
         using tmp for "http://tmp/tmp#",
               tmq for "http://tmq/tmq#",
               dc for "http://purl.org/dc/elements/1.1/",
               rdf for "http://www.w3.org/1999/02/22-rdf-syntax-ns#"''')
     select = u'select c.name, e__dc__title__o.value, g__dc__description__o.value from rdf_statement e__dc__title__s, rdf_statement e__tmq__R__s, rdf_resource e, rdf_resource d, rdf_resource g, rdf_resource f, rdf_statement c__tmp__P__s, rdf_statement f__tmq__S__s, rdf_resource c, rdf_statement g__dc__description__s, rdf_string g__dc__description__o, rdf_statement d__tmp__Q__s, rdf_string e__dc__title__o where c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.object_resource_id = d.id and d__tmp__Q__s.subject_id = d.id and d__tmp__Q__s.predicate_id = %s and d__tmp__Q__s.object_resource_id = e.id and e__tmq__R__s.subject_id = e.id and e__tmq__R__s.predicate_id = %s and e__tmq__R__s.object_resource_id = f.id and f__tmq__S__s.subject_id = f.id and f__tmq__S__s.predicate_id = %s and f__tmq__S__s.object_resource_id = g.id and c.type_id = %s and e.type_id = %s and d.type_id = %s and g.type_id = %s and f.type_id = %s and e__dc__title__s.subject_id = e.id and e__dc__title__s.predicate_id = %s and e__dc__title__s.id = e__dc__title__o.statement_id and g__dc__description__s.subject_id = g.id and g__dc__description__s.predicate_id = %s and g__dc__description__s.id = g__dc__description__o.statement_id' % (P.id, Q.id, R.id, S.id, C.id, E.id, D.id, G.id, F.id, DC['title'].id, DC['description'].id)
     count = u'select count(*) from rdf_statement e__dc__title__s, rdf_statement e__tmq__R__s, rdf_resource e, rdf_resource d, rdf_resource g, rdf_resource f, rdf_statement c__tmp__P__s, rdf_statement f__tmq__S__s, rdf_resource c, rdf_statement g__dc__description__s, rdf_string g__dc__description__o, rdf_statement d__tmp__Q__s, rdf_string e__dc__title__o where c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.object_resource_id = d.id and d__tmp__Q__s.subject_id = d.id and d__tmp__Q__s.predicate_id = %s and d__tmp__Q__s.object_resource_id = e.id and e__tmq__R__s.subject_id = e.id and e__tmq__R__s.predicate_id = %s and e__tmq__R__s.object_resource_id = f.id and f__tmq__S__s.subject_id = f.id and f__tmq__S__s.predicate_id = %s and f__tmq__S__s.object_resource_id = g.id and c.type_id = %s and e.type_id = %s and d.type_id = %s and g.type_id = %s and f.type_id = %s and e__dc__title__s.subject_id = e.id and e__dc__title__s.predicate_id = %s and e__dc__title__s.id = e__dc__title__o.statement_id and g__dc__description__s.subject_id = g.id and g__dc__description__s.predicate_id = %s and g__dc__description__s.id = g__dc__description__o.statement_id' % (P.id, Q.id, R.id, S.id, C.id, E.id, D.id, G.id, F.id, DC['title'].id, DC['description'].id)
     self.assertEqual(0, rqs.count())
     self.assertEqual(getattr(rqs, '_cached_query').select, select)
     self.assertEqual(getattr(rqs, '_cached_query').count, count)
     self.assertEqual(0, len(rqs.filter())) # IGNORE:E1101
Example #2
0
def sparql(request):
    """
    Returns the results of the SPARQL query in the `sparql` POST parameter, formatted 
    as RDF/XML.
    """
    offset = int(request['offset']) if request.has_key('offset') else 0
    limit = int(request['limit']) if request.has_key('limit') else 100
    sparql = request['sparql']
    qs = SPARQLQuerySet().sparql(sparql)
    return render_as_rdf(
        resources=qs[offset:limit], count=qs.count(), limit=limit, offset=offset)
Example #3
0
 def test_simple_empty_self_referential(self):
     TMP = create(Namespace, 'tmp', 'http://tmp/tmp#')
     C = create(Concept, TMP, 'C')
     one_one = Cardinality.objects.get(domain='1', range='1') # IGNORE:E1101
     P = create(Predicate, TMP, 'P', domain=C, range=C, cardinality=one_one)
     self.assertFalse(P.literal)
     rqs = SPARQLQuerySet().rdql(\
         u'select c.tmp:P from tmp:C c using tmp for "http://tmp/tmp#"')
     select = u'''select c__tmp__P__o.name from rdf_resource c, rdf_statement c__tmp__P__s, rdf_resource c__tmp__P__o where c.type_id = %s and c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.object_resource_id = c__tmp__P__o.id''' % (C.id, P.id)
     count = u'''select count(*) from rdf_resource c, rdf_statement c__tmp__P__s, rdf_resource c__tmp__P__o where c.type_id = %s and c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.object_resource_id = c__tmp__P__o.id''' % (C.id, P.id)
     self.assertEqual(0, rqs.count())
     self.assertEqual(getattr(rqs, '_cached_query').select, select)
     self.assertEqual(getattr(rqs, '_cached_query').count, count)
     self.assertEqual(0, len(rqs.filter())) # IGNORE:E1101
Example #4
0
 def test_simple_empty_with_literal_object(self):
     XS = get(Namespace, 'xs')
     TMP = create(Namespace, 'tmp', 'http://tmp/tmp#')
     TEXT = XS['string']
     self.assertTrue(TEXT.literal)
     C = create(Concept, TMP, 'C') # Defaults to 'rdf.models.Resource'
     one_one = Cardinality.objects.get(domain='1', range='1') # IGNORE:E1101
     P = create(Predicate, TMP, 'P', domain=C, range=TEXT, cardinality=one_one)
     self.assertTrue(P.literal)
     rqs = SPARQLQuerySet().rdql(\
         u'select c.tmp:P from tmp:C c using tmp for "http://tmp/tmp#"')
     select = u'''select c__tmp__P__o.value from rdf_resource c, rdf_statement c__tmp__P__s, rdf_string c__tmp__P__o where c.type_id = %s and c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.id = c__tmp__P__o.statement_id''' % (C.id, P.id)
     count = u'''select count(*) from rdf_resource c, rdf_statement c__tmp__P__s, rdf_string c__tmp__P__o where c.type_id = %s and c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.id = c__tmp__P__o.statement_id''' % (C.id, P.id)
     self.assertEqual(0, rqs.count())
     self.assertEqual(getattr(rqs, '_cached_query').select, select)
     self.assertEqual(getattr(rqs, '_cached_query').count, count)
     self.assertEqual(0, len(rqs.filter())) # IGNORE:E1101
Example #5
0
 def test_empty_chain_length_2(self):
     TMP = create(Namespace, 'tmp', 'http://tmp/tmp#')
     C, D, E = create((Concept, TMP, 'C'), (Concept, TMP, 'D'), (Concept, TMP, 'E'))
     one_one = Cardinality.objects.get(domain='1', range='1') # IGNORE:E1101
     P = create(Predicate, TMP, 'P', domain=C, range=D, cardinality=one_one)
     Q = create(Predicate, TMP, 'Q', domain=D, range=E, cardinality=one_one)
     rqs = SPARQLQuerySet().rdql(u'''
         select c.rdf:about, e.rdf:about 
         from tmp:C c, tmp:D d, tmp:E e
         where c tmp:P d
           and d tmp:Q e 
         using tmp for "http://tmp/tmp#",
               rdf for "http://www.w3.org/1999/02/22-rdf-syntax-ns#"''')
     select = u'select c.name, e.name from rdf_resource c, rdf_statement c__tmp__P__s, rdf_resource e, rdf_resource d, rdf_statement d__tmp__Q__s where c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.object_resource_id = d.id and d__tmp__Q__s.subject_id = d.id and d__tmp__Q__s.predicate_id = %s and d__tmp__Q__s.object_resource_id = e.id and c.type_id = %s and e.type_id = %s and d.type_id = %s' % (P.id, Q.id, C.id, E.id, D.id)
     count = u'select count(*) from rdf_resource c, rdf_statement c__tmp__P__s, rdf_resource e, rdf_resource d, rdf_statement d__tmp__Q__s where c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.object_resource_id = d.id and d__tmp__Q__s.subject_id = d.id and d__tmp__Q__s.predicate_id = %s and d__tmp__Q__s.object_resource_id = e.id and c.type_id = %s and e.type_id = %s and d.type_id = %s' % (P.id, Q.id, C.id, E.id, D.id)
     self.assertEqual(0, rqs.count())
     self.assertEqual(getattr(rqs, '_cached_query').select, select)
     self.assertEqual(getattr(rqs, '_cached_query').count, count)
     self.assertEqual(0, len(rqs.filter())) # IGNORE:E1101
Example #6
0
 def XXXtest_empty_chain_length_2_shorthand(self):
     """
     This shorthand notation is not yet supported by the compiler and maybe never will.
     """
     TMP = create(Namespace, 'tmp', 'http://tmp/tmp#')
     C, D, E = create((Concept, TMP, 'C'), (Concept, TMP, 'D'), (Concept, TMP, 'E'))
     one_one = Cardinality.objects.get(domain='1', range='1') # IGNORE:E1101
     P = create(Predicate, TMP, 'P', domain=C, range=D, cardinality=one_one)
     Q = create(Predicate, TMP, 'Q', domain=D, range=E, cardinality=one_one)
     rqs = SPARQLQuerySet().rdql(u'''
         select c.rdf:about, c.tmp:P.tmp:Q.rdf:about 
         from tmp:C c
         using tmp for "http://tmp/tmp#",
               rdf for "http://www.w3.org/1999/02/22-rdf-syntax-ns#"''')
     select = u'''select c__tmp__P__o.name from rdf_resource c, rdf_statement c__tmp__P__s, rdf_resource c__tmp__P__o where c.type_id = %s and c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.object_resource_id = c__tmp__P__o.id''' % (C.id, P.id)
     count = u'''select count(*) from rdf_resource c, rdf_statement c__tmp__P__s, rdf_resource c__tmp__P__o where c.type_id = %s and c__tmp__P__s.subject_id = c.id and c__tmp__P__s.predicate_id = %s and c__tmp__P__s.object_resource_id = c__tmp__P__o.id''' % (C.id, P.id)
     self.assertEqual(0, rqs.count())
     self.assertEqual(getattr(rqs, '_cached_query').select, select)
     self.assertEqual(getattr(rqs, '_cached_query').count, count)
     self.assertEqual(0, len(rqs.filter())) # IGNORE:E1101