def demo_model0(): global m0, g0 #Initialize a valuation of non-logical constants.""" v = [('john', 'b1'), ('mary', 'g1'), ('suzie', 'g2'), ('fido', 'd1'), ('tess', 'd2'), ('noosa', 'n'), ('girl', set(['g1', 'g2'])), ('boy', set(['b1', 'b2'])), ('dog', set(['d1', 'd2'])), ('bark', set(['d1', 'd2'])), ('walk', set(['b1', 'g2', 'd1'])), ('chase', set([('b1', 'g1'), ('b2', 'g1'), ('g1', 'd1'), ('g2', 'd2')])), ('see', set([('b1', 'g1'), ('b2', 'd2'), ('g1', 'b1'),('d2', 'b1'), ('g2', 'n')])), ('in', set([('b1', 'n'), ('b2', 'n'), ('d2', 'n')])), ('with', set([('b1', 'g1'), ('g1', 'b1'), ('d1', 'b1'), ('b1', 'd1')])) ] #Read in the data from ``v`` val = evaluate.Valuation(v) #Bind ``dom`` to the ``domain`` property of ``val`` dom = val.domain #Initialize a model with parameters ``dom`` and ``val``. m0 = evaluate.Model(dom, val) #Initialize a variable assignment with parameter ``dom`` g0 = evaluate.Assignment(dom)
def demo_model0(): global m0, g0 val = evaluate.Valuation() #Initialize a valuation of non-logical constants.""" v = [('john', 'b1'), ('mary', 'g1'), ('suzie', 'g2'), ('fido', 'd1'), ('tess', 'd2'), ('noosa', 'n'), ('girl', set(['g1', 'g2'])), ('boy', set(['b1', 'b2'])), ('dog', set(['d1', 'd2'])), ('bark', set(['d1', 'd2'])), ('walk', set(['b1', 'g2', 'd1'])), ('chase', set([('b1', 'g1'), ('b2', 'g1'), ('g1', 'd1'), ('g2', 'd2')])), ('see', set([('b1', 'g1'), ('b2', 'd2'), ('g1', 'b1'),('d2', 'b1'), ('g2', 'n')])), ('in', set([('b1', 'n'), ('b2', 'n'), ('d2', 'n')])), ('with', set([('b1', 'g1'), ('g1', 'b1'), ('d1', 'b1'), ('b1', 'd1')])) ] #Read in the data from C{v} val.read(v) #Bind C{dom} to the C{domain} property of C{val} dom = val.domain #Initialize a model with parameters C{dom} and C{val}. m0 = evaluate.Model(dom, val) #Initialize a variable assignment with parameter C{dom} g0 = evaluate.Assignment(dom)
def parse_valuation(s): """ Convert a valuation file into a valuation. :param s: the contents of a valuation file :type s: str :return: a ``nltk.sem`` valuation :rtype: Valuation """ statements = [] for linenum, line in enumerate(s.splitlines()): line = line.strip() if line.startswith('#') or line=='': continue try: statements.append(parse_valuation_line(line)) except ValueError: raise ValueError('Unable to parse line %s: %s' % (linenum, line)) val = evaluate.Valuation(statements) return val
def parse_valuation(s): """ Convert a valuation file into a valuation. @parameter s: the contents of a valuation file @type s: C{str} @return: a L{nltk.sem} valuation @rtype: L{Valuation} """ statements = [] for linenum, line in enumerate(s.splitlines()): line = line.strip() if line.startswith('#') or line=='': continue try: statements.append(parse_valuation_line(line)) except ValueError: raise ValueError, 'Unable to parse line %s: %s' % (linenum, line) val = evaluate.Valuation(statements) return val