Skip to content

Commit

Permalink
Tags and connotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Garside committed Feb 3, 2014
1 parent f9127d3 commit 97065a1
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 10 deletions.
53 changes: 53 additions & 0 deletions EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1052,3 +1052,56 @@ feathers owned by Dad - 4

### Response 2
3 feathers

***

# Zoidberg Solution

## The problem
Tom is 6 years old.
Lee is 3 years younger than Tom.
How old is Lee?

## Digested problem
Tom is 6 years old .
NNP VBZ CD NNS JJ .

Lee is 3 years younger than Tom .
NNP VBZ CD NNS JJR IN NNP .

How old is Lee ?
WRB JJ VBZ NNP .

## Problem inference
I think this problem is about Tom and Lee grouping years and asks a single question.

## Parsed problem
Tom is 6 years old .
context operator constant unit adjective punctuation

Lee is 3 years younger than Tom .
context operator constant unit rel_less conjunction comparator_context punctuation

How old is Lee ?
asking q_start context punctuation


## Question 1

### Question text
How old is Lee?

### Answer interpretation
The answer is the unknown value of years owned by Lee.

## Data extraction

### Sentence 1
years owned by Tom = 6

### Sentence 2
years owned by Lee = 6
years owned by Lee - 3

## Correct response
3 years
3 changes: 3 additions & 0 deletions calibrations/20.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Tom is 6 years old.
Lee is 3 years younger than Tom.
How old is Lee?
2 changes: 1 addition & 1 deletion example.brain.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"gender": {"Archie": "masculine", "bananas": "neutral", "family": "mixed", "Marc": "masculine", "fish": "mixed", "Jim": "masculine", "doughnuts": "neutral", "pieces": "neutral", "Mr.": "masculine", "himself": "masculine", "Lupis": "ambiguous", "pond": "neutral", "Jane": "feminine", "muffins": "neutral", "skulls": "neutral", "Chandler": "masculine", "Hellen": "feminine", "skeleton": "neutral", "pink": "neutral", "toy": "neutral", "bottles": "neutral", "Mitch": "masculine", "her": "feminine", "cobs": "neutral", "Troy": "masculine", "Ragdoll": "feminine", "him": "masculine", "William": "masculine", "Mac": "masculine", "Jack": "masculine", "Charlie": "masculine", "jars": "neutral", "he": "masculine", "balloons": "neutral", "eggs": "neutral", "friend": "ambiguous", "dolls": "neutral", "Jones": "ambiguous", "Dad": "masculine", "them": "mixed", "his": "masculine", "Alex": "masculine", "marbles": "neutral", "Sara": "feminine", "cars": "neutral", "corn": "neutral", "Meathead": "masculine", "Michael": "masculine", "Lucy": "feminine", "Mrs.": "feminine", "boys": "masculine", "they": "mixed", "Skellington": "ambiguous", "Lisa": "feminine", "Tony": "masculine", "friends": "mixed", "Richard": "masculine", "Joey": "masculine", "Mickey": "masculine", "christmas": "neutral", "Pigpen": "masculine", "Spooky": "ambiguous", "newspapers": "neutral", "Bennett": "masculine", "tree": "neutral", "Julia": "feminine", "rocks": "neutral", "feathers": "neutral", "ornaments": "neutral", "she": "feminine", "mother": "feminine", "Ethelle": "feminine", "sister": "feminine", "pizza": "neutral", "Eric": "masculine", "apples": "neutral"}, "operator_verbs": {"has": "eq", "needs": "re", "ate": "su", "join": "ad", "takes": "su", "give": "ex", "tree": null, "buys": "ad", "had": "eq", "collects": "ad", "gave": "ex", "buy": "ad", "bake": "co", "have": "eq", "were": "False", "need": "re", "kept": "su", "left": null, "bought": "ad", "throws": "su", "gives": "ex"}, "inclusive": {"her family": "inclusive", "family": "inclusive", "his friends": "exclusive", "Mrs. Jones' family": "inclusive", "Pigpen's friends": "exclusive", "friends": "exclusive", "her friends": "exclusive", "Mrs. Jones' friends": "exclusive"}, "numbers": {"4": "4", "dozen": "12"}, "subordinates": {"pond": "place_noun", "left": "time_ending", "away": "False", "there": null, "only": "False", "rocks": null, "boys": "context_grouping", "christmas tree": "place_noun", "apples": null, "altogether": "context_grouping", "muffins": null, "now": "time_ending", "beginning": "time_starting", "friend": null, "pizza": null}, "variables": {"some": "dynamic_variable", "half": "0.5"}, "retagged": {"fish": "noun", "are": "pre_ind_plu", "collects": "operator_verbs", "muffins": "noun_p", "bake": "operator_verbs", "dozen": "numbers", "mitch": "prop_noun", "away": "noise", "there": "exestential", "only": "noise", "4": "numbers", "friend": "noun", "pizza": "noun", "beginning": "subordinates", "ate": "operator_verbs", "join": "operator_verbs", "tree": "noun", "rocks": "noun_p", "apples": "noun_p", "were": "noise", "more": "comparison_adj", "left": "subordinates"}, "relative": {"fewer": "rel_less", "more": "rel_more"}, "answer_syntax": {"How many": "expression", "how many": "expression"}, "plurality": {"Archie": "singular", "bananas": "plural", "family": "plural", "Marc": "singular", "fish": "regular", "Jim": "singular", "doughnuts": "plural", "pieces": "singular", "Mr.": "singular", "himself": "singular", "are": null, "Lupis": "singular", "muffins": "plural", "Jane": "singular", "pond": "singular", "skulls": "plural", "Chandler": "singular", "Hellen": "singular", "dozen": null, "pink": "singular", "toy": "singular", "bottles": "plural", "Richard": "singular", "her": "singular", "cobs": "plural", "beginning": null, "Troy": "singular", "Ragdoll": "singular", "William": "singular", "Mac": "singular", "Jack": "singular", "Charlie": "singular", "jars": "plural", "Joey": "singular", "balloons": "plural", "eggs": "plural", "Mitch": "singular", "dolls": "plural", "Jones": "singular", "Dad": "singular", "them": "plural", "his": "singular", "Alex": "singular", "marbles": "plural", "Ethelle": "singular", "Sara": "singular", "cars": "plural", "corn": "singular", "Meathead": "singular", "Michael": "singular", "Lucy": "singular", "Mrs.": "singular", "boys": "plural", "they": "plural", "Skellington": "singular", "collects": null, "Lisa": "singular", "friends": "plural", "him": "singular", "he": "singular", "Mickey": "singular", "christmas": "singular", "Pigpen": "singular", "ate": null, "join": null, "mitch": null, "she": "singular", "Spooky": "singular", "newspapers": "plural", "Bennett": "singular", "tree": "singular", "Julia": "singular", "rocks": "plural", "skeleton": "singular", "feathers": "plural", "ornaments": "plural", "friend": "singular", "mother": "singular", "Tony": "singular", "sister": "singular", "pizza": "singular", "Eric": "singular", "apples": "plural"}, "exestential": {"there": "noise"}, "unknown": {"('bake', 'VB', None)": null, "('4', 'LS', None)": null, "('fish', 'JJ', None)": null, "('more', 'RBR', None)": null}, "gerunds": {"remaining": "solution_zero", "swimming": "acting"}, "comparison_adj": {"more": "gt"}, "determiners": {"a": "constant", "away": "noise", "were": "noise", "some": "variable", "only": "noise", "another": "noise", "half": "variable", "the": "noise"}}
{"connotation_tags": {"how old": "age"}, "comparison_adj": {"more": "gt"}, "operator_verbs": {"give": "ex", "is": "eq", "have": "eq", "gave": "ex", "need": "re", "collects": "ad", "bake": "co", "needs": "re", "takes": "su", "had": "eq", "buys": "ad", "has": "eq", "gives": "ex", "buy": "ad", "join": "ad", "ate": "su", "kept": "su", "tree": null, "were": "False", "bought": "ad", "throws": "su", "left": null}, "inclusive": {"her family": "inclusive", "family": "inclusive", "his friends": "exclusive", "Mrs. Jones' family": "inclusive", "Pigpen's friends": "exclusive", "friends": "exclusive", "her friends": "exclusive", "Mrs. Jones' friends": "exclusive"}, "numbers": {"4": "4", "dozen": "12"}, "subordinates": {"pond": "place_noun", "left": "time_ending", "away": "False", "there": null, "only": "False", "rocks": null, "boys": "context_grouping", "christmas tree": "place_noun", "apples": null, "altogether": "context_grouping", "muffins": null, "now": "time_ending", "beginning": "time_starting", "friend": null, "pizza": null}, "variables": {"some": "dynamic_variable", "half": "0.5"}, "retagged": {"fish": "noun", "are": "pre_ind_plu", "collects": "operator_verbs", "muffins": "noun_p", "bake": "operator_verbs", "dozen": "numbers", "mitch": "prop_noun", "away": "noise", "there": "exestential", "only": "noise", "4": "numbers", "friend": "noun", "pizza": "noun", "beginning": "subordinates", "ate": "operator_verbs", "join": "operator_verbs", "tree": "noun", "rocks": "noun_p", "apples": "noun_p", "were": "noise", "more": "comparison_adj", "left": "subordinates"}, "unknown": {"('bake', 'VB', None)": null, "('4', 'LS', None)": null, "('fish', 'JJ', None)": null, "('more', 'RBR', None)": null}, "determiners": {"a": "constant", "away": "noise", "were": "noise", "some": "variable", "only": "noise", "another": "noise", "half": "variable", "the": "noise"}, "relative": {"younger": "rel_less", "fewer": "rel_less", "more": "rel_more"}, "answer_syntax": {"how old": "expression_connotation", "How many": "expression", "how many": "expression"}, "plurality": {"skeleton": "singular", "Jim": "singular", "years": "plural", "Lupis": "singular", "bananas": "plural", "Dad": "singular", "jars": "plural", "balloons": "plural", "dolls": "plural", "them": "plural", "Pigpen": "singular", "Michael": "singular", "Mrs.": "singular", "they": "plural", "him": "singular", "Spooky": "singular", "rocks": "plural", "Troy": "singular", "she": "singular", "Mitch": "singular", "Marc": "singular", "fish": "regular", "feathers": "plural", "are": null, "ornaments": "plural", "Jane": "singular", "collects": null, "skulls": "plural", "Hellen": "singular", "Lee": "singular", "mitch": null, "cobs": "plural", "William": "singular", "Charlie": "singular", "christmas": "singular", "cars": "plural", "corn": "singular", "Meathead": "singular", "beginning": null, "Mickey": "singular", "sister": "singular", "ate": null, "newspapers": "plural", "Ethelle": "singular", "Eric": "singular", "family": "plural", "doughnuts": "plural", "Tom": "singular", "toy": "singular", "her": "singular", "friend": "singular", "himself": "singular", "marbles": "plural", "boys": "plural", "Skellington": "singular", "he": "singular", "join": null, "Bennett": "singular", "tree": "singular", "apples": "plural", "Tony": "singular", "Richard": "singular", "Sara": "singular", "pieces": "singular", "Mr.": "singular", "his": "singular", "muffins": "plural", "pond": "singular", "Chandler": "singular", "dozen": null, "pink": "singular", "bottles": "plural", "Ragdoll": "singular", "Mac": "singular", "Jack": "singular", "pizza": "singular", "Jones": "singular", "Alex": "singular", "eggs": "plural", "Lucy": "singular", "Lisa": "singular", "friends": "plural", "Joey": "singular", "Archie": "singular", "Julia": "singular", "mother": "singular"}, "tag_units": {"age": ["years"]}, "gender": {"Jones": "ambiguous", "Archie": "masculine", "bananas": "neutral", "family": "mixed", "Marc": "masculine", "fish": "mixed", "Jim": "masculine", "doughnuts": "neutral", "pieces": "neutral", "Mr.": "masculine", "himself": "masculine", "Lupis": "ambiguous", "pond": "neutral", "Jane": "feminine", "muffins": "neutral", "skulls": "neutral", "Chandler": "masculine", "Hellen": "feminine", "skeleton": "neutral", "pink": "neutral", "he": "masculine", "toy": "neutral", "bottles": "neutral", "Richard": "masculine", "her": "feminine", "cobs": "neutral", "Troy": "masculine", "Ragdoll": "feminine", "William": "masculine", "Mac": "masculine", "Jack": "masculine", "Charlie": "masculine", "Tony": "masculine", "jars": "neutral", "Joey": "masculine", "balloons": "neutral", "eggs": "neutral", "Mitch": "masculine", "dolls": "neutral", "Tom": "masculine", "Dad": "masculine", "them": "mixed", "his": "masculine", "Alex": "masculine", "marbles": "neutral", "Sara": "feminine", "cars": "neutral", "corn": "neutral", "Meathead": "masculine", "Michael": "masculine", "Lucy": "feminine", "Mrs.": "feminine", "boys": "masculine", "they": "mixed", "Skellington": "ambiguous", "Lisa": "feminine", "years": "neutral", "friends": "mixed", "him": "masculine", "Lee": "masculine", "Mickey": "masculine", "christmas": "neutral", "Pigpen": "masculine", "she": "feminine", "Spooky": "ambiguous", "newspapers": "neutral", "Bennett": "masculine", "tree": "neutral", "Julia": "feminine", "rocks": "neutral", "feathers": "neutral", "ornaments": "neutral", "friend": "ambiguous", "mother": "feminine", "Ethelle": "feminine", "sister": "feminine", "pizza": "neutral", "Eric": "masculine", "apples": "neutral"}, "gerunds": {"remaining": "solution_zero", "swimming": "acting"}, "tag_list": ["age"], "exestential": {"there": "noise"}}
2 changes: 1 addition & 1 deletion run_example.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
clear
echo "" > EXAMPLE.md
MAX_IDX=19
MAX_IDX=20

