Skip to content

Commit

Permalink
Can figure out creation/production
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Garside committed Feb 27, 2014
1 parent 1b7141f commit 505f740
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 17 deletions.
67 changes: 64 additions & 3 deletions EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,18 @@
## Data extraction

### Sentence 1
cars owned by Joey = 13
toy cars owned by Joey = 13
toy cars owned by Joey + 13

### Sentence 2
cars owned by Chandler = 6
toy cars owned by Chandler = 6
toy cars owned by Chandler + 6

### Sentence 3
No data

## Correct response
14 toy cars
7 toy cars

***

Expand Down Expand Up @@ -2574,3 +2574,64 @@

## Correct response
38 cents

***

# Zoidberg Solution

## The problem
Mrs. Hilt made 5 Rice Krispie Treats.
She used 8 large marshmallows and 10 mini marshmallows.
How many marshmallows did she use altogether?


## Digested problem
Mrs. Hilt made 5 Rice Krispie Treats .
NNP NNP VBD CD NNP NNP NNPS .

She used 8 large marshmallows and 10 mini marshmallows .
PRP VBD CD JJ NNS CC CD NN VBZ .

How many marshmallows did she use altogether ?
WRB JJ NNS VBD PRP VBP RB .

## Problem inference
I think this problem is about Mrs. Hilt Rice Krispie Treats, Rice Treats, Krispie Treats, large marshmallows, mini marshmallows, and marshmallows and asks a single question.

## Parsed problem
Mrs. Hilt made 5 Rice Krispie Treats .
context operator constant unit punctuation

Mrs. Hilt used 8 large marshmallows and 10 mini marshmallows .
context operator constant unit coordinating_conjunction constant unit punctuation

How many marshmallows did Mrs. Hilt use altogether ?
asking unit q_start context q_stop subordinate punctuation


## Question 1

### Question text
How many marshmallows did she use altogether?

### Answer interpretation
The answer is the unknown value of marshmallows used by Mrs. Hilt added together.

## Data extraction

### Sentence 1
Krispie Treats created by Mrs. Hilt +> 5
Rice Treats created by Mrs. Hilt +> 5
Rice Krispie Treats created by Mrs. Hilt +> 5

### Sentence 2
marshmallows used by Mrs. Hilt <- 8
marshmallows used by Mrs. Hilt <- 10
large marshmallows used by Mrs. Hilt <- 8
mini marshmallows used by Mrs. Hilt <- 10

### Sentence 3
No data

## Correct response
18 marshmallows
4 changes: 4 additions & 0 deletions calibrations/46.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Mrs. Hilt made 5 Rice Krispie Treats.
She used 8 large marshmallows and 10 mini marshmallows.
How many marshmallows did she use altogether?

2 changes: 1 addition & 1 deletion example.brain.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion run_example.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
clear
echo "" > EXAMPLE.md
MIN_ID=1
MAX_IDX=45
MAX_IDX=46

for i in $(seq $MIN_ID $MAX_IDX); do
cat calibrations/$i.txt | zoidberg | tee -a EXAMPLE.md
Expand Down
4 changes: 3 additions & 1 deletion zoidberg/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"su": "lost by",
"di": "lost by",
"re": "required by",
"co": "converted by"
"co": "converted by",
"cr": "created by",
"cn": "used by",
}

ANSWER_SYNTAX = {
Expand Down
10 changes: 8 additions & 2 deletions zoidberg/brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def common_prefix(strings):
("di", "Division"),
("re", "Requires (the total we need to answer)"),
("co", "Convert (change one unit into another)"),
("ex", "Exchange (give units from one context to another)")
("ex", "Exchange (give units from one context to another)"),
("cr", "Creates (makes something)"),
("cn", "Consume (something used to make something)")
]

# Various types of supported subordinace
Expand Down Expand Up @@ -180,6 +182,10 @@ def common_prefix(strings):
("wh_pro", "Wh-pronoun"),
("pos_wh_pro", "Possessive Wh-pronoun"),

("jj", "Adjective"),
("jjr", "Adjective, comparative"),
("jjs", "Adjective, superlative"),

("vb", "Verb, base form"),
("vbd", "Verb, past tense"),
("vbg", "Verb, gerund/present participle"),
Expand Down Expand Up @@ -454,7 +460,7 @@ def retag(self, val, tag):
val = str(self.raw["numbers"][val])
elif item == "pre_ind_plu":
tag = "PIP"
elif item[:2] == "vb":
elif item[:2] in ["vb", "jj"]:
tag = item.upper()
else:
print item
Expand Down
10 changes: 7 additions & 3 deletions zoidberg/sentence_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,10 @@ def do_track(subtype, tag):
self.last_context = None
lc = self.contexts.pop()
self.parsed.pop()
if self.main_context == lc:
self.main_context = None

