def test_query(self): query = RDFQuery(rdf_subject=TemplateWordNode("Subject"), rdf_predicate=TemplateWordNode("Predicate"), rdf_object=TemplateWordNode("Object")) self.assertIsNotNone(query) self.assertEquals(query.query_type, RDFQuery.QUERY) self.assertEquals( "<q><subj>Subject</subj><pred>Predicate</pred><obj>Object</obj></q>", query.to_xml(None, None)) self.assertEquals("query=( subj=Subject, pred=Predicate, obj=Object )", query.to_string(None, None))
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(rdf_subject=TemplateWordNode("ACCOUNT"), rdf_predicate=TemplateWordNode("?x"), rdf_object=TemplateWordNode("?y")) self.assertEquals("query=( subj=ACCOUNT, pred=?x, obj=?y )", query.to_string(None, None)) resultset = query.execute(bot, "testid") self.assertIsNotNone(resultset) self.assertEquals(5, len(resultset.results))