for i in $(seq 1 $MAX_IDX); do
cat calibrations/$i.txt | zoidberg | tee -a EXAMPLE.md
Expand Down
15 changes: 13 additions & 2 deletions zoidberg/answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"unknown": "unknown to me",
"expression": "value",
"unit": "unit",
"context": "owner"
"context": "owner",
"expression_connotation": "value"
}

ANSWER_SUBORDINATE = {
Expand All @@ -40,6 +41,7 @@ def __init__(self, query):
self.rel_mode = None
self.comparator = None
self.subordinates = []
self.operator = None

self.relative_value = False
self.value = None
Expand All @@ -54,6 +56,8 @@ def __init__(self, query):
self.actor_subtype = None
self.action = None

self.connotation_tag = None

self.execute()

def execute(self):
Expand All @@ -76,6 +80,10 @@ def execute(self):
if part == "asking":
self.syntax = p.brain.answer_syntax(val, str(self.query))
asking = True
if self.syntax == "expression_connotation":
tag = p.brain.connotation(val, str(self.query))
self.connotation_tag = tag
self.unit = p.brain.connotation_unit(tag, p.units)

if part == "rel_less":
if asking:
Expand Down Expand Up @@ -200,8 +208,11 @@ def __str__(self):
if self.context:
if self.query.problem.inference.is_requirement_problem:
i.append("needed by {0}".format(self.context))
else:
elif self.operator is not None:
i.append("{1} {0}".format(self.context, OPERATOR_STR[self.operator]))
else:
# Assume equals failing all else?
i.append("{1} {0}".format(self.context, OPERATOR_STR["eq"]))

if self.relative:
if self.comparator is not None:
Expand Down
71 changes: 67 additions & 4 deletions zoidberg/brain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
from os.path import isfile, realpath, expanduser
from utilities import get_json, set_json
from utilities import get_json, set_json, uniq
import sys
import json

Expand All @@ -19,7 +19,10 @@
"relative": {},
"gerunds": {},
"numbers": {},
"variables": {}
"variables": {},
"connotation_tags": {},
"tag_list": [],
"tag_units": {}
}

