Exemplo n.º 1
0
    def test_select_single_query(self):
        bot = TestBot()
        self.load_data(bot.brain.rdf)

        select = RDFSelectStatement(["?x"], [
            RDFQuery(rdf_subject=TemplateWordNode("?x"),
                     rdf_predicate=TemplateWordNode("legs"),
                     rdf_object=TemplateWordNode("2"))
        ])
        self.assertIsNotNone(select)

        result = select.execute(bot, "testid")
        self.assertIsNotNone(result)
        self.assertEquals([['?x', 'MONKEY'], ['?x', 'BIRD']], result)
Exemplo n.º 2
0
    def test_select_single_not_query(self):
        bot = TestBot()
        self.load_data(bot.brain.rdf)

        select = RDFSelectStatement(["?x"], [
            RDFQuery(subject=TemplateWordNode("?x"),
                     predicate=TemplateWordNode("legs"),
                     object=TemplateWordNode("2"),
                     query_type=RDFQuery.NOT_QUERY)
        ])
        self.assertIsNotNone(select)

        result = select.execute(bot, "testid")
        self.assertIsNotNone(result)
        self.assertEquals([['?x', 'BEAR'], ['?x', 'BEAR']], result)
Exemplo n.º 3
0
    def test_select_multi_query(self):
        bot = TestBot()
        self.load_data(bot.brain.rdf)

        select = RDFSelectStatement(["?x"], [
            RDFQuery(subject=TemplateWordNode("?x"),
                     predicate=TemplateWordNode("legs"),
                     object=TemplateWordNode("2")),
            RDFQuery(subject=TemplateWordNode("?x"),
                     predicate=TemplateWordNode("feathers"),
                     object=TemplateWordNode("yes"))
        ])
        self.assertIsNotNone(select)

        result = select.execute(bot, "testid")
        self.assertIsNotNone(result)
        self.assertEquals([['?x', 'BIRD']], result)
Exemplo n.º 4
0
 def __init__(self, query=None):
     TemplateNode.__init__(self)
     if query is None:
         self._query = RDFSelectStatement()
     else:
         self._query = query