fix: Evaluation
This commit is contained in:
parent
d702b9b081
commit
1acd1cfb67
17 changed files with 189 additions and 120 deletions
|
@ -101,21 +101,28 @@ class EvaluationTest {
|
|||
val father = Fact(Structure(Atom("father"), listOf(Atom("john"), Atom("jimmy"))))
|
||||
val mother = Fact(Structure(Atom("mother"), listOf(Atom("jane"), Atom("jimmy"))))
|
||||
|
||||
val variable1 = Variable("X")
|
||||
val variable2 = Variable("Y")
|
||||
|
||||
val parent = Rule(
|
||||
Structure(Atom("parent"), listOf(Variable("X"), Variable("Y"))),
|
||||
Structure(Atom("parent"), listOf(variable1, variable2)),
|
||||
/* :- */ Disjunction(
|
||||
Structure(Atom("father"), listOf(Variable("X"), Variable("Y"))),
|
||||
Structure(Atom("father"), listOf(variable1, variable2)),
|
||||
/* ; */
|
||||
Structure(Atom("mother"), listOf(Variable("X"), Variable("Y")))
|
||||
Structure(Atom("mother"), listOf(variable1, variable2))
|
||||
))
|
||||
|
||||
Program.load(listOf(father, mother, parent))
|
||||
|
||||
assertTrue(Program.query(Structure(Atom("parent"), listOf(Atom("john"), Atom("jimmy")))))
|
||||
assertTrue(Program.query(Structure(Atom("parent"), listOf(Atom("jane"), Atom("jimmy")))))
|
||||
val result1 = Program.query(Structure(Atom("parent"), listOf(Atom("john"), Atom("jimmy"))))
|
||||
assertTrue(result1)
|
||||
val result2 = Program.query(Structure(Atom("parent"), listOf(Atom("jane"), Atom("jimmy"))))
|
||||
assertTrue(result2)
|
||||
|
||||
assertFalse(Program.query(Structure(Atom("parent"), listOf(Atom("john"), Atom("jane")))))
|
||||
assertFalse(Program.query(Structure(Atom("father"), listOf(Atom("john"), Atom("jane")))))
|
||||
val result3 = Program.query(Structure(Atom("parent"), listOf(Atom("john"), Atom("jane"))))
|
||||
assertFalse(result3)
|
||||
val result4 = Program.query(Structure(Atom("father"), listOf(Atom("john"), Atom("jane"))))
|
||||
assertFalse(result4)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,18 +137,25 @@ class EvaluationTest {
|
|||
val parent1 = Fact(Structure(Atom("parent"), listOf(Atom("john"), Atom("jimmy"))))
|
||||
val parent2 = Fact(Structure(Atom("parent"), listOf(Atom("jane"), Atom("jimmy"))))
|
||||
|
||||
val variable1 = Variable("X")
|
||||
val variable2 = Variable("Y")
|
||||
|
||||
val isFather = Rule(
|
||||
Structure(Atom("isFather"), listOf(Variable("X"), Variable("Y"))),
|
||||
Structure(Atom("isFather"), listOf(variable1, variable2)),
|
||||
Conjunction(
|
||||
Structure(Atom("parent"), listOf(Variable("X"), Variable("Y"))),
|
||||
Structure(Atom("male"), listOf(Variable("X")))
|
||||
Structure(Atom("parent"), listOf(variable1, variable2)),
|
||||
Structure(Atom("male"), listOf(variable1))
|
||||
)
|
||||
)
|
||||
|
||||
val variable3 = Variable("X")
|
||||
val variable4 = Variable("Y")
|
||||
|
||||
val isMother = Rule(
|
||||
Structure(Atom("isMother"), listOf(Variable("X"), Variable("Y"))),
|
||||
Structure(Atom("isMother"), listOf(variable3, variable4)),
|
||||
Conjunction(
|
||||
Structure(Atom("parent"), listOf(Variable("X"), Variable("Y"))),
|
||||
Structure(Atom("female"), listOf(Variable("X")))
|
||||
Structure(Atom("parent"), listOf(variable3, variable4)),
|
||||
Structure(Atom("female"), listOf(variable3))
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Reference in a new issue