context = " ".join([self.last_word, word])
context = " ".join([lc, word])
if self.is_relative_quantity and self.comparator_context == lc:
self.comparator_context = context
if self.subtype is not None and self.subtype[1] == "ambiguous":
Expand All @@ -675,7 +677,8 @@ def do_track(subtype, tag):
self.comparator_context = context
self.track(context, "comparator_context", self.subtype)
else:
self.main_context = context
if not self.main_context:
self.main_context = context
self.track(context, "context", self.subtype)
self.context_subtypes[context] = self.subtype

Expand Down Expand Up @@ -965,7 +968,7 @@ def do_track(subtype, tag):
for part in self.parsed:
word, role, subtype = part
if role == "context":
if word in self.problem.units:
if word in self.problem.units or (word != self.main_context and len(self.units) == 0):
self.contexts.remove(word)
role = "unit"
self.units.append(word)
Expand Down Expand Up @@ -995,6 +998,7 @@ def do_track(subtype, tag):
role = "context"
self.contexts.append(word)
reparsed.append((word, role, subtype))
#rint self.sentence_text, "::::", self.main_context
self.parsed = reparsed

# Make all the inferred items unique
Expand Down
36 changes: 30 additions & 6 deletions zoidberg/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,27 @@
from utilities import oxfordComma
from math import floor

OPERATOR_F_STR = {
"eq": "owned by",
"ad": "owned by",
"mu": "owned by",
"su": "owned by",
"di": "owned by",
"eqx": "owned by",
"cr": "created by",
"cn": "used by",
"re": "needed by",
"ans": "owned by"
}

OPERATOR_STR = {
"eq": "owned by",
"ad": "gained by",
"mu": "gained by",
"su": "lost by",
"di": "lost by",
"cr": "created by",
"cn": "used by",
"ans": "finally owned by"
}

Expand All @@ -27,7 +42,9 @@
"di": "/",
"re": "==",
"co": "=>",
"ex": "->"
"ex": "->",
"cn": "<-",
"cr": "+>"
}

def number(s):
Expand Down Expand Up @@ -209,7 +226,8 @@ def get_symbol(self, context, context_constant, unit, container, idx=-1, operato
#raise Exception
if operator != "eqx":
self.work[dsym].append("= " + str(constant))
elif operator == "ad":
elif operator in ["ad", "cr", "cn"]:
#rint symbol, constant, sym
if self.relational_var is None:
symbol += constant
u_symbol += constant
Expand Down Expand Up @@ -595,6 +613,8 @@ def digest_unit_groups(self, container, k1, context_constant, k2, rmc=None):
item = parts.pop()
for part in parts:
nu = " ".join([part, item])
if nu == k2:
nu = item

if nu in self.containers[container][k1][context_constant]:
ndata = []
Expand Down Expand Up @@ -1042,6 +1062,10 @@ def simple_solve(sym, context_constant, rel_var=None):
for s in answer.subordinates:
word, sub = s

if sub == "context_grouping" and (answer.context is not None and not self.problem.exestential):
# we don't want to consider a context group if there aren't a composite context
if not "and" in answer.context:
sub = "unit_grouping"
if sub == "context_grouping" and answer.context is None and self.problem.exestential:
# Exestential problems may not have contexts for things
# wonder about alltogetherness. This is a tough case
Expand Down Expand Up @@ -1083,6 +1107,7 @@ def simple_solve(sym, context_constant, rel_var=None):
self.correct_responses.append(
"Not sure; too many starting variables!")
elif sub == "unit_grouping":
#rint "do unit groupin", answer.unit, answer.context
do_orig = False
if resp is None and answer.unit:
con_con = answer.context_constant
Expand Down Expand Up @@ -1376,11 +1401,10 @@ def __str__(self):
elif context is not None and unit is not None:

i.append(unit)
if operator is not None and operator == "re":
i.append("needed by")
else:
# i.append(OPERATOR_STR[operator])
if operator is None:
i.append("owned by")
else:
i.append(OPERATOR_F_STR[operator])

# if self.problem.inference.is_requirement_problem:

Expand Down

0 comments on commit 505f740

Please sign in to comment.