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/descendant_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/descendant_2/common.py')
-rw-r--r-- | prolog/problems/family_relations/descendant_2/common.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/prolog/problems/family_relations/descendant_2/common.py b/prolog/problems/family_relations/descendant_2/common.py index cfa1d37..49e7e5c 100644 --- a/prolog/problems/family_relations/descendant_2/common.py +++ b/prolog/problems/family_relations/descendant_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 = 101 @@ -21,8 +21,10 @@ descendant(X, Y) :- ''' hint_type = { + 'gender_is_irrelevant_markup': HintPopup('gender_is_irrelevant_markup'), 'gender_is_irrelevant': Hint('gender_is_irrelevant'), 'grandparent_used': Hint('grandparent_used'), + 'grandparent_used_markup': HintPopup('grandparent_used_markup'), 'base_case': Hint('base_case'), 'descendant_of_oneself': Hint('ancestor_to_oneself'), 'descendant_need_not_be_parent': Hint('descendant_need_not_be_parent'), @@ -30,7 +32,12 @@ hint_type = { } test_cases = [ - # TODO + ('descendant(anna, X)', + [{'X': 'jerry'}, {'X': 'elaine'}, {'X': 'morty'}, {'X': 'helen'}]), + ('descendant(daniela, X)', + [{'X': 'nevia'}, {'X': 'aleksander'}, {'X': 'margaret'}, {'X': 'ana'}, {'X': 'aleksandr'}]), + ('descendant(X, william)', + [{'X': 'vanessa'}, {'X': 'patricia'}, {'X': 'susan'}, {'X': 'john'}, {'X': 'michael'}, {'X': 'michelle'}]), ] def test(program, solved_problems): @@ -75,29 +82,29 @@ 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'}] # grandparent is a sign of complications # it's likely used instead of recursion targets = [prolog.util.Token('NAME', 'grandparent')] - 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': 'grandparent_used', 'highlight': pos}] + marks = [(t.pos, t.pos + len(t.val)) for t in tokens if t in targets] + if marks: + return [{'id': 'grandparent_used_markup', 'start': m[0], 'end': m[1]} for m in marks] + \ + [{'id': 'grandparent_used'}] # missing/failed base case # TODO: how will ask_truth handle/return timeouts... # TODO: timeout is the same as fail in this particular case if prolog.engine.ask_truth(engine_id, 'parent(Y, X), \+ descendant(X, Y)'): - return [{'id', 'base_case'}] + return [{'id': 'base_case'}] # descendant of oneself if prolog.engine.ask_truth(engine_id, 'descendant(X, X)'): - return [{'id', 'descendant_of_oneself'}] + return [{'id': 'descendant_of_oneself'}] # X does not necessarily need to be a parent if prolog.engine.ask_one(engine_id, @@ -109,7 +116,7 @@ def hint(program, solved_problems): if prolog.engine.ask_truth(engine_id, 'findall(_, descendant(william, X), L1), length(L1, 6), \ findall(_, descendant(X, william), L2), length(L2, 2)'): - return [{'id', 'wrong_direction'}] + return [{'id': 'wrong_direction'}] except socket.timeout as ex: pass |