def setUp(self): dom = set(['b1', 'c1']) self.vals = [] for z in chain.from_iterable(combinations(dom, r) for r in range(len(dom)+1)): self.vals.append(extrasem.Valuation([('sleep', set(z))])) self.g1 = extrasem.Assignment(values=['b1', 'c1']) self.r1 = extrasem.ReferentSystem(variables=['x', 'y']) self.possibilities = [[self.r1, self.g1, x] for x in self.vals] self.info = extrasem.InformationState(dom, self.possibilities) self.inq = extrasem.DynamicInquisitiveState([self.info]) self.possibilities2 = [[self.r1, self.g1, x] for x in self.vals] self.info2 = extrasem.InformationState(dom, self.possibilities) self.inq2 = extrasem.DynamicInquisitiveState([self.info2]) self.g2 = extrasem.Assignment(values=['b1', 'c1', 'b1']) self.r2 = extrasem.ReferentSystem(variables=['x', 'y', 'z']) self.w = extrasem.Valuation([('sleep', set(['b1']))]) self.small_possibilities = [[self.r2, self.g2, x] for x in self.vals] self.info4 = extrasem.InformationState(dom, self.small_possibilities) self.info5 = extrasem.InformationState(dom, [[self.r2, self.g2, self.w]]) self.inq4 = extrasem.DynamicInquisitiveState([self.info4]) self.inq5 = extrasem.DynamicInquisitiveState([self.info5])
def test_values(self): extended_inq = self.inq.evaluate("exists z. (-sleep(z))") g_extra1 = extrasem.Assignment(values=['b1', 'c1', 'b1']) r2 = extrasem.ReferentSystem(variables=['x', 'y', 'z']) info1 = extrasem.InformationState(self.dom, [[r2, g_extra1, extrasem.Valuation([('sleep', set(['c1'])), ('john', 'b1'), ('mary', 'c1')])], [r2, g_extra1, extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')])]]) g_extra2 = extrasem.Assignment(values=['b1', 'c1', 'c1']) info2 = extrasem.InformationState(self.dom, [[r2, g_extra2, extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])], [r2, g_extra2, extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')])]]) info3 = extrasem.InformationState(self.dom, [[r2, g_extra1, extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')])], [r2, g_extra2, extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')])]]) self.assertEqual(extended_inq, extrasem.DynamicInquisitiveState([info1, info2, info3]) ) extended_inq = self.inq.evaluate("-(exists z. sleep(z))") self.assertEqual(extended_inq, extrasem.DynamicInquisitiveState([extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')])]])]) ) extended_inq = self.inq.evaluate("sleep(mary) | sleep(john)") self.assertEqual(extended_inq, extrasem.DynamicInquisitiveState([extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])]]), extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('sleep', set(['c1'])), ('john', 'b1'), ('mary', 'c1')])], [self.r1, self.g1, extrasem.Valuation([('sleep', set(['c1', 'b1'])), ('john', 'b1'), ('mary', 'c1')])]])])) extended_inq = self.inq.evaluate("(exists z. sleep(z)) | (exists w. (sleep(w)))") extended_inq = self.inq.evaluate("sleep(mary) -> sleep(john)") self.assertEqual(extended_inq, extrasem.DynamicInquisitiveState([extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])], [self.r1, self.g1, extrasem.Valuation([('sleep', set(['c1', 'b1'])), ('john', 'b1'), ('mary', 'c1')])], [self.r1, self.g1, extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')])]])])) extended_inq = self.inq.evaluate("all z. sleep(z)") self.assertEqual(extended_inq, extrasem.DynamicInquisitiveState([extrasem.InformationState(self.dom, [[r2, g_extra1, extrasem.Valuation([('sleep', set(['c1', 'b1'])), ('john', 'b1'), ('mary', 'c1')])], [r2, g_extra2, extrasem.Valuation([('sleep', set(['c1', 'b1'])), ('john', 'b1'), ('mary', 'c1')])]])])) extended_inq = self.inq.evaluate("-(all z. sleep(z))") self.assertEqual(extended_inq, extrasem.DynamicInquisitiveState([extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])], [self.r1, self.g1, extrasem.Valuation([('sleep', set(['c1'])), ('john', 'b1'), ('mary', 'c1')])], [self.r1, self.g1, extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')])]])])) extended_inq = self.inq.evaluate("all z. -(sleep(z))") self.assertEqual(extended_inq, extrasem.DynamicInquisitiveState([extrasem.InformationState(self.dom, [[r2, g_extra1, extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')])], [r2, g_extra2, extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')])]])])) extended_inq = self.inq.evaluate("!sleep(x)") self.assertEqual(extended_inq, self.inq.evaluate("sleep(x)")) extended_inq = self.inq.evaluate("!(sleep(x) | sleep(y))") self.assertEqual(extended_inq, extrasem.DynamicInquisitiveState([extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])], [self.r1, self.g1, extrasem.Valuation([('sleep', set(['c1'])), ('john', 'b1'), ('mary', 'c1')])], [self.r1, self.g1, extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')])]])])) extended_inq = self.inq.evaluate("?sleep(x)") self.assertEqual(extended_inq, self.inq.evaluate("sleep(x) | -sleep(x)"))
def setUp(self): dom = set(['b1', 'c1']) vals = [] for z in chain.from_iterable(combinations(dom, r) for r in range(len(dom)+1)): vals.append(extrasem.Valuation([('sleep', set(z))])) vals2 = vals[0:2] g1 = extrasem.Assignment(values=['b1', 'c1']) g2 = extrasem.Assignment(values=['b1']) r1 = extrasem.ReferentSystem(variables=['x', 'y']) r2 = extrasem.ReferentSystem(variables=['x', 'z']) self.info = extrasem.InformationState(dom, [[r1, g1, x] for x in vals]) self.info2 = extrasem.InformationState(dom, [[r1, g1, x] for x in vals]) self.info3 = extrasem.InformationState(dom, [[r1, g1, x] for x in vals2]) possibilities = [[r1, g1, x] for x in vals[:-1]] + [[r1, g2, vals[-1]]] self.info4 = extrasem.InformationState(dom, possibilities)
def setUp(self): dom = set(['b1', 'c1']) self.vals = [] for z in chain.from_iterable(combinations(dom, r) for r in range(len(dom)+1)): self.vals.append(extrasem.Valuation([('sleep', set(z))])) self.w = extrasem.Valuation([('dance', set(['b1']))]) self.g1 = extrasem.Assignment(values=['b1', 'c1']) self.g2 = extrasem.Assignment(values=['b1']) self.r1 = extrasem.ReferentSystem(variables=['x', 'y']) self.possibilities = [[self.r1, self.g1, x] for x in self.vals] self.info = extrasem.InformationState(dom, self.possibilities)
def setUp(self): self.dom = set(['b1', 'c1']) self.vals = [] for z in chain.from_iterable(combinations(self.dom, r) for r in range(len(self.dom)+1)): self.vals.append(extrasem.Valuation([('sleep', set(z))])) for x in self.vals: x['john'] = 'b1' x['mary'] = 'c1' self.inq = extrasem.InquisitiveState(self.dom, [self.vals]) self.g1 = nltk.Assignment(self.dom, [('x', 'b1'), ('y', 'c1')])
def setUp(self): dom = set(['b1', 'c1']) vals = [] for z in chain.from_iterable(combinations(dom, r) for r in range(len(dom)+1)): vals.append(extrasem.Valuation([('sleep', set(z))])) vals2 = vals[0:2] self.g1 = extrasem.Assignment(values=['b1', 'c1']) self.r1 = extrasem.ReferentSystem(variables=['x', 'y'])
def test_values(self): new_inqstate = self.inq.evaluate("sleep (mary)") tested1 = extrasem.DynamicInquisitiveState([extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('b1'), ('c1')])) ])], [self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('c1')])) ])]])]) self.assertEqual(tested1, new_inqstate) new_inqstate = self.inq.evaluate("sleep (mary) & sleep(john)") tested2 = extrasem.DynamicInquisitiveState([extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('b1'), ('c1')])) ])] ])]) self.assertEqual(tested2, new_inqstate) extended_inq = self.inq.evaluate("exists z. (!(sleep(z) | -sleep(z)))") self.assertEqual(extrasem.DynamicInquisitiveState([self.info]), self.inq) g_extra1 = extrasem.Assignment(values=['b1', 'c1', 'b1']) r2 = extrasem.ReferentSystem(variables=['x', 'y', 'z']) part1 = [[r2, g_extra1, x] for x in self.vals] g_extra2 = extrasem.Assignment(values=['b1', 'c1', 'c1']) part2 = [[r2, g_extra2, x] for x in self.vals] info1 = extrasem.InformationState(self.dom, part1 + part2) self.assertEqual(extended_inq.find_maximal().pop(), info1) extended_inq2 = extended_inq.evaluate("sleep(z)") info1 = extrasem.InformationState(self.dom, [[r2, g_extra1, extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])], [r2, g_extra1, extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')])]]) info2 = extrasem.InformationState(self.dom, [[r2, g_extra2, extrasem.Valuation([('sleep', set(['c1'])), ('john', 'b1'), ('mary', 'c1')])], [r2, g_extra2, extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')])]]) info3 = extrasem.InformationState(self.dom, [[r2, g_extra1, extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')])], [r2, g_extra2, extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')])]]) self.assertEqual(extended_inq2, extrasem.DynamicInquisitiveState([info1, info2, info3]))
def test_values(self): new_infostate = self.info.evaluate("sleep (mary)") tested1 = extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('b1'), ('c1')])) ])], [self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('c1')])) ])]]) self.assertEqual(tested1, new_infostate) new_infostate = self.info.evaluate("-sleep (john)") tested1 = extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('c1')])) ])], [self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set()) ])]]) self.assertEqual(tested1, new_infostate) new_infostate = self.info.evaluate("sleep (mary) & sleep(john)") tested2 = extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('b1'), ('c1')])) ])] ]) self.assertEqual(tested2, new_infostate) extended_info = self.info.evaluate("exists z. (sleep(z) | -sleep(z)) ") #empty(x) is a dummy prop, always satisfied g_extra1 = extrasem.Assignment(values=['b1', 'c1', 'b1']) g_extra2 = extrasem.Assignment(values=['b1', 'c1', 'c1']) r2 = extrasem.ReferentSystem(variables=['x', 'y', 'z']) info1 = extrasem.InformationState(self.dom, [[r2, g_extra1, x] for x in self.vals] +\ [[r2, g_extra2, x] for x in self.vals]) self.assertEqual(extended_info, info1) extended_info = self.info.evaluate("sleep(mary) -> sleep(john)") tested3 = extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('b1'), ('c1')])) ])], [self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('b1')])) ])], [self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set()) ])] ]) self.assertEqual(extended_info, tested3) extended_info = self.info.evaluate("all z. sleep(z)") tested4 = extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('b1'), ('c1')])) ])] ]) self.assertEqual(extended_info, tested4) extended_info = self.info.evaluate("-(all z. sleep(z))") tested5 = extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set()) ])], [self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('b1')])) ])], [self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set([('c1')])) ])]]) self.assertEqual(tested5, extended_info) extended_info = self.info.evaluate("all z. -(sleep(z))") tested6 = extrasem.InformationState(self.dom, [[self.r1, self.g1, extrasem.Valuation([('john', 'b1'), ('mary', 'c1'), ('sleep', set()) ])] ]) self.assertEqual(extended_info, tested6)
def setUp(self): self.dom = set(['b1', 'c1']) self.vals = [] for z in chain.from_iterable(combinations(self.dom, r) for r in range(len(self.dom)+1)): self.vals.append(extrasem.Valuation([('sleep', set(z))])) for x in self.vals: x['john'] = 'b1' x['mary'] = 'c1' self.g1 = extrasem.Assignment(values=['b1', 'c1']) self.r1 = extrasem.ReferentSystem(variables=['x', 'y']) self.possibilities = [[self.r1, self.g1, x] for x in self.vals] self.info = extrasem.InformationState(self.dom, self.possibilities) self.inq = extrasem.DynamicInquisitiveState([self.info])
def test_values(self): new_inqstate = self.inq.evaluate("sleep (mary)", self.g1) compared = extrasem.InquisitiveState(self.dom, [[extrasem.Valuation([('sleep', set(['c1'])), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set(['c1', 'b1'])), ('john', 'b1'), ('mary', 'c1')])]] ) self.assertEqual(new_inqstate, compared) new_inqstate = self.inq.evaluate("sleep (mary) & sleep (john)", self.g1) compared = extrasem.InquisitiveState(self.dom, [[extrasem.Valuation([('sleep', set(['c1', 'b1'])), ('john', 'b1'), ('mary', 'c1')])]] ) self.assertEqual(new_inqstate, compared) new_inqstate = self.inq.evaluate("- sleep (mary) ", self.g1) compared = extrasem.InquisitiveState(self.dom, [[extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])]] ) self.assertEqual(new_inqstate, compared) new_inqstate = self.inq.evaluate("exists z( sleep (z)) ", self.g1) compared = extrasem.InquisitiveState(self.dom, [[extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])], [extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set(['c1'])), ('john', 'b1'), ('mary', 'c1')])]] ) self.assertEqual(new_inqstate, compared) new_inqstate = self.inq.evaluate("sleep (mary) | sleep (john) ", self.g1) compared = extrasem.InquisitiveState(self.dom, [[extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])], [extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set(['c1'])), ('john', 'b1'), ('mary', 'c1')])]] ) self.assertEqual(new_inqstate, compared) new_inqstate = self.inq.evaluate("sleep (mary) -> sleep (john) ", self.g1) compared = extrasem.InquisitiveState(self.dom, [ [extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])]] ) self.assertEqual(new_inqstate, compared) new_inqstate = self.inq.evaluate("all x( sleep (x)) ", self.g1) compared = extrasem.InquisitiveState(self.dom, [[extrasem.Valuation([('sleep', set(['b1', 'c1'])), ('john', 'b1'), ('mary', 'c1')])]] ) self.assertEqual(new_inqstate, compared) new_inqstate = self.inq.evaluate("? sleep (mary) ", self.g1) compared = extrasem.InquisitiveState(self.dom, [[extrasem.Valuation([('sleep', set()), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set(['b1'])), ('john', 'b1'), ('mary', 'c1')])], [extrasem.Valuation([('sleep', set(['c1', 'b1'])), ('john', 'b1'), ('mary', 'c1')]), extrasem.Valuation([('sleep', set(['c1'])), ('john', 'b1'), ('mary', 'c1')])]] ) self.assertEqual(new_inqstate, compared) new_inqstate = self.inq.evaluate("!(? sleep (mary)) ", self.g1) self.assertEqual(new_inqstate, self.inq) self.assertEqual(self.inq, self.inq.copy())
""" An example of how to build IDPL. This uses sets of information states, i.e., it is built on top of CorMod (DPL). """ from itertools import chain, combinations import extrasemantics as sem #We will assume the domain of 2 individuals: dom = set(['b1', 'c1']) vals = [] vals.append(sem.Valuation([('see', set([('b1', 'c1')])), ('like', set([('b1', 'c1'), ('c1', 'c1')]))])) #vals.append(sem.Valuation([('see', set([('b1', 'c1')])), ('like', set())])) vals.append(sem.Valuation([('see', set([('b1', 'c1'), ('c1', 'c1')])), ('like', set([('b1', 'c1'), ('c1', 'c1')])) ])) #vals.append(sem.Valuation([('see', set([('b1', 'c1'), ('c1', 'c1')])), ('like', set())])) #furthermore, we add naming functions, so we can refer to b1 and c1 #for x in vals: # x['john'] = 'b1' # x['mary'] = 'c1' #now we create an assignment function g1 = sem.Assignment(values=['b1', 'c1']) #and we create referent system r1 = sem.ReferentSystem(variables=['x', 'y'])
#We will assume the domain of 2 individuals: dom = set(['b1', 'c1', 'd1', 'e1']) vals = [] temp_dom = set(['b1', 'c1']) temp_dom2 = set(['d1', 'e1']) for z in chain.from_iterable(combinations(temp_dom, r) for r in range(len(temp_dom)+1)): like_set = set([('b1', 'd1'), ('c1', 'd1')]) if not z: #vals.append(sem.Valuation([('sleep', set()), ('dreamAbout', set()), ('like', like_set), ('dance', temp_dom) ])) continue for y in temp_dom2: temp_set = set() for x in z: temp_set.add((x, y)) vals.append(sem.Valuation([('sleep', set(z)), ('dreamAbout', temp_set), ('like', like_set) ])) #furthermore, we add naming functions, so we can refer to b1 and c1 for x in vals: x['john'] = 'b1' x['mary'] = 'c1' x['dog'] = 'd1' x['elephant'] = 'e1' #now we create an assignment function g1 = sem.Assignment(values=['b1', 'c1']) #and we create referent system r1 = sem.ReferentSystem(variables=['x', 'y']) #all possibilities are put together as triples with identical g1 and r1, but varying worlds
""" import nltk from itertools import chain, combinations import extrasemantics as sem #We will assume the domain of 2 individuals: dom = set(['b1', 'c1']) #adding another predicate: vals = [] for z in chain.from_iterable( combinations(dom, r) for r in range(len(dom) + 1)): vals.append( sem.Valuation([('sleep', set(z)), ('dance', dom.difference(set(z)))])) #furthermore, we add naming functions, so we can refer to b1 and c1 for x in vals: x['john'] = 'b1' x['mary'] = 'c1' #now we create an assignment function g1 = nltk.Assignment(dom, []) inq = sem.InquisitiveState(dom, [vals]) #some examples exp_list = [] exp_list.append("mary = john") exp_list.append("sleep (mary) & dance (john)")
""" from itertools import chain, combinations import extrasemantics as sem #We will assume the domain of 2 individuals: dom = set(['b1', 'c1']) vals = [] temp_dom = set(['b1', 'c1']) for z in chain.from_iterable(combinations(temp_dom, r) for r in range(len(temp_dom)+1)): like_set = set([('b1', 'c1'), ('c1', 'b1')]) if not z: continue vals.append(sem.Valuation([('sleep', set(z)), ('dance', temp_dom.difference(set(z))), ('like', like_set) ])) vals[-1].update({'like': set([('b1', 'c1'), ('b1', 'b1'), ('c1', 'c1'),('c1', 'b1')])}) #furthermore, we add naming functions, so we can refer to b1 and c1 for x in vals: x['john'] = 'b1' x['mary'] = 'c1' #now we create an assignment function g1 = sem.Assignment(values=['b1', 'c1']) #and we create referent system r1 = sem.ReferentSystem(variables=['x', 'y']) #all possibilities are put together as triples with identical g1 and r1, but varying worlds possibilities = [[r1, g1, x] for x in vals]