A dictionary which represents an assignment of values to variables.
An assigment can only assign values from its domain.
If an unknown expression a is passed to a model M's interpretation function i, i will first check whether M's valuation assigns an interpretation to a as a constant, and if this fails, i will delegate the interpretation of a to g. g only assigns values to individual variables (i.e., members of the class IndividualVariableExpression in the logic module. If a variable is not assigned a value by g, it will raise an Undefined exception.
A variable Assignment is a mapping from individual variables to entities in the domain. Individual variables are usually indicated with the letters 'x', 'y', 'w' and 'z', optionally followed by an integer (e.g., 'x0', 'y332'). Assignments are created using the Assignment constructor, which also takes the domain as a parameter.
>>> from nltk.sem.evaluate import Assignment >>> dom = set(['u1', 'u2', 'u3', 'u4']) >>> g3 = Assignment(dom, [('x', 'u1'), ('y', 'u2')]) >>> g3 == {'x': 'u1', 'y': 'u2'} True
There is also a print format for assignments which uses a notation closer to that in logic textbooks:
>>> print(g3) g[u1/x][u2/y]
It is also possible to update an assignment using the add method:
>>> dom = set(['u1', 'u2', 'u3', 'u4']) >>> g4 = Assignment(dom) >>> g4.add('x', 'u1') {'x': 'u1'}
With no arguments, purge() is equivalent to clear() on a dictionary:
>>> g4.purge() >>> g4 {}
Parameters | |
domain | the domain of discourse |
assign | a list of (varname, value) associations |
Method | __getitem__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __str__ |
Pretty printing for assignments. {'x', 'u'} appears as 'g[u/x]' |
Method | add |
Add a new variable-value pair to the assignment, and update self.variant. |
Method | copy |
Undocumented |
Method | purge |
Remove one or all keys (i.e. logic variables) from an assignment, and update self.variant. |
Instance Variable | domain |
Undocumented |
Instance Variable | variant |
Undocumented |
Method | _addvariant |
Create a more pretty-printable version of the assignment. |