summaryrefslogtreecommitdiff
path: root/prolog/problems/family_relations/aunt_2/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'prolog/problems/family_relations/aunt_2/common.py')
-rw-r--r--prolog/problems/family_relations/aunt_2/common.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/prolog/problems/family_relations/aunt_2/common.py b/prolog/problems/family_relations/aunt_2/common.py
index 51bc99a..df1a272 100644
--- a/prolog/problems/family_relations/aunt_2/common.py
+++ b/prolog/problems/family_relations/aunt_2/common.py
@@ -27,14 +27,21 @@ aunt(X, Y) :-
hint_type = {
'x_and_y_mixed_up': Hint('x_and_y_mixed_up'),
'precedence_fail': Hint('precedence_fail'),
+ 'x_must_have_sibling': Hint('x_must_have_sibling'),
'x_must_be_female': Hint('x_must_be_female'),
+ 'y_must_have_parent': Hint('y_must_have_parent'),
'aunt_vs_mother': Hint('aunt_vs_mother'),
'x_need_not_be_parent': Hint('x_need_not_be_parent'),
'y_need_not_be_parent': Hint('y_need_not_be_parent'),
}
test_cases = [
- # TODO
+ ('aunt(X, _)',
+ [{'X': 'sally'}, {'X': 'melanie'}, {'X': 'vanessa'}, {'X': 'patricia'}]),
+ ('aunt(_, X)',
+ [{'X': 'vanessa'}, {'X': 'patricia'}, {'X': 'joanne'}, {'X': 'john'}, {'X': 'susan'}]),
+ ('aunt(sally, X)',
+ [{'X': 'vanessa'}, {'X': 'patricia'}]),
]
def test(program, solved_problems):
@@ -82,25 +89,36 @@ def hint(program, solved_problems):
if prolog.engine.ask_truth(engine_id,
'findall(X/Y, aunt(X, Y), \
[vanessa/sally, patricia/sally, joanne/melanie, john/vanessa, susan/patricia])'):
- return [{'id', 'x_and_y_mixed_up'}]
+ return [{'id': 'x_and_y_mixed_up'}]
# precedence fail (AND block vs OR block)
# case in point: female(X), parent(P, Y), brother(P, X) ; sister(P, X)
# warning: knowledge base dependent
if prolog.util.Token('SEMI', ';') in tokens and prolog.engine.ask_truth(engine_id,
'findall(_, aunt(X, Y), L), length(L, 15)'):
- return [{'id', 'precedence_fail'}]
+ return [{'id': 'precedence_fail'}]
# X must be female
if prolog.engine.ask_truth(engine_id,
'aunt(X, _), male(X)'):
- return [{'id', 'x_must_be_female'}]
+ return [{'id': 'x_must_be_female'}]
+
+ # Y must have a parent
+ # perhaps risky as only one such nephew exists in DB (susan)
+ if prolog.engine.ask_truth(engine_id,
+ 'aunt(_, Y), \+ parent(_, Y)'):
+ return [{'id': 'y_must_have_parent'}]
# X and P can be the same person
# this can occur if the problem is not solved using sister/2
if prolog.engine.ask_truth(engine_id,
'aunt(X, Y), mother(X, Y)'):
- return [{'id', 'aunt_vs_mother'}]
+ return [{'id': 'aunt_vs_mother'}]
+
+ # X must have sibling
+ if prolog.engine.ask_truth(engine_id,
+ 'aunt(X, _), \+ (sister(X, _) ; brother(X, _))'): # TODO: Tim, can I use sister/brother predicates here? Or sister98?
+ return [{'id': 'x_must_have_sibling'}]
# X does not necessarily need to be a parent
# perhaps risky as only one aunt that is not a parent exists in DB (melanie)