From 86bfc55d2ddc19b79127f2c788609635b702dbfd Mon Sep 17 00:00:00 2001 From: Aleksander Sadikov Date: Sat, 17 Oct 2015 20:04:54 +0200 Subject: Family relations section fully hint-ready (just a few minor things missing). --- .../family_relations/descendant_2/common.py | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'prolog/problems/family_relations/descendant_2/common.py') 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 -- cgit v1.2.1