class AnaphoraUnitTester(TestCase): def setUp(self): self.atomspace= AtomSpace() __init__(self.atomspace) data=["opencog/scm/config.scm", "opencog/scm/core_types.scm", "spacetime/spacetime_types.scm", "opencog/nlp/types/nlp_types.scm", "opencog/dynamics/attention/attention_types.scm", "opencog/embodiment/embodiment_types.scm", "opencog/reasoning/pln/pln_types.scm", "opencog/scm/apply.scm", "opencog/scm/file-utils.scm", "opencog/scm/persistence.scm", #"opencog/scm/repl-shell.scm", "opencog/scm/utilities.scm", "opencog/scm/av-tv.scm", "opencog/nlp/scm/type-definitions.scm", "opencog/nlp/scm/config.scm", "opencog/nlp/scm/file-utils.scm", "opencog/nlp/scm/nlp-utils.scm", "opencog/nlp/scm/disjunct-list.scm", "opencog/nlp/scm/processing-utils.scm", ] for item in data: status=load_scm(self.atomspace, item) self.hobbsAgent=HobbsAgent() def tearDown(self): del self.atomspace del self.hobbsAgent def getWord(self,name,type=types.WordInstanceNode): rv=self.atomspace.get_atoms_by_name(type,name) return rv[0] def compare(self,list_1,list_2): if len(list_1)==len(list_2): for i in range(len(list_1)): if list_1[i]!=list_2[i].name: return False return True else: return False @unittest.skip("Unit test disabled, see: https://github.com/opencog/opencog/issues/1280") def test_bfs(self): ''' Testing the bfs function ''' self.hobbsAgent.initilization(self.atomspace) self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/bfs.scm")) self.hobbsAgent.run(self.atomspace) self.assertTrue(self.compare(['a','b','c','d','e','f','g'],self.hobbsAgent.bfs(self.getWord('a')))) self.atomspace.clear() #@unittest.skip("debugging skipping") def test_getWords(self): ''' Testing the getWords function ''' self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/getWords.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.compare(['a','b','c','d','e','f','g','h','j'],self.hobbsAgent.getWords())) self.atomspace.clear() @unittest.skip("Unit test disabled, see: https://github.com/opencog/opencog/issues/1280") def test_propose(self): ''' Testing the propose function ''' def filter_1(): print("Testing filter #1...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#4.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#5.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#6.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() def filter_2(): print("Testing filter #2...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#2/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#2/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() def filter_3(): print("Testing filter #3...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#3/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),3)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#3/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),3)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#3/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),3)) self.atomspace.clear() def filter_4(): print("Testing filter #4...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#4/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),4)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#4/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),4)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#4/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),4)) self.atomspace.clear() def filter_5(): print("Testing filter #5...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#5/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),5)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#5/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),5)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#5/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),5)) self.atomspace.clear() def filter_6(): print("Testing filter #6...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#6/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),6)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#6/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),6)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#6/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),6)) self.atomspace.clear() def filter_7(): print("Testing filter #7...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#7/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),7)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#7/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),7)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#7/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),7)) self.atomspace.clear() def filter_8(): print("Testing filter #8...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#8/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),8)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#8/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),8)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#8/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),8)) self.atomspace.clear() def filter_9(): print("Testing filter #9...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#9/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),9)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#9/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),9)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#9/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),9)) self.atomspace.clear() def filter_10(): print("Testing filter #10...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#10/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),10)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#10/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),10)) self.atomspace.clear() def filter_11(): print("Testing filter #11...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#11/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),11)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#11/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),11)) self.atomspace.clear() def filter_12(): print("Testing filter #12...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#12/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent',types.ParseNode),12)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#12/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),12)) self.atomspace.clear() def filter_13(): print("Testing filter #13...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#13/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),13)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#13/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),13)) self.atomspace.clear() def filter_14(): print("Testing filter #14...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#14/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),14)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#14/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),14)) self.atomspace.clear() def filter_15(): print("Testing filter #15...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#15/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),15)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#15/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),15)) self.atomspace.clear() def filter_16(): print("Testing filter #16...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#16/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),16)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#16/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),16)) self.atomspace.clear() def filter_17(): print("Testing filter #17...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#17/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),17)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#17/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),17)) self.atomspace.clear() def filter_18(): print("Testing filter #18...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#18/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),18)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#18/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),18)) self.atomspace.clear() filter_1() filter_2() filter_3() filter_4() filter_5() filter_6() filter_7() filter_8() filter_9() filter_10() filter_11() filter_12() filter_13() filter_14() filter_15() filter_16() filter_17() filter_18() #@unittest.skip("debugging skipping") def test_pleonastic_if(self): self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#4.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#5.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() #@unittest.skip("debugging skipping") def test_conjunctions(self): self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/conjunction.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('waitresses'))) self.atomspace.clear()
class AnaphoraUnitTester(TestCase): def setUp(self): self.atomspace= AtomSpace() scheme_eval(self.atomspace, "(add-to-load-path \"/usr/local/share/opencog/scm\")") scheme_eval(self.atomspace, "(use-modules (opencog))") scheme_eval(self.atomspace, "(use-modules (opencog atom-types))") scheme_eval(self.atomspace, "(use-modules (opencog query))") data=["opencog/scm/config.scm", "opencog/scm/core_types.scm", "opencog/scm/apply.scm", "opencog/scm/file-utils.scm", "opencog/scm/utilities.scm", "opencog/scm/av-tv.scm", "opencog/nlp/scm/type-definitions.scm", "opencog/nlp/scm/config.scm", "opencog/nlp/scm/file-utils.scm", "opencog/nlp/scm/nlp-utils.scm", "opencog/nlp/scm/disjunct-list.scm", "opencog/nlp/scm/processing-utils.scm", ] for item in data: status=load_scm(self.atomspace, item) # print "load status=", status, " item=", item self.hobbsAgent=HobbsAgent() def tearDown(self): del self.atomspace del self.hobbsAgent def getWord(self,name,type=types.WordInstanceNode): rv=self.atomspace.get_atoms_by_name(type,name) return rv[0] def compare(self,list_1,list_2): if len(list_1)==len(list_2): for i in range(len(list_1)): if list_1[i]!=list_2[i].name: return False return True else: return False def test_bfs(self): ''' Testing the bfs function ''' self.hobbsAgent.initilization(self.atomspace) self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/bfs.scm")) self.hobbsAgent.run(self.atomspace) self.assertTrue(self.compare(['a','b','c','d','e','f','g'],self.hobbsAgent.bfs(self.getWord('a')))) self.atomspace.clear() #@unittest.skip("debugging skipping") def test_getWords(self): ''' Testing the getWords function ''' self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/getWords.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.compare(['a','b','c','d','e','f','g','h','j'],self.hobbsAgent.getWords())) self.atomspace.clear() def test_propose(self): ''' Testing the propose function ''' def filter_1(): print("Testing filter #1...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#4.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#5.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#6.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() def filter_2(): print("Testing filter #2...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#2/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#2/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() def filter_3(): print("Testing filter #3...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#3/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),3)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#3/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),3)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#3/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),3)) self.atomspace.clear() def filter_4(): print("Testing filter #4...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#4/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),4)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#4/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),4)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#4/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),4)) self.atomspace.clear() def filter_5(): print("Testing filter #5...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#5/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),5)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#5/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),5)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#5/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),5)) self.atomspace.clear() def filter_6(): print("Testing filter #6...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#6/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),6)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#6/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),6)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#6/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),6)) self.atomspace.clear() def filter_7(): print("Testing filter #7...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#7/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),7)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#7/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),7)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#7/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),7)) self.atomspace.clear() def filter_8(): print("Testing filter #8...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#8/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),8)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#8/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),8)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#8/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),8)) self.atomspace.clear() def filter_9(): print("Testing filter #9...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#9/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),9)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#9/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),9)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#9/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),9)) self.atomspace.clear() def filter_10(): print("Testing filter #10...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#10/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),10)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#10/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),10)) self.atomspace.clear() def filter_11(): print("Testing filter #11...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#11/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),11)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#11/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),11)) self.atomspace.clear() def filter_12(): print("Testing filter #12...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#12/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent',types.ParseNode),12)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#12/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),12)) self.atomspace.clear() def filter_13(): print("Testing filter #13...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#13/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),13)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#13/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),13)) self.atomspace.clear() def filter_14(): print("Testing filter #14...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#14/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),14)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#14/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),14)) self.atomspace.clear() def filter_15(): print("Testing filter #15...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#15/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),15)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#15/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),15)) self.atomspace.clear() def filter_16(): print("Testing filter #16...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#16/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),16)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#16/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),16)) self.atomspace.clear() def filter_17(): print("Testing filter #17...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#17/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),17)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#17/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),17)) self.atomspace.clear() def filter_18(): print("Testing filter #18...") self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#18/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),18)) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#18/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),18)) self.atomspace.clear() filter_1() filter_2() filter_3() filter_4() filter_5() filter_6() filter_7() filter_8() filter_9() filter_10() filter_11() filter_12() filter_13() filter_14() filter_15() filter_16() filter_17() filter_18() #@unittest.skip("debugging skipping") def test_pleonastic_if(self): self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#4.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#5.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() #@unittest.skip("debugging skipping") def test_conjunctions(self): self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/conjunction.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('waitresses'))) self.atomspace.clear()
class AtomSpaceTest(TestCase): def setUp(self): self.space = AtomSpace() def tearDown(self): del self.space def test_add_node(self): a1 = self.space.add_node(types.Node, "test") self.assertTrue(a1) # duplicates resolve to same handle a2 = self.space.add_node(types.Node, "test") self.assertEquals(a1, a2) # Should fail when intentionally adding bad type # self.assertRaises(RuntimeError, self.space.add_node(types.Link, "test")) caught = False try: self.space.add_node(types.Link, "test") except RuntimeError: caught = True self.assertEquals(caught, True) # test adding with a truthvalue a3 = self.space.add_node(types.Node, "test_w_tv", TruthValue(0.5, 100)) self.assertEquals(self.space.size(), 2) # test adding with prefixed node a1 = self.space.add_node(types.Node, "test", prefixed=True) a2 = self.space.add_node(types.Node, "test", prefixed=True) self.assertNotEqual(a1, a2) self.assertEquals(self.space.size(), 4) a3 = self.space.add_node(types.Node, "test", TruthValue(0.5, 100), prefixed=True) self.assertNotEqual(a1, a3) self.assertEquals(self.space.size(), 5) # tests with bad parameters # test with not a proper truthvalue self.assertRaises(TypeError, self.space.add_node, types.Node, "test", 0, True) # test with bad type self.assertRaises(TypeError, self.space.add_node, "ConceptNode", "test", TruthValue(0.5, 100)) def test_add_link(self): n1 = self.space.add_node(types.Node, "test1") n2 = self.space.add_node(types.Node, "test2") l1 = self.space.add_link(types.Link, [n1, n2]) self.assertTrue(l1 is not None) l2 = self.space.add_link(types.Link, [n1, n2]) self.assertTrue(l2 is not None) self.assertTrue(l2 == l1) n3 = self.space.add_node(types.Node, "test3") l3 = self.space.add_link(types.Link, [n1, n3], TruthValue(0.5, 100)) self.assertTrue(l3 is not None) # Test with a handle instead of atom l4 = self.space.add_link(types.Link, [n2.h, n3], TruthValue(0.5, 100)) self.assertTrue(l4 is not None) # Should fail when adding an intentionally bad type caught = False try: l1 = self.space.add_link(types.Node, [n1, n3]) except RuntimeError: caught = True self.assertEquals(caught, True) def test_is_valid(self): h1 = self.space.add_node(types.Node, "test1") # check with Handle object self.assertTrue(self.space.is_valid(h1.h)) # check with raw UUID self.assertTrue(self.space.is_valid(h1.h.value())) # check with bad UUID self.assertFalse(self.space.is_valid(2919)) # check with bad type self.assertRaises(TypeError, self.space.is_valid, "test") def test_truth_value(self): # check attributes come back as assigned tv = TruthValue(0.5, 100) self.assertEqual(tv.mean, 0.5) self.assertEqual(tv.count, 100) # test confidence self.assertAlmostEqual(tv.confidence, 0.1111, places=4) # test string representation self.assertEqual(str(tv), "(stv 0.500000 0.111111)") # check equality tv2 = TruthValue(0.5, 100) tv3 = TruthValue(0.6, 100) self.assertTrue(tv == tv2) self.assertFalse(tv == tv3) def test_get_by_name_and_type(self): n1 = self.space.add_node(types.Node, "test") n2 = self.space.add_node(types.ConceptNode, "test") n3 = self.space.add_node(types.PredicateNode, "test") # test recursive subtypes result = self.space.get_atoms_by_name(types.Node, "test") self.assertTrue(n1 in result) self.assertTrue(n2 in result) self.assertTrue(n3 in result) # test non-recursive subtype result = self.space.get_atoms_by_name(types.Node, "test", subtype=False) self.assertTrue(n1 in result) self.assertTrue(n2 not in result) self.assertTrue(n3 not in result) # test empty result = self.space.get_atoms_by_name(types.AnchorNode, "test", subtype=False) self.assertEqual(len(result), 0) def test_get_by_type(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") # test recursive subtypes result = self.space.get_atoms_by_type(types.Node) self.assertTrue(h1 in result) self.assertTrue(h2 in result) self.assertTrue(h3 in result) # links l1 = self.space.add_link(types.InheritanceLink, [h1, h2]) result = self.space.get_atoms_by_type(types.Link) self.assertTrue(l1 in result) # test non-recursive subtype result = self.space.get_atoms_by_type(types.Node, subtype=False) self.assertTrue(h1 in result) self.assertTrue(h2 not in result) self.assertTrue(h3 not in result) # test empty result = self.space.get_atoms_by_type(types.AnchorNode, subtype=False) self.assertEqual(len(result), 0) def test_get_by_av(self): h1 = self.space.add_node(types.ConceptNode, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_link(types.InheritanceLink, [h1, h2]) h4 = self.space.add_node(types.ConceptNode, "test4") h5 = self.space.add_node(types.ConceptNode, "test5") self.space.set_av(h=h1.h, sti=10) self.space.set_av(h=h2.h, sti=5) self.space.set_av(h=h3.h, sti=4) self.space.set_av(h=h4.h, sti=1) result = self.space.get_atoms_by_av(4, 10) assert len(result) == 3 assert set(result) == set([h1, h2, h3]) assert h4 not in result result = self.space.get_atoms_in_attentional_focus() assert len(result) == 4 assert set(result) == set([h1, h2, h3, h4]) def test_get_by_target_type(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") # test it doesn't apply to Nodes result = self.space.get_atoms_by_target_type(types.Node, types.Node) self.assertTrue(h1 not in result) # links l1 = self.space.add_link(types.InheritanceLink, [h1.h, h2.h]) result = self.space.get_atoms_by_target_type(types.Link, types.ConceptNode, target_subtype=False) self.assertTrue(l1 in result) # test recursive target subtype result = self.space.get_atoms_by_target_type(types.Link, types.Node, target_subtype=True) self.assertTrue(l1 in result) def test_get_by_target_atom(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") # test it doesn't apply to Nodes result = self.space.get_atoms_by_target_atom(types.Node, h1) self.assertTrue(h1 not in result) # links l1 = self.space.add_link(types.InheritanceLink, [h1, h2]) result = self.space.get_atoms_by_target_atom(types.Link, h1) self.assertTrue(l1 in result) result = self.space.get_atoms_by_target_atom(types.Link, h3) self.assertTrue(l1 not in result) def test_include_incoming_outgoing(self): frog = self.space.add_node(types.ConceptNode, "Frog") thing = self.space.add_node(types.ConceptNode, "Thing") animal = self.space.add_node(types.ConceptNode, "Animal") self.space.add_node(types.ConceptNode, "SeparateThing") self.space.add_link(types.InheritanceLink, [frog, animal]) self.space.add_link(types.InheritanceLink, [animal, thing]) assert len(self.space.include_incoming(self.space.get_atoms_by_name(types.ConceptNode, "Frog"))) == 2 assert len(self.space.include_incoming(self.space.get_atoms_by_type(types.ConceptNode))) == 6 assert len(self.space.include_outgoing(self.space.get_atoms_by_type(types.InheritanceLink))) == 5 assert len(self.space.include_outgoing( self.space.include_incoming(self.space.get_atoms_by_name(types.ConceptNode, "Frog")))) == 3 def test_remove(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") self.assertTrue(h1 in self.space) self.assertTrue(h2 in self.space) self.assertTrue(h3 in self.space) self.space.remove(h1) self.assertTrue(h1 not in self.space) self.assertTrue(h2 in self.space) self.assertTrue(h3 in self.space) l = self.space.add_link(types.SimilarityLink, [h2, h3]) self.space.remove(h2, True) # won't remove it unless recursive is True self.assertTrue(h2 not in self.space) self.assertTrue(l not in self.space) def test_clear(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") self.space.clear() self.assertEquals(self.space.size(), 0) self.assertEquals(self.space.size(), 0) self.assertEquals(len(self.space), 0) def test_container_methods(self): self.assertEquals(len(self.space), 0) h = Handle(100) self.assertRaises(KeyError, self.space.__getitem__, "blah") self.assertRaises(IndexError, self.space.__getitem__, h) a1 = self.space.add_node(types.Node, "test1") a2 = self.space.add_node(types.ConceptNode, "test2") a3 = self.space.add_node(types.PredicateNode, "test3") h1 = a1.h h2 = a2.h self.assertEquals(a1, self.space[h1]) self.assertTrue(h1 in self.space) self.assertTrue(a1 in self.space) self.assertTrue(h2 in self.space) self.assertTrue(len(self.space), 3)
class AnaphoraUnitTester(TestCase): def setUp(self): self.atomspace = AtomSpace() __init__(self.atomspace) data = [ "opencog/scm/config.scm", "opencog/atomspace/core_types.scm", "spacetime/spacetime_types.scm", "opencog/nlp/types/nlp_types.scm", "opencog/dynamics/attention/attention_types.scm", "opencog/embodiment/AtomSpaceExtensions/embodiment_types.scm", "opencog/learning/pln/pln_types.scm", "opencog/scm/apply.scm", "opencog/scm/file-utils.scm", "opencog/scm/persistence.scm", #"opencog/scm/repl-shell.scm", "opencog/scm/utilities.scm", "opencog/scm/av-tv.scm", "opencog/nlp/scm/type-definitions.scm", "opencog/nlp/scm/config.scm", "opencog/nlp/scm/file-utils.scm", "opencog/nlp/scm/nlp-utils.scm", "opencog/nlp/scm/disjunct-list.scm", "opencog/nlp/scm/processing-utils.scm", "opencog/nlp/scm/relex-to-logic.scm", ] for item in data: status = load_scm(self.atomspace, item) self.hobbsAgent = HobbsAgent() def tearDown(self): del self.atomspace del self.hobbsAgent def getWord(self, name, type=types.WordInstanceNode): rv = self.atomspace.get_atoms_by_name(type, name) return rv[0] def compare(self, list_1, list_2): if len(list_1) == len(list_2): for i in range(len(list_1)): if list_1[i] != list_2[i].name: return False return True else: return False #@unittest.skip("debugging skipping") def test_bfs(self): ''' Testing the bfs function ''' self.hobbsAgent.initilization(self.atomspace) self.assertTrue( load_scm(self.atomspace, "tests/python/test_anaphora/data/bfs.scm")) self.hobbsAgent.run(self.atomspace) self.assertTrue( self.compare(['a', 'b', 'c', 'd', 'e', 'f', 'g'], self.hobbsAgent.bfs(self.getWord('a')))) self.atomspace.clear() #@unittest.skip("debugging skipping") def test_getWords(self): ''' Testing the getWords function ''' self.assertTrue( load_scm(self.atomspace, "tests/python/test_anaphora/data/getWords.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.compare(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j'], self.hobbsAgent.getWords())) self.atomspace.clear() #@unittest.skip("debugging skipping") def test_propose(self): ''' Testing the propose function ''' def filter_1(): print("Testing filter #1...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#1/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose( self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#1/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#1/data_#3.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose( self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#1/data_#4.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose( self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#1/data_#5.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose( self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#1/data_#6.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose( self.getWord('antecedent'))) self.atomspace.clear() def filter_2(): print("Testing filter #2...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#2/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#2/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.propose( self.getWord('antecedent'))) self.atomspace.clear() def filter_3(): print("Testing filter #3...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#3/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 3)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#3/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 3)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#3/data_#3.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 3)) self.atomspace.clear() def filter_4(): print("Testing filter #4...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#4/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 4)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#4/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 4)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#4/data_#3.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 4)) self.atomspace.clear() def filter_5(): print("Testing filter #5...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#5/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 5)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#5/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 5)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#5/data_#3.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 5)) self.atomspace.clear() def filter_6(): print("Testing filter #6...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#6/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 6)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#6/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 6)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#6/data_#3.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 6)) self.atomspace.clear() def filter_7(): print("Testing filter #7...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#7/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 7)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#7/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 7)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#7/data_#3.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 7)) self.atomspace.clear() def filter_8(): print("Testing filter #8...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#8/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 8)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#8/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 8)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#8/data_#3.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 8)) self.atomspace.clear() def filter_9(): print("Testing filter #9...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#9/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 9)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#9/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 9)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#9/data_#3.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 9)) self.atomspace.clear() def filter_10(): print("Testing filter #10...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#10/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 10)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#10/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 10)) self.atomspace.clear() def filter_11(): print("Testing filter #11...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#11/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 11)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#11/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 11)) self.atomspace.clear() def filter_12(): print("Testing filter #12...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#12/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose( self.getWord('antecedent', types.ParseNode), 12)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#12/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 12)) self.atomspace.clear() def filter_13(): print("Testing filter #13...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#13/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 13)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#13/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 13)) self.atomspace.clear() def filter_14(): print("Testing filter #14...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#14/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 14)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#14/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 14)) self.atomspace.clear() def filter_15(): print("Testing filter #15...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#15/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 15)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#15/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 15)) self.atomspace.clear() def filter_16(): print("Testing filter #16...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#16/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 16)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#16/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 16)) self.atomspace.clear() def filter_17(): print("Testing filter #17...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#17/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 17)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#17/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 17)) self.atomspace.clear() def filter_18(): print("Testing filter #18...") self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#18/data_#1.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.propose(self.getWord('antecedent'), 18)) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/propose/filter-#18/data_#2.scm" )) self.hobbsAgent.initilization(self.atomspace) self.assertTrue( self.hobbsAgent.propose(self.getWord('antecedent'), 18)) self.atomspace.clear() filter_1() filter_2() filter_3() filter_4() filter_5() filter_6() filter_7() filter_8() filter_9() filter_10() filter_11() filter_12() filter_13() filter_14() filter_15() filter_16() filter_17() filter_18() #@unittest.skip("debugging skipping") def test_pleonastic_if(self): self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/pleonastic_it/data_#1.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/pleonastic_it/data_#2.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/pleonastic_it/data_#3.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/pleonastic_it/data_#4.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() self.assertTrue( load_scm( self.atomspace, "tests/python/test_anaphora/data/pleonastic_it/data_#5.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it'))) self.atomspace.clear() #@unittest.skip("debugging skipping") def test_conjunctions(self): self.assertTrue( load_scm(self.atomspace, "tests/python/test_anaphora/data/conjunction.scm")) self.hobbsAgent.initilization(self.atomspace) self.assertFalse( self.hobbsAgent.pleonastic_it(self.getWord('waitresses'))) self.atomspace.clear()
class AtomSpaceTest(TestCase): def setUp(self): self.space = AtomSpace() def tearDown(self): del self.space def test_add_node(self): a1 = self.space.add_node(types.Node, "test") self.assertTrue(a1) # duplicates resolve to same handle a2 = self.space.add_node(types.Node, "test") self.assertEquals(a1, a2) # Should fail when intentionally adding bad type # self.assertRaises(RuntimeError, self.space.add_node(types.Link, "test")) caught = False try: self.space.add_node(types.Link, "test") except RuntimeError: caught = True self.assertEquals(caught, True) # test adding with a truthvalue a3 = self.space.add_node(types.Node, "test_w_tv", TruthValue(0.5, 100)) self.assertEquals(self.space.size(), 2) ### FIXME TODO -- re-enable this test after the prefixing code is ### ### # test adding with prefixed node ### a1 = self.space.add_node(types.Node, "test", prefixed=True) ### a2 = self.space.add_node(types.Node, "test", prefixed=True) ### self.assertNotEqual(a1, a2) ### self.assertEquals(self.space.size(), 4) ### ### a3 = self.space.add_node(types.Node, "test", TruthValue(0.5, 100), prefixed=True) ### self.assertNotEqual(a1, a3) ### self.assertEquals(self.space.size(), 5) # tests with bad parameters # test with not a proper truthvalue self.assertRaises(TypeError, self.space.add_node, types.Node, "test", 0, True) # test with bad type self.assertRaises(TypeError, self.space.add_node, "ConceptNode", "test", TruthValue(0.5, 100)) def test_add_link(self): n1 = self.space.add_node(types.Node, "test1") n2 = self.space.add_node(types.Node, "test2") l1 = self.space.add_link(types.Link, [n1, n2]) self.assertTrue(l1 is not None) l2 = self.space.add_link(types.Link, [n1, n2]) self.assertTrue(l2 is not None) self.assertTrue(l2 == l1) n3 = self.space.add_node(types.Node, "test3") l3 = self.space.add_link(types.Link, [n1, n3], TruthValue(0.5, 100)) self.assertTrue(l3 is not None) # Test with a handle instead of atom l4 = self.space.add_link(types.Link, [n2.h, n3], TruthValue(0.5, 100)) self.assertTrue(l4 is not None) # Should fail when adding an intentionally bad type caught = False try: l1 = self.space.add_link(types.Node, [n1, n3]) except RuntimeError: caught = True self.assertEquals(caught, True) def test_is_valid(self): h1 = self.space.add_node(types.Node, "test1") # check with Handle object self.assertTrue(self.space.is_valid(h1.h)) # check with raw UUID self.assertTrue(self.space.is_valid(h1.h.value())) # check with bad UUID self.assertFalse(self.space.is_valid(2919)) # check with bad type self.assertRaises(TypeError, self.space.is_valid, "test") def test_truth_value(self): # check attributes come back as assigned tv = TruthValue(0.5, 100) self.assertEqual(tv.mean, 0.5) self.assertEqual(tv.count, 100) # test confidence self.assertAlmostEqual(tv.confidence, 0.1111, places=4) # test string representation self.assertEqual(str(tv), "(stv 0.500000 0.111111)") # check equality tv2 = TruthValue(0.5, 100) tv3 = TruthValue(0.6, 100) self.assertTrue(tv == tv2) self.assertFalse(tv == tv3) def test_get_by_name_and_type(self): n1 = self.space.add_node(types.Node, "test") n2 = self.space.add_node(types.ConceptNode, "test") n3 = self.space.add_node(types.PredicateNode, "test") # test recursive subtypes result = self.space.get_atoms_by_name(types.Node, "test") self.assertTrue(n1 in result) self.assertTrue(n2 in result) self.assertTrue(n3 in result) # test non-recursive subtype result = self.space.get_atoms_by_name(types.Node, "test", subtype=False) self.assertTrue(n1 in result) self.assertTrue(n2 not in result) self.assertTrue(n3 not in result) # test empty result = self.space.get_atoms_by_name(types.AnchorNode, "test", subtype=False) self.assertEqual(len(result), 0) def test_get_by_type(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") # test recursive subtypes result = self.space.get_atoms_by_type(types.Node) self.assertTrue(h1 in result) self.assertTrue(h2 in result) self.assertTrue(h3 in result) # links l1 = self.space.add_link(types.InheritanceLink, [h1, h2]) result = self.space.get_atoms_by_type(types.Link) self.assertTrue(l1 in result) # test non-recursive subtype result = self.space.get_atoms_by_type(types.Node, subtype=False) self.assertTrue(h1 in result) self.assertTrue(h2 not in result) self.assertTrue(h3 not in result) # test empty result = self.space.get_atoms_by_type(types.AnchorNode, subtype=False) self.assertEqual(len(result), 0) def test_get_by_av(self): h1 = self.space.add_node(types.ConceptNode, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_link(types.InheritanceLink, [h1, h2]) h4 = self.space.add_node(types.ConceptNode, "test4") h5 = self.space.add_node(types.ConceptNode, "test5") self.space.set_av(h=h1.h, sti=10) self.space.set_av(h=h2.h, sti=5) self.space.set_av(h=h3.h, sti=4) self.space.set_av(h=h4.h, sti=1) result = self.space.get_atoms_by_av(4, 10) assert len(result) == 3 assert set(result) == set([h1, h2, h3]) assert h4 not in result result = self.space.get_atoms_in_attentional_focus() assert len(result) == 4 assert set(result) == set([h1, h2, h3, h4]) def test_get_by_target_atom(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") # test it doesn't apply to Nodes result = self.space.get_atoms_by_target_atom(types.Node, h1) self.assertTrue(h1 not in result) # links l1 = self.space.add_link(types.InheritanceLink, [h1, h2]) result = self.space.get_atoms_by_target_atom(types.Link, h1) self.assertTrue(l1 in result) result = self.space.get_atoms_by_target_atom(types.Link, h3) self.assertTrue(l1 not in result) def test_include_incoming_outgoing(self): frog = self.space.add_node(types.ConceptNode, "Frog") thing = self.space.add_node(types.ConceptNode, "Thing") animal = self.space.add_node(types.ConceptNode, "Animal") self.space.add_node(types.ConceptNode, "SeparateThing") self.space.add_link(types.InheritanceLink, [frog, animal]) self.space.add_link(types.InheritanceLink, [animal, thing]) assert len( self.space.include_incoming( self.space.get_atoms_by_name(types.ConceptNode, "Frog"))) == 2 assert len( self.space.include_incoming( self.space.get_atoms_by_type(types.ConceptNode))) == 6 assert len( self.space.include_outgoing( self.space.get_atoms_by_type(types.InheritanceLink))) == 5 assert len( self.space.include_outgoing( self.space.include_incoming( self.space.get_atoms_by_name(types.ConceptNode, "Frog")))) == 3 def test_remove(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") self.assertTrue(h1 in self.space) self.assertTrue(h2 in self.space) self.assertTrue(h3 in self.space) self.space.remove(h1) self.assertTrue(h1 not in self.space) self.assertTrue(h2 in self.space) self.assertTrue(h3 in self.space) l = self.space.add_link(types.SimilarityLink, [h2, h3]) self.space.remove(h2, True) # won't remove it unless recursive is True self.assertTrue(h2 not in self.space) self.assertTrue(l not in self.space) def test_clear(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") self.space.clear() self.assertEquals(self.space.size(), 0) self.assertEquals(self.space.size(), 0) self.assertEquals(len(self.space), 0) def test_container_methods(self): self.assertEquals(len(self.space), 0) h = Handle(100) self.assertRaises(KeyError, self.space.__getitem__, "blah") self.assertRaises(IndexError, self.space.__getitem__, h) a1 = self.space.add_node(types.Node, "test1") a2 = self.space.add_node(types.ConceptNode, "test2") a3 = self.space.add_node(types.PredicateNode, "test3") h1 = a1.h h2 = a2.h self.assertEquals(a1, self.space[h1]) self.assertTrue(h1 in self.space) self.assertTrue(a1 in self.space) self.assertTrue(h2 in self.space) self.assertEquals(len(self.space), 3) def test_get_predicates(self): dog = self.space.add_node(types.ConceptNode, "dog") mammal = self.space.add_node(types.ConceptNode, "mammal") canine = self.space.add_node(types.ConceptNode, "canine") animal = self.space.add_node(types.ConceptNode, "animal") dog_mammal = self.space.add_link(types.ListLink, [dog, mammal]) dog_canine = self.space.add_link(types.ListLink, [dog, canine]) dog_animal = self.space.add_link(types.ListLink, [dog, animal]) isA = self.space.add_node(types.PredicateNode, "IsA") dogIsAMammal = self.space.add_link(types.EvaluationLink, [isA, dog_mammal]) dogIsACanine = self.space.add_link(types.EvaluationLink, [isA, dog_canine]) dogIsAAnimal = self.space.add_link(types.EvaluationLink, [isA, dog_animal]) dog_predicates = self.space.get_predicates(dog) self.assertEquals(len(dog_predicates), 3) count = 0 for dogIs in self.space.xget_predicates(dog): count += 1 self.assertEquals(count, 3) def test_get_predicates_for(self): dog = self.space.add_node(types.ConceptNode, "dog") mammal = self.space.add_node(types.ConceptNode, "mammal") canine = self.space.add_node(types.ConceptNode, "canine") animal = self.space.add_node(types.ConceptNode, "animal") dog_mammal = self.space.add_link(types.ListLink, [dog, mammal]) dog_canine = self.space.add_link(types.ListLink, [dog, canine]) dog_animal = self.space.add_link(types.ListLink, [dog, animal]) isA = self.space.add_node(types.PredicateNode, "IsA") dogIsAMammal = self.space.add_link(types.EvaluationLink, [isA, dog_mammal]) dogIsACanine = self.space.add_link(types.EvaluationLink, [isA, dog_canine]) dogIsAAnimal = self.space.add_link(types.EvaluationLink, [isA, dog_animal]) human = self.space.add_node(types.ConceptNode, "human") dog_human = self.space.add_link(types.ListLink, [dog, human]) loves = self.space.add_node(types.PredicateNode, "loves") dogLovesHumans = self.space.add_link(types.EvaluationLink, [loves, dog_human]) dog_predicates = self.space.get_predicates_for(dog, isA) self.assertEquals(len(dog_predicates), 3) dog_predicates = self.space.get_predicates_for(dog, loves) self.assertEquals(len(dog_predicates), 1) count = 0 for dogIsA in self.space.xget_predicates_for(dog, isA): count += 1 self.assertEquals(count, 3) count = 0 for dogLoves in self.space.xget_predicates_for(dog, loves): count += 1 self.assertEquals(count, 1)
class AtomSpaceTest(TestCase): def setUp(self): self.space = AtomSpace() def tearDown(self): del self.space def test_add_node(self): a1 = self.space.add_node(types.Node, "test") self.assertTrue(a1) # duplicates resolve to same handle a2 = self.space.add_node(types.Node, "test") self.assertEquals(a1, a2) # Should fail when intentionally adding bad type # self.assertRaises(RuntimeError, self.space.add_node(types.Link, "test")) caught = False try: self.space.add_node(types.Link, "test") except RuntimeError: caught = True self.assertEquals(caught, True) # test adding with a truthvalue a3 = self.space.add_node(types.Node, "test_w_tv", TruthValue(0.5, 100)) self.assertEquals(self.space.size(), 2) # test adding with prefixed node a1 = self.space.add_node(types.Node, "test", prefixed=True) a2 = self.space.add_node(types.Node, "test", prefixed=True) self.assertNotEqual(a1, a2) self.assertEquals(self.space.size(), 4) a3 = self.space.add_node(types.Node, "test", TruthValue(0.5, 100), prefixed=True) self.assertNotEqual(a1, a3) self.assertEquals(self.space.size(), 5) # tests with bad parameters # test with not a proper truthvalue self.assertRaises(TypeError, self.space.add_node, types.Node, "test", 0, True) # test with bad type self.assertRaises(TypeError, self.space.add_node, "ConceptNode", "test", TruthValue(0.5, 100)) def test_add_link(self): n1 = self.space.add_node(types.Node, "test1") n2 = self.space.add_node(types.Node, "test2") l1 = self.space.add_link(types.Link, [n1, n2]) self.assertTrue(l1 is not None) l2 = self.space.add_link(types.Link, [n1, n2]) self.assertTrue(l2 is not None) self.assertTrue(l2 == l1) n3 = self.space.add_node(types.Node, "test3") l3 = self.space.add_link(types.Link, [n1, n3], TruthValue(0.5, 100)) self.assertTrue(l3 is not None) # Test with a handle instead of atom l4 = self.space.add_link(types.Link, [n2.h, n3], TruthValue(0.5, 100)) self.assertTrue(l4 is not None) # Should fail when adding an intentionally bad type caught = False try: l1 = self.space.add_link(types.Node, [n1, n3]) except RuntimeError: caught = True self.assertEquals(caught, True) def test_is_valid(self): h1 = self.space.add_node(types.Node, "test1") # check with Handle object self.assertTrue(self.space.is_valid(h1.h)) # check with raw UUID self.assertTrue(self.space.is_valid(h1.h.value())) # check with bad UUID self.assertFalse(self.space.is_valid(2919)) # check with bad type self.assertRaises(TypeError, self.space.is_valid, "test") def test_truth_value(self): # check attributes come back as assigned tv = TruthValue(0.5, 100) self.assertEqual(tv.mean, 0.5) self.assertEqual(tv.count, 100) # test confidence self.assertAlmostEqual(tv.confidence, 0.1111, places=4) # test string representation self.assertEqual(str(tv), "(stv 0.500000 0.111111)") # check equality tv2 = TruthValue(0.5, 100) tv3 = TruthValue(0.6, 100) self.assertTrue(tv == tv2) self.assertFalse(tv == tv3) def test_get_by_name_and_type(self): n1 = self.space.add_node(types.Node, "test") n2 = self.space.add_node(types.ConceptNode, "test") n3 = self.space.add_node(types.PredicateNode, "test") # test recursive subtypes result = self.space.get_atoms_by_name(types.Node, "test") self.assertTrue(n1 in result) self.assertTrue(n2 in result) self.assertTrue(n3 in result) # test non-recursive subtype result = self.space.get_atoms_by_name(types.Node, "test", subtype=False) self.assertTrue(n1 in result) self.assertTrue(n2 not in result) self.assertTrue(n3 not in result) # test empty result = self.space.get_atoms_by_name(types.AnchorNode, "test", subtype=False) self.assertEqual(len(result), 0) def test_get_by_type(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") # test recursive subtypes result = self.space.get_atoms_by_type(types.Node) self.assertTrue(h1 in result) self.assertTrue(h2 in result) self.assertTrue(h3 in result) # links l1 = self.space.add_link(types.InheritanceLink, [h1, h2]) result = self.space.get_atoms_by_type(types.Link) self.assertTrue(l1 in result) # test non-recursive subtype result = self.space.get_atoms_by_type(types.Node, subtype=False) self.assertTrue(h1 in result) self.assertTrue(h2 not in result) self.assertTrue(h3 not in result) # test empty result = self.space.get_atoms_by_type(types.AnchorNode, subtype=False) self.assertEqual(len(result), 0) def test_get_by_target_type(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") # test it doesn't apply to Nodes result = self.space.get_atoms_by_target_type(types.Node, types.Node) self.assertTrue(h1 not in result) # links l1 = self.space.add_link(types.InheritanceLink, [h1.h, h2.h]) result = self.space.get_atoms_by_target_type(types.Link, types.ConceptNode, target_subtype=False) self.assertTrue(l1 in result) # test recursive target subtype result = self.space.get_atoms_by_target_type(types.Link, types.Node, target_subtype=True) self.assertTrue(l1 in result) def test_get_by_target_atom(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") # test it doesn't apply to Nodes result = self.space.get_atoms_by_target_atom(types.Node, h1) self.assertTrue(h1 not in result) # links l1 = self.space.add_link(types.InheritanceLink, [h1, h2]) result = self.space.get_atoms_by_target_atom(types.Link, h1) self.assertTrue(l1 in result) result = self.space.get_atoms_by_target_atom(types.Link, h3) self.assertTrue(l1 not in result) def test_remove(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") self.assertTrue(h1 in self.space) self.assertTrue(h2 in self.space) self.assertTrue(h3 in self.space) self.space.remove(h1) self.assertTrue(h1 not in self.space) self.assertTrue(h2 in self.space) self.assertTrue(h3 in self.space) l = self.space.add_link(types.SimilarityLink, [h2, h3]) self.space.remove(h2, False) # won't remove it unless recursive is True self.assertTrue(h2 in self.space) self.space.remove(h2, True) # won't remove it unless recursive is True self.assertTrue(h2 not in self.space) self.assertTrue(l not in self.space) def test_clear(self): h1 = self.space.add_node(types.Node, "test1") h2 = self.space.add_node(types.ConceptNode, "test2") h3 = self.space.add_node(types.PredicateNode, "test3") self.space.clear() self.assertEquals(self.space.size(), 0) self.assertEquals(self.space.size(), 0) self.assertEquals(len(self.space), 0) def test_container_methods(self): self.assertEquals(len(self.space), 0) h = Handle(100) self.assertRaises(KeyError, self.space.__getitem__, "blah") self.assertRaises(IndexError, self.space.__getitem__, h) a1 = self.space.add_node(types.Node, "test1") a2 = self.space.add_node(types.ConceptNode, "test2") a3 = self.space.add_node(types.PredicateNode, "test3") h1 = a1.h h2 = a2.h self.assertEquals(a1, self.space[h1]) self.assertTrue(h1 in self.space) self.assertTrue(a1 in self.space) self.assertTrue(h2 in self.space) self.assertTrue(len(self.space), 3)
class AtomSpaceTest(TestCase): def setUp(self): self.space = AtomSpace() def tearDown(self): del self.space def test_add_node(self): a1 = self.space.add_node(types.Node,"test") self.assertTrue(a1) # duplicates resolve to same handle a2 = self.space.add_node(types.Node,"test") self.assertEquals(a1,a2) # fails when adding with a link type a1 = self.space.add_node(types.Link,"test") self.assertEquals(a1,None) # test adding with a truthvalue a3 = self.space.add_node(types.Node,"test_w_tv",TruthValue(0.5,100)) self.assertEquals(self.space.size(),2) # test adding with prefixed node a1 = self.space.add_node(types.Node,"test",prefixed=True) a2 = self.space.add_node(types.Node,"test",prefixed=True) self.assertNotEqual(a1,a2) self.assertEquals(self.space.size(),4) a3 = self.space.add_node(types.Node,"test",TruthValue(0.5,100),prefixed=True) self.assertNotEqual(a1,a3) self.assertEquals(self.space.size(),5) # tests with bad parameters # test with not a proper truthvalue self.assertRaises(TypeError,self.space.add_node,types.Node,"test",0,True) # test with bad type self.assertRaises(TypeError,self.space.add_node,"ConceptNode","test",TruthValue(0.5,100)) def test_add_link(self): n1 = self.space.add_node(types.Node,"test1") n2 = self.space.add_node(types.Node,"test2") l1 = self.space.add_link(types.Link,[n1,n2]) self.assertTrue(l1 is not None) l2 = self.space.add_link(types.Link,[n1,n2]) self.assertTrue(l2 is not None) self.assertTrue(l2 == l1) n3 = self.space.add_node(types.Node,"test3") l3 = self.space.add_link(types.Link,[n1,n3],TruthValue(0.5,100)) self.assertTrue(l3 is not None) # test with a handle instead of atom l4 = self.space.add_link(types.Link,[n2.h,n3],TruthValue(0.5,100)) self.assertTrue(l4 is not None) # fails when adding with a node type l1 = self.space.add_link(1,[n1,n3]) self.assertEquals(l1,None) def test_is_valid(self): h1 = self.space.add_node(types.Node,"test1") # check with Handle object self.assertTrue(self.space.is_valid(h1.h)) # check with raw UUID self.assertTrue(self.space.is_valid(h1.h.value())) # check with bad UUID self.assertFalse(self.space.is_valid(2919)) # check with bad type self.assertRaises(TypeError,self.space.is_valid,"test") def test_truth_value(self): # check attributes come back as assigned tv = TruthValue(0.5, 100) self.assertEqual(tv.mean,0.5) self.assertEqual(tv.count,100) # test confidence self.assertAlmostEqual(tv.confidence,0.1111,places=4) # test string representation self.assertEqual(str(tv),"[0.500000,100.000000=0.111111]") # check equality tv2 = TruthValue(0.5, 100) tv3 = TruthValue(0.6, 100) self.assertTrue(tv == tv2) self.assertFalse(tv == tv3) def test_get_by_name_and_type(self): n1 = self.space.add_node(types.Node,"test") n2 = self.space.add_node(types.ConceptNode,"test") n3 = self.space.add_node(types.PredicateNode,"test") # test recursive subtypes result = self.space.get_atoms_by_name(types.Node,"test") self.assertTrue(n1 in result) self.assertTrue(n2 in result) self.assertTrue(n3 in result) # test non-recursive subtype result = self.space.get_atoms_by_name(types.Node,"test",subtype=False) self.assertTrue(n1 in result) self.assertTrue(n2 not in result) self.assertTrue(n3 not in result) # test empty result = self.space.get_atoms_by_name(types.SemeNode,"test",subtype=False) self.assertEqual(len(result),0) def test_get_by_type(self): h1 = self.space.add_node(types.Node,"test1") h2 = self.space.add_node(types.ConceptNode,"test2") h3 = self.space.add_node(types.PredicateNode,"test3") # test recursive subtypes result = self.space.get_atoms_by_type(types.Node) self.assertTrue(h1 in result) self.assertTrue(h2 in result) self.assertTrue(h3 in result) # links l1 = self.space.add_link(types.InheritanceLink,[h1,h2]) result = self.space.get_atoms_by_type(types.Link) self.assertTrue(l1 in result) # test non-recursive subtype result = self.space.get_atoms_by_type(types.Node,subtype=False) self.assertTrue(h1 in result) self.assertTrue(h2 not in result) self.assertTrue(h3 not in result) # test empty result = self.space.get_atoms_by_type(types.SemeNode,subtype=False) self.assertEqual(len(result),0) def test_get_by_target_type(self): h1 = self.space.add_node(types.Node,"test1") h2 = self.space.add_node(types.ConceptNode,"test2") h3 = self.space.add_node(types.PredicateNode,"test3") # test it doesn't apply to Nodes result = self.space.get_atoms_by_target_type(types.Node,types.Node) self.assertTrue(h1 not in result) # links l1 = self.space.add_link(types.InheritanceLink,[h1.h,h2.h]) result = self.space.get_atoms_by_target_type(types.Link,types.ConceptNode,target_subtype=False) self.assertTrue(l1 in result) # test recursive target subtype result = self.space.get_atoms_by_target_type(types.Link,types.Node,target_subtype=True) self.assertTrue(l1 in result) def test_get_by_target_atom(self): h1 = self.space.add_node(types.Node,"test1") h2 = self.space.add_node(types.ConceptNode,"test2") h3 = self.space.add_node(types.PredicateNode,"test3") # test it doesn't apply to Nodes result = self.space.get_atoms_by_target_atom(types.Node,h1) self.assertTrue(h1 not in result) # links l1 = self.space.add_link(types.InheritanceLink,[h1,h2]) result = self.space.get_atoms_by_target_atom(types.Link,h1) self.assertTrue(l1 in result) result = self.space.get_atoms_by_target_atom(types.Link,h3) self.assertTrue(l1 not in result) def test_remove(self): h1 = self.space.add_node(types.Node,"test1") h2 = self.space.add_node(types.ConceptNode,"test2") h3 = self.space.add_node(types.PredicateNode,"test3") self.assertTrue(h1 in self.space) self.assertTrue(h2 in self.space) self.assertTrue(h3 in self.space) self.space.remove(h1) self.assertTrue(h1 not in self.space) self.assertTrue(h2 in self.space) self.assertTrue(h3 in self.space) l = self.space.add_link(types.SimilarityLink,[h2,h3]) self.space.remove(h2) # won't remove it unless recursive is True self.assertTrue(h2 in self.space) self.space.remove(h2,True) # won't remove it unless recursive is True self.assertTrue(h2 not in self.space) self.assertTrue(l not in self.space) def test_clear(self): h1 = self.space.add_node(types.Node,"test1") h2 = self.space.add_node(types.ConceptNode,"test2") h3 = self.space.add_node(types.PredicateNode,"test3") self.space.clear() self.assertEquals(self.space.size(),0) self.assertEquals(self.space.size(),0) self.assertEquals(len(self.space),0) def test_container_methods(self): self.assertEquals(len(self.space),0) h = Handle(100) self.assertRaises(KeyError,self.space.__getitem__,"blah") self.assertRaises(IndexError,self.space.__getitem__,h) a1 = self.space.add_node(types.Node,"test1") a2 = self.space.add_node(types.ConceptNode,"test2") a3 = self.space.add_node(types.PredicateNode,"test3") h1 = a1.h h2 = a2.h self.assertEquals(a1,self.space[h1]) self.assertTrue(h1 in self.space) self.assertTrue(a1 in self.space) self.assertTrue(h2 in self.space) self.assertTrue(len(self.space), 3)