class Expression(SubstituteBindingsI): (source)
Known subclasses: nltk.sem.drt.DRS
, nltk.sem.drt.DrtProposition
, nltk.sem.drt.PossibleAntecedents
, nltk.sem.logic.AbstractVariableExpression
, nltk.sem.logic.ApplicationExpression
, nltk.sem.logic.BinaryExpression
, nltk.sem.logic.NegatedExpression
, nltk.sem.logic.VariableBinderExpression
This is the base abstract object for all logical expressions
Class Method | fromstring |
Undocumented |
Method | __and__ |
Undocumented |
Method | __call__ |
Undocumented |
Method | __eq__ |
Undocumented |
Method | __gt__ |
Undocumented |
Method | __hash__ |
Undocumented |
Method | __lt__ |
Undocumented |
Method | __ne__ |
Undocumented |
Method | __neg__ |
Undocumented |
Method | __or__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | applyto |
Undocumented |
Method | constants |
Return a set of individual constants (non-predicates). :return: set of Variable objects |
Method | equiv |
Check for logical equivalence. Pass the expression (self <-> other) to the theorem prover. If the prover says it is valid, then the self and other are equal. |
Method | findtype |
Find the type of the given variable as it is used in this expression. For example, finding the type of "P" in "P(x) & Q(x,y)" yields "<e,t>" |
Method | free |
Return a set of all the free (non-bound) variables. This includes both individual and predicate variables, but not constants. :return: set of Variable objects |
Method | make_ |
Undocumented |
Method | negate |
If this is a negated expression, remove the negation. Otherwise add a negation. |
Method | normalize |
Rename auto-generated unique variables |
Method | predicates |
Return a set of predicates (constants, not variables). :return: set of Variable objects |
Method | replace |
Replace every instance of 'variable' with 'expression' :param variable: Variable The variable to replace :param expression: Expression The expression with which to replace it :param replace_bound: bool Should bound variables be replaced... |
Method | simplify |
No summary |
Method | substitute |
No summary |
Method | typecheck |
Infer and check types. Raise exceptions if necessary. |
Method | variables |
Return a set of all the variables for binding substitution. The variables returned include all free (non-bound) individual variables and any variable starting with '?' or '@'. :return: set of Variable objects... |
Method | visit |
Recursively visit subexpressions. Apply 'function' to each subexpression and pass the result of each function application to the 'combinator' for aggregation: |
Method | visit |
Recursively visit subexpressions. Apply 'function' to each subexpression and pass the result of each function application to the 'combinator' for aggregation. The combinator must have the same signature as the constructor... |
Method | _set |
Set the type of this expression to be the given type. Raise type exceptions where applicable. |
Class Variable | _logic |
Undocumented |
Class Variable | _type |
Undocumented |
nltk.sem.drt.DRS
, nltk.sem.drt.DrtProposition
, nltk.sem.drt.PossibleAntecedents
, nltk.sem.logic.AbstractVariableExpression
, nltk.sem.logic.ApplicationExpression
, nltk.sem.logic.BinaryExpression
, nltk.sem.logic.LambdaExpression
, nltk.sem.logic.NegatedExpression
, nltk.sem.logic.QuantifiedExpression
Undocumented
nltk.sem.logic.ApplicationExpression
, nltk.sem.logic.ConstantExpression
, nltk.sem.logic.FunctionVariableExpression
, nltk.sem.logic.IndividualVariableExpression
Return a set of individual constants (non-predicates). :return: set of Variable objects
Check for logical equivalence. Pass the expression (self <-> other) to the theorem prover. If the prover says it is valid, then the self and other are equal.
Parameters | |
other | an Expression to check equality against |
prover | a nltk.inference.api.Prover |
nltk.sem.logic.AbstractVariableExpression
, nltk.sem.logic.ApplicationExpression
, nltk.sem.logic.BinaryExpression
, nltk.sem.logic.NegatedExpression
, nltk.sem.logic.VariableBinderExpression
Find the type of the given variable as it is used in this expression. For example, finding the type of "P" in "P(x) & Q(x,y)" yields "<e,t>"
Parameters | |
variable | Variable |
nltk.sem.drt.DRS
, nltk.sem.drt.PossibleAntecedents
, nltk.sem.logic.ConstantExpression
, nltk.sem.logic.FunctionVariableExpression
, nltk.sem.logic.IndividualVariableExpression
, nltk.sem.logic.VariableBinderExpression
Return a set of all the free (non-bound) variables. This includes both individual and predicate variables, but not constants. :return: set of Variable objects
nltk.sem.logic.NegatedExpression
If this is a negated expression, remove the negation. Otherwise add a negation.
nltk.sem.drt.DRS
, nltk.sem.drt.DrtConcatenation
, nltk.sem.drt.DrtConcatenation
, nltk.sem.drt.DrtProposition
, nltk.sem.drt.PossibleAntecedents
, nltk.sem.logic.AbstractVariableExpression
, nltk.sem.logic.VariableBinderExpression
Replace every instance of 'variable' with 'expression' :param variable: Variable The variable to replace :param expression: Expression The expression with which to replace it :param replace_bound: bool Should bound variables be replaced? :param alpha_convert: bool Alpha convert automatically to avoid name clashes?
nltk.sem.drt.DrtConcatenation
, nltk.sem.drt.DrtConcatenation
, nltk.sem.logic.AbstractVariableExpression
, nltk.sem.logic.ApplicationExpression
Returns | |
beta-converted version of this expression |
Returns | |
(any) | The object that is obtained by replacing each variable bound by bindings with its values. Aliases are already resolved. (maybe?) |
Infer and check types. Raise exceptions if necessary.
Parameters | |
signature | dict that maps variable names to types (or string representations of types) |
Returns | |
the signature, plus any additional type mappings |
Return a set of all the variables for binding substitution. The variables returned include all free (non-bound) individual variables and any variable starting with '?' or '@'. :return: set of Variable objects
nltk.sem.drt.DRS
, nltk.sem.drt.DrtProposition
, nltk.sem.logic.ApplicationExpression
, nltk.sem.logic.BinaryExpression
, nltk.sem.logic.NegatedExpression
, nltk.sem.logic.VariableBinderExpression
Recursively visit subexpressions. Apply 'function' to each subexpression and pass the result of each function application to the 'combinator' for aggregation:
return combinator(map(function, self.subexpressions))
Bound variables are neither applied upon by the function nor given to the combinator. :param function: Function<Expression,T> to call on each subexpression :param combinator: Function<list<T>,R> to combine the results of the function calls :return: result of combination R
nltk.sem.drt.DRS
, nltk.sem.drt.DrtProposition
, nltk.sem.logic.VariableBinderExpression
Recursively visit subexpressions. Apply 'function' to each subexpression and pass the result of each function application to the 'combinator' for aggregation. The combinator must have the same signature as the constructor. The function is not applied to bound variables, but they are passed to the combinator. :param function: Function to call on each subexpression :param combinator: Function with the same signature as the constructor, to combine the results of the function calls :return: result of combination
nltk.sem.logic.AbstractVariableExpression
, nltk.sem.logic.ApplicationExpression
, nltk.sem.logic.BooleanExpression
, nltk.sem.logic.EqualityExpression
, nltk.sem.logic.LambdaExpression
, nltk.sem.logic.NegatedExpression
, nltk.sem.logic.QuantifiedExpression
Set the type of this expression to be the given type. Raise type exceptions where applicable.
Parameters | |
other | Type |
signature | dict(str -> list(AbstractVariableExpression)) |