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/cousin_2/Prolog_cousin_01.svg | 448 +++++++++++ .../family_relations/cousin_2/Prolog_cousin_02.svg | 582 +++++++++++++++ .../family_relations/cousin_2/Prolog_cousin_03.svg | 825 +++++++++++++++++++++ .../family_relations/cousin_2/Prolog_cousin_04.svg | 609 +++++++++++++++ .../problems/family_relations/cousin_2/common.py | 24 +- prolog/problems/family_relations/cousin_2/sl.py | 19 +- 6 files changed, 2489 insertions(+), 18 deletions(-) create mode 100644 prolog/problems/family_relations/cousin_2/Prolog_cousin_01.svg create mode 100644 prolog/problems/family_relations/cousin_2/Prolog_cousin_02.svg create mode 100644 prolog/problems/family_relations/cousin_2/Prolog_cousin_03.svg create mode 100644 prolog/problems/family_relations/cousin_2/Prolog_cousin_04.svg (limited to 'prolog/problems/family_relations/cousin_2') diff --git a/prolog/problems/family_relations/cousin_2/Prolog_cousin_01.svg b/prolog/problems/family_relations/cousin_2/Prolog_cousin_01.svg new file mode 100644 index 0000000..2e7cf55 --- /dev/null +++ b/prolog/problems/family_relations/cousin_2/Prolog_cousin_01.svg @@ -0,0 +1,448 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/cousin_2/Prolog_cousin_02.svg b/prolog/problems/family_relations/cousin_2/Prolog_cousin_02.svg new file mode 100644 index 0000000..3844a83 --- /dev/null +++ b/prolog/problems/family_relations/cousin_2/Prolog_cousin_02.svg @@ -0,0 +1,582 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/cousin_2/Prolog_cousin_03.svg b/prolog/problems/family_relations/cousin_2/Prolog_cousin_03.svg new file mode 100644 index 0000000..8829022 --- /dev/null +++ b/prolog/problems/family_relations/cousin_2/Prolog_cousin_03.svg @@ -0,0 +1,825 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/prolog/problems/family_relations/cousin_2/Prolog_cousin_04.svg b/prolog/problems/family_relations/cousin_2/Prolog_cousin_04.svg new file mode 100644 index 0000000..d49256c --- /dev/null +++ b/prolog/problems/family_relations/cousin_2/Prolog_cousin_04.svg @@ -0,0 +1,609 @@ + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 diff --git a/prolog/problems/family_relations/cousin_2/sl.py b/prolog/problems/family_relations/cousin_2/sl.py index 7e3e7f0..7bd819a 100644 --- a/prolog/problems/family_relations/cousin_2/sl.py +++ b/prolog/problems/family_relations/cousin_2/sl.py @@ -13,23 +13,24 @@ description = '''\ plan = ['''\

Verjetno bi se sedaj splačalo uporabiti rešitev kakšne prejšnje naloge?

-

-

Loni naj zbriše imena relacij (parent, sister) s te slike!

-

Seveda se da rešiti tudi brez prejšnjih rešitev... MORE

-

-

Loni naj zbriše imena relacij (parent, sister) s te slike!

-''', '''\ -

+

Jaz imam otroka, moj brat ali sestra ima tudi otroka...

+

Seveda se da rešiti tudi brez prejšnjih rešitev...

''', '''\

Če je PX starš od X in je PY starš od Y ter sta PX in PY brat ali sestra, potem je X bratranec/sestrična od Y.

+''', '''\ +

Jaz imam otroka, moj brat ali sestra ima tudi otroka, najina otroka sta zato...

'''] hint = { 'gender_is_irrelevant': '''\

Je spol res pomemben?

+''', + + 'gender_is_irrelevant_markup': '''\ +

Je to res potrebno?

''', 'precedence_fail': '''\ @@ -41,13 +42,13 @@ lahko uporabiš oklepaje.

'cousin_vs_sibling': '''\

Kako je lahko bratranec/sestrična hkrati tudi brat/sestra od Y? Si morda pozabil, da starša od X in Y ne smeta biti ista oseba?

-

+

''', 'cousin_to_oneself': '''\

Kako je lahko nekdo bratranec/sestrična samemu sebi? Imata morda X in Y istega starša?

-

+

''', 'cousin_need_not_be_parent': '''\ -- cgit v1.2.1