Ejemplo n.º 1
0
    def test_named_terms_matches_a_token(self):
        '''
        Ensures that all terms are named, and they are bound to a token that is
        in the query.
        '''
        from itertools import izip
        from xotl.ql.core import thesefy
        from xotl.ql.translate import cofind_tokens

        @thesefy
        class Person(object):
            pass

        @thesefy
        class Partnership(object):
            pass

        query = these((person, partner)
                      for person, partner in izip(Person, Person)
                      for rel in Partnership
                      if (rel.subject == person) & (rel.obj == partner)
                      if person.age > 35)

        tokens = query.tokens
        matches_token = lambda term: (term.name and (
            term.binding.expression in tokens or matches_token(term.parent)))
        with context(UNPROXIFING_CONTEXT):
            self.assertTrue(
                all(
                    matches_token(term)
                    for term in cofind_tokens(*query.filters)))
Ejemplo n.º 2
0
    def test_named_terms_matches_a_token(self):
        '''
        Ensures that all terms are named, and they are bound to a token that is
        in the query.
        '''
        from itertools import izip
        from xotl.ql.core import thesefy
        from xotl.ql.translate import cofind_tokens

        @thesefy
        class Person(object):
            pass

        @thesefy
        class Partnership(object):
            pass

        query = these((person, partner)
                      for person, partner in izip(Person, Person)
                      for rel in Partnership
                      if (rel.subject == person) & (rel.obj == partner)
                      if person.age > 35)

        tokens = query.tokens
        matches_token = lambda term: (term.name and (
                                      term.binding.expression in tokens or
                                      matches_token(term.parent)))
        with context(UNPROXIFING_CONTEXT):
            self.assertTrue(all(matches_token(term)
                                for term in cofind_tokens(*query.filters)))
Ejemplo n.º 3
0
    def test_cofind_tokens(self):
        from itertools import izip
        from xotl.ql.expressions import is_a
        from xotl.ql.translate import cofind_tokens

        @thesefy
        class Person(object):
            pass

        @thesefy
        class Partnership(object):
            pass

        query = these((person, partner)
                      for person, partner in izip(Person, Person)
                      for rel in Partnership
                      if (rel.subject == person) & (rel.obj == partner))
        filters = list(query.filters)
        person, partner = query.selection
        person_is_a_person = is_a(person, Person)
        partner_is_a_person = is_a(partner, Person)
        with context(UNPROXIFING_CONTEXT):
            self.assertNotEqual(person, partner)
            self.assertIn(person_is_a_person, filters)
            self.assertIn(partner_is_a_person, filters)
            filters.remove(person_is_a_person)
            filters.remove(partner_is_a_person)
            # left filter are is_a(rel, Partnership) and the explicit we see in
            # the query expression
            self.assertIs(2, len(filters))

            rel_is_a = next(f for f in filters
                            if f.operation == is_a)
            filters.remove(rel_is_a)

            # there are 4 named instances in the left filter
            # (rel.subject == person) & (rel.obj == partner)
            self.assertIs(4, len(list(cofind_tokens(filters[0]))))
Ejemplo n.º 4
0
    def test_cofind_tokens(self):
        from itertools import izip
        from xotl.ql.expressions import is_a
        from xotl.ql.translate import cofind_tokens

        @thesefy
        class Person(object):
            pass

        @thesefy
        class Partnership(object):
            pass

        query = these((person, partner)
                      for person, partner in izip(Person, Person)
                      for rel in Partnership
                      if (rel.subject == person) & (rel.obj == partner))
        filters = list(query.filters)
        person, partner = query.selection
        person_is_a_person = is_a(person, Person)
        partner_is_a_person = is_a(partner, Person)
        with context(UNPROXIFING_CONTEXT):
            self.assertNotEqual(person, partner)
            self.assertIn(person_is_a_person, filters)
            self.assertIn(partner_is_a_person, filters)
            filters.remove(person_is_a_person)
            filters.remove(partner_is_a_person)
            # left filter are is_a(rel, Partnership) and the explicit we see in
            # the query expression
            self.assertIs(2, len(filters))

            rel_is_a = next(f for f in filters if f.operation == is_a)
            filters.remove(rel_is_a)

            # there are 4 named instances in the left filter
            # (rel.subject == person) & (rel.obj == partner)
            self.assertIs(4, len(list(cofind_tokens(filters[0]))))