nltk.Assignment¶
-
class
nltk.Assignment(domain, assign=None)[source]¶ 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
IndividualVariableExpressionin thelogicmodule. If a variable is not assigned a value by g, it will raise anUndefinedexception.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 theAssignmentconstructor, 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
printformat 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
addmethod:>>> dom = set(['u1', 'u2', 'u3', 'u4']) >>> g4 = Assignment(dom) >>> g4.add('x', 'u1') {'x': 'u1'}
With no arguments,
purge()is equivalent toclear()on a dictionary:>>> g4.purge() >>> g4 {}
Parameters: - domain (set) – the domain of discourse
- assign (list) – a list of (varname, value) associations
Methods¶
__init__(domain[, assign]) |
|
add(var, val) |
Add a new variable-value pair to the assignment, and update self.variant. |
clear(() -> None. Remove all items from D.) |
|
copy() |
|
fromkeys(...) |
v defaults to None. |
get((k[,d]) -> D[k] if k in D, ...) |
|
has_key((k) -> True if D has a key k, else False) |
|
items(() -> list of D’s (key, value) pairs, ...) |
|
iteritems(() -> an iterator over the (key, ...) |
|
iterkeys(() -> an iterator over the keys of D) |
|
itervalues(...) |
|
keys(() -> list of D’s keys) |
|
pop((k[,d]) -> v, ...) |
If key is not found, d is returned if given, otherwise KeyError is raised |
popitem(() -> (k, v), ...) |
2-tuple; but raise KeyError if D is empty. |
purge([var]) |
Remove one or all keys (i.e. |
setdefault((k[,d]) -> D.get(k,d), ...) |
|
update(([E, ...) |
If E present and has a .keys() method, does: for k in E: D[k] = E[k] |
values(() -> list of D’s values) |
|
viewitems(...) |
|
viewkeys(...) |
|
viewvalues(...) |
Attributes¶
unicode_repr() <==> repr(x) |