# Various mathematical operators we know of
Expand Down Expand Up @@ -77,7 +80,8 @@
ANSWERS = [
("expression", "Answer is the solution to an expression (4 cars)"),
("unit", "Answer is the unit of the solution to an expression (cars)"),
("context", "Answer is the owner of the solution to an expression (Joe)")
("context", "Answer is the owner of the solution to an expression (Joe)"),
("expression_connotation", "Answer is the solution to an expression AND connotes the unit (how old = X years)")
]

PLURALITY = [
Expand Down Expand Up @@ -118,8 +122,32 @@
]

INPUT_STR = "What {0} does {1}'{2}' indicate in the sentence: '{3}'"
TAG_STR = "What tag does {0}'{1}' connote?"

def get_input(data, prompt, x, ref, brain, force_retag=False):
def get_tag(x, brain):
msg = "\t{0}. {1}"
sys.stdin = open('/dev/tty')
if not "tag_list" in brain.raw:
brain.raw["tag_list"] = []
data = brain.raw["tag_list"]

i = 0
print "\t0. Enter a new tag."
for k in data:
i += 1
print msg.format(i, k[1])

r = int(raw_input("The tag: "))

if r == 0:
t = raw_input("Please enter tag: ")
data.append(t)

if r < 0 or r > len(data):
return get_tag(x, brain)
return data[r - 1]

def get_input(data, prompt, x, ref, brain, force_retag=False, for_tag=False):
msg = "\t{0}. {1}"
sys.stdin = open('/dev/tty')

Expand Down Expand Up @@ -217,6 +245,10 @@ def input_answer_syntax(x, ref, brain):
print INPUT_STR.format("question", "", x, ref)
return get_input(ANSWERS, "'{0}' indicates: ".format(x), x, ref, brain)

def input_connotation_tag(x, ref, brain):
print TAG_STR.format("", x)
return get_tag(x, brain)

def input_plurality(p, ref, brain):
x, tag = p

Expand Down Expand Up @@ -385,6 +417,37 @@ def comparison(self, comp, ref):
def answer_syntax(self, query, ref):
return self.proc("answer_syntax", query, input_answer_syntax, ref)

def connotation(self, query, ref):
return self.proc("connotation_tags", query, input_connotation_tag, ref)

def connotation_unit(self, tag, units):
possible_units = []
connoted_unit = None
if "tag_units" not in self.raw:
self.raw["tag_units"] = {}
if not tag in self.raw["tag_units"]:
self.raw["tag_units"][tag] = []
unit_tag_list = self.raw["tag_units"][tag]

if len(units) == 1:
# Make an assumption that this tag and unit are related
connoted_unit = units[0]
if not connoted_unit in unit_tag_list:
# Track this assumption for later
unit_tag_list.append(connoted_unit)
else:
raise Exception("I don't know how to handle this; could need multiple tags")
possible_units = unit_tag_list

if len(possible_units) > 0 and connoted_unit is None:
relevant_units = list(set(possible_units).intersection(set(units)))
if len(relevant_units) == 1:
connoted_unit = relevant_units[0]
else:
raise Exception("I don't know how to handle this! Help me!")

return connoted_unit

def noun_like(self, n, tag, ref):
if tag in ["NNP", "NNPS"]:
n = n.capitalize()
Expand Down
5 changes: 3 additions & 2 deletions zoidberg/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self, text, brain_path=None, file_name=None):
self.units_acting_as_context = {}
self.descriptive_units = []
self.refined_units = {}
self.units = []

self.exestential = False
self.adaptive_context = {}
Expand Down Expand Up @@ -71,7 +72,7 @@ def __init__(self, text, brain_path=None, file_name=None):
"feminine": {},
"neutral": {},
"mixed": {},
"ambiguous": None
"ambiguous": {}
},
"last": None
}
Expand All @@ -86,7 +87,7 @@ def __init__(self, text, brain_path=None, file_name=None):
"feminine": {},
"neutral": {},
"mixed": {},
"ambiguous": None
"ambiguous": {}
},
"last": None
}
Expand Down
2 changes: 2 additions & 0 deletions zoidberg/sentence_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,8 @@ def do_track(subtype, tag):
if c:
self.problem.subordinate_adaptive_contexts.append(c[0])
self.subordinates = uniq(self.subordinates)
self.problem.units += self.units
self.problem.units = uniq(self.problem.units)

def __str__(self):
return self.sentence_text
Expand Down

0 comments on commit 97065a1

Please sign in to comment.