def setUp(self): self.KB = KnowledgeBase() self.axioms = [ ClassAssertion(And(Concept("Man"), Concept("Human")), Instance("Aditya")), ClassAssertion(Some("owns", Concept("Conputer")), Instance("Aditya")) ]
def test_nnf_or(self): axiom1 = Or(Concept("A"), Concept("B")) axiom2 = Or(Concept("A"), Not(Concept("B"))) axiom3 = Or(Not(Not(Concept("A"))), Not(Not(Concept("B")))) self.assertEqual(axiom1, NNF(axiom1)) self.assertEqual(axiom1, NNF(axiom3)) self.assertNotEqual(axiom1, NNF(axiom2))
def setUp(self): self.KB = NodeSet() self.axioms = [ And(Concept("Man"), All("hasChild", Concept("Human"))), And(Concept("Woman"), All("hasChild", Concept("Human"))), Concept("Human"), Not(Concept("Robot")) ] self.KB.add_axioms(self.axioms)
def test_contains_axiom(self): self.assertTrue(self.KB.contains(Concept("Human")))
def test_all_equality(self): self.assertEqual(All("play", Concept("Child")), All("play", Concept("Man")))
def test_all_constructor(self): all_role = All("hasParent", Concept("Man")) self.assertEqual(all_role.name, "hasParent") self.assertEqual(all_role.concept.name, "Man")
def test_concept_inequality(self): self.assertFalse(Concept("Man") == Concept("Woman"))
def test_nnf_complex_statement(self): axiom1 = Not(And(Some("A", Concept("B")), Not(Concept("C")))) axiom2 = Or(All("A", Not(Concept("B"))), Concept("C")) self.assertEqual(axiom2, NNF(axiom1))
def test_nnf_subsumption(self): axiom1 = Concept("Man") axiom2 = Concept("Human") axiom = Subsumption(axiom1, axiom2) self.assertEqual(NNF(axiom), Or(Not(Concept("Man")), Concept("Human")))
def test_nnf_all(self): axiom1 = All("A", Concept("B")) self.assertEqual(NNF(axiom1), axiom1)
def test_nnf_not_all(self): axiom1 = Not(All("A", Concept("B"))) axiom2 = Some("A", Not(Concept("B"))) self.assertEqual(NNF(axiom1), axiom2)
def test_nnf_some(self): axiom1 = Some("A", Concept("B")) self.assertEqual(axiom1, NNF(axiom1))
def test_nnf_not_and(self): axiom1 = Not(And(Concept("A"), Concept("B"))) axiom2 = Or(Not(Concept("A")), Not(Concept("B"))) self.assertEqual(axiom2, NNF(axiom1))
def test_nnf_and(self): axiom1 = And(Concept("A"), Concept("B")) axiom2 = And(Not(Not(Concept("A"))), Not(Not(Concept("B")))) self.assertEqual(axiom1, NNF(axiom2))
def test_concept_constructor(self): self.assertEqual(Concept("Man").name, "Man")
def setUp(self): _axiom=Some("hasParent",And(Concept("Man"),Concept("Human"))) self.pre_graph=get_models({},_axiom,"Aditya")[0]
def test_some_role_constructor(self): some_role = Some("hasParent", Concept("Man")) self.assertEqual(some_role.name, "hasParent") self.assertEqual(some_role.concept.name, "Man")
def test_simple_and(self): axiom=And(And(Concept("Man"),Concept("Living")),And(Concept("Machine"),Concept("Terminator"))) models=get_models({},axiom,"Aditya") self.assertTrue(is_model_consistent(models))
def test_concept_equality(self): self.assertTrue(Concept("Man") == Concept("Man"))
def test_unsat_and(self): axiom=And(And(Concept("Man"),Concept("Living")),And(Not(Concept("Man")),Concept("Terminator"))) models=get_models({},axiom,"Aditya") self.assertFalse(is_model_consistent(models))
def test_some_equality(self): self.assertEqual(Some("hasParent", Concept("Man")), Some("hasParent", Concept("Woman")))
def test_simple_or(self): axiom=Or(Concept("Man"),Concept("Terminator")) models=get_models({},axiom,"Aditya") self.assertTrue(is_model_consistent(models))
import sys sys.path.append("/home/adityas/Projects/ALC-reasoner/") from reasoner.knowledgebase.axioms import And, Or, Not, ClassAssertion, ABoxAxiom, RoleAssertion, TBoxAxiom, Subsumption from reasoner.common.constructors import Concept, All, Some, Instance little_kb = [ ABoxAxiom(ClassAssertion(Concept("Man"), Instance("Aditya"))), TBoxAxiom(Subsumption(Concept("Man"), Concept("Biological"))) ] small_kb = [ ABoxAxiom(ClassAssertion(Concept("Man"), Instance("Aditya"))), ABoxAxiom(ClassAssertion(Concept("Machine"), Instance("Icarus"))), TBoxAxiom(Subsumption(Concept("Man"), Concept("Biological"))) ] simple_kb = [ ABoxAxiom(ClassAssertion(Concept("Man"), Instance("Aditya"))), ABoxAxiom(ClassAssertion(Concept("Machine"), Instance("Icarus"))), TBoxAxiom(Subsumption(Concept("Man"), Concept("Biological"))), TBoxAxiom(Subsumption(Concept("Machine"), Not(Concept("Man")))), TBoxAxiom(Subsumption(Concept("Biological"), Concept("Man"))) ] inconsistent_test_kb = [ ABoxAxiom(ClassAssertion(Concept("Man"), Instance("Aditya"))), ABoxAxiom( ClassAssertion(And(Concept("Machine"), Concept("Man")), Instance("Adam"))),
def test_complex_and_or(self): axiom=Or(And(Concept("Man"),Not(Concept("Man"))),And(Concept("Machine"),Or(Not(Concept("Machine")),Concept("Machine")))) models=get_models({},axiom,"Aditya") self.assertTrue(is_model_consistent(models))
import sys sys.path.append("/home/adityas/Projects/ALC-reasoner/") from reasoner.knowledgebase.axioms import And, Or, Not, ClassAssertion, ABoxAxiom, RoleAssertion, TBoxAxiom, Subsumption from reasoner.common.constructors import Concept, All, Some, Instance simple_or = Or(Concept("Man"), Concept("Machine")) complex_or = Or(Or(Concept("Man"), Concept("Machine")), Concept("Robot")) kinda_complicated_axiom = And( Or(And(Concept("Man"), Not(Concept("Machine"))), And(Concept("Machine"), Not(Concept("Man")))), Concept("Physical")) kinda_complicated_abox = ABoxAxiom( ClassAssertion(kinda_complicated_axiom, Instance("Aditya"))) kinda_complicated_unsat_axiom = And( Or(And(Concept("Man"), Not(Concept("Machine"))), And(Concept("Machine"), Not(Concept("Man")))), And(Concept("Man"), Concept("Machine"))) kinda_complicated_unsat_abox = ABoxAxiom( ClassAssertion(kinda_complicated_unsat_axiom, Instance("Aditya"))) simple_and_abox = ABoxAxiom( ClassAssertion(And(Concept("Man"), Concept("Machine")), Instance("Aditya"))) simple_or_abox = ABoxAxiom(ClassAssertion(simple_or, Instance("Aditya"))) consistent_complex_abox = [ ABoxAxiom(
def test_simple_some(self): axiom=Some("hasParent",And(Concept("Man"),Concept("Human"))) models=get_models({},axiom,"Aditya") self.assertTrue(is_model_consistent(models))
def test_add_single_axiom(self): self.KB.add_axiom(Concept("Terminator")) self.assertEqual(len(self.KB), len(self.axioms) + 1)
def test_simple_all(self): axiom=All("hasParent",And(Concept("Engineer"),Concept("Graduate"))) models=get_models(self.pre_graph,axiom,"Aditya")
def test_not_contains_axiom(self): self.assertFalse(self.KB.contains(Concept("Dinosaur")))
def test_nnf_not_not_not_concept(self): self.assertEqual(NNF(Not(Not(Not(Concept("A"))))), Not(Concept("A"))) self.assertNotEqual(Not(Not(Concept("A"))), Not(Concept("A")))