diff options
author | Martin Možina <martin.mozina@fri.uni-lj.si> | 2015-10-18 19:21:36 +0200 |
---|---|---|
committer | Martin Možina <martin.mozina@fri.uni-lj.si> | 2015-10-18 19:21:36 +0200 |
commit | ce6b6b0bc9af3cff176bd995ee25c8334eea632c (patch) | |
tree | 0b6606017549c342171440fd61059e57195e7384 /prolog/problems/family_relations/cousin_2/common.py | |
parent | 7dd2b4dc917fe26267c1db1f5f58585a5417cb8c (diff) | |
parent | 8f0a1bdd9a2f2e0b951dd07c23d7f4db1189aee5 (diff) |
Merge branch 'master' of 192.168.15.97:codeq-problems
Diffstat (limited to 'prolog/problems/family_relations/cousin_2/common.py')
-rw-r--r-- | prolog/problems/family_relations/cousin_2/common.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/prolog/problems/family_relations/cousin_2/common.py b/prolog/problems/family_relations/cousin_2/common.py index 8dc33b8..c556ffd 100644 --- a/prolog/problems/family_relations/cousin_2/common.py +++ b/prolog/problems/family_relations/cousin_2/common.py @@ -4,7 +4,7 @@ from operator import itemgetter import socket import prolog.engine import prolog.util -from server.hints import Hint, HintSequence +from server.hints import Hint, HintPopup import server.problems id = 99 @@ -34,6 +34,7 @@ cousin(X, Y) :- ''' hint_type = { + 'gender_is_irrelevant_markup': HintPopup('gender_is_irrelevant_markup'), 'gender_is_irrelevant': Hint('gender_is_irrelevant'), 'precedence_fail': Hint('precedence_fail'), 'cousin_vs_sibling': Hint('cousin_vs_sibling'), @@ -42,7 +43,12 @@ hint_type = { } test_cases = [ - # TODO + ('cousin(X, _)', + [{'X': 'vanessa'}, {'X': 'patricia'}, {'X': 'melanie'}, {'X': 'andrew'}, {'X': 'john'}, {'X': 'susan'}]), + ('cousin(X, john)', + [{'X': 'susan'}]), + ('cousin(patricia, X)', + [{'X': 'andrew'}, {'X': 'melanie'}]), ] def test(program, solved_problems): @@ -87,10 +93,10 @@ def hint(program, solved_problems): # gender testing is redundant # this is not necessarily wrong, but worth mentioning anyway targets = [prolog.util.Token('NAME', 'male'), prolog.util.Token('NAME', 'female')] - pos = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets] - if pos: - # TODO: resolve how highlighting info is communicated - return [{'id': 'gender_is_irrelevant', 'highlight': pos}] + marks = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets] + if marks: + return [{'id': 'gender_is_irrelevant_markup', 'start': m[0], 'end': m[1]} for m in marks] + \ + [{'id': 'gender_is_irrelevant'}] # precedence fail (AND block vs OR block) # case in point: parent(PX, X), parent(PY, Y), brother(PX, PY) ; sister(PX, PY) @@ -98,18 +104,18 @@ def hint(program, solved_problems): # warning: knowledge base dependent if prolog.util.Token('SEMI', ';') in tokens and prolog.engine.ask_truth(engine_id, 'findall(_, cousin(X, Y), L), (length(L, 14) ; length(L, 16))'): - return [{'id', 'precedence_fail'}] + return [{'id': 'precedence_fail'}] # cousin should not be brother or sister # common parent, probably solved via grandparent if prolog.engine.ask_truth(engine_id, 'cousin(X, Y), (brother(X, Y) ; sister(X, Y))'): - return [{'id', 'cousin_vs_sibling'}] + return [{'id': 'cousin_vs_sibling'}] # cousin to him/herself # just common grandparent is not enough if prolog.engine.ask_truth(engine_id, 'cousin(X, X)'): - return [{'id', 'cousin_to_oneself'}] + return [{'id': 'cousin_to_oneself'}] # X (or Y) does not necessarily need to be a parent |