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). --- .../problems/family_relations/cousin_2/common.py | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'prolog/problems/family_relations/cousin_2/common.py') 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 -- cgit v1.2.1