Ejemplo n.º 1
0
 def test_execute_multi_vars(self):
     bot = TestBot()
     bot.brain.rdf.load_from_text("""
         ACCOUNT:hasPurpose:to track money
         ACCOUNT:hasSize:0
         ACCOUNT:hasSyllables:2
         ACCOUNT:isa:Concept
         ACCOUNT:lifeArea:Finances
         ACT:hasPurpose:to entertain by performing
     """)
     query = RDFQuery(subject=TemplateWordNode("ACCOUNT"),
                      predicate=TemplateWordNode("?x"),
                      object=TemplateWordNode("?y"))
     resultset = query.execute(bot, "testid")
     self.assertIsNotNone(resultset)
     self.assertEquals(5, len(resultset.results))
Ejemplo n.º 2
0
    def test_execute_single_var(self):
        bot = TestBot()
        bot.brain.rdf.load_from_text("""
            ACCOUNT:hasPurpose:to track money
            ACCOUNT:hasSize:0
            ACCOUNT:hasSyllables:2
            ACCOUNT:isa:Concept
            ACCOUNT:lifeArea:Finances
            ACT:hasPurpose:to entertain by performing
        """)
        query = RDFQuery(rdf_subject=TemplateWordNode("ACCOUNT"),
                         rdf_predicate=TemplateWordNode("hasSize"),
                         rdf_object=TemplateWordNode("?x"))

        self.assertEquals("query=( subj=ACCOUNT, pred=hasSize, obj=?x )",
                          query.to_string(None, None))

        resultset = query.execute(bot, "testid")
        self.assertIsNotNone(resultset)
        result = resultset.results[0]
        self.assertIsNotNone(result)
        self.assertEquals(result[0][1], "ACCOUNT")
        self.assertEquals(result[1][1], "hasSize")
        self.assertEquals(result[2][1], "0")