Package nltk :: Package sem :: Module logic :: Class ApplicationExpression
[hide private]
[frames] | no frames]

Class ApplicationExpression

source code

         object --+        
                  |        
SubstituteBindingsI --+    
                      |    
             Expression --+
                          |
                         ApplicationExpression
Known Subclasses:

This class is used to represent two related types of logical expressions.

The first is a Predicate Expression, such as "P(x,y)". A predicate expression is comprised of a VariableExpression as the predicate and a list of Expressions as the arguments.

The second is a an application of one expression to another, such as "(\x.dog(x))(fido)".

The reason Predicate Expressions are treated as Application Expressions is that the VariableExpression predicate of the expression may be replaced with another Expression, such as a LambdaExpression, which would mean that the Predicate should be thought of as being applied to the arguments.

The LogicParser will always curry arguments in a application expression. So, "\x y.see(x,y)(john,mary)" will be represented internally as "((\x y.(see(x))(y))(john))(mary)". This simplifies the internals since there will always be exactly one argument in an application.

The str() method will usually print the curried forms of application expressions. The one exception is when the the application expression is really a predicate expression (ie, underlying function is a VariableExpression). This means that the example from above will be returned as "(\x y.see(x,y)(john))(mary)".

Instance Methods [hide private]
 
__init__(self, function, argument)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
simplify(self) source code
 
replace(self, variable, expression, replace_bound=False)
Replace every instance of 'variable' with 'expression'
source code
 
variables(self)
Return a set of all the variables that are available to be replaced.
source code
 
free(self, indvar_only=True)
Return a set of all the free (non-bound) variables in self.
source code
 
__eq__(self, other) source code
 
str(self, syntax=1) source code
 
uncurry(self)
return: A tuple (base-function, arg-list)
source code

Inherited from Expression: __and__, __call__, __gt__, __hash__, __lt__, __neg__, __or__, __repr__, __str__, applyto, negate, substitute_bindings, tp_equals

Inherited from object: __delattr__, __getattribute__, __new__, __reduce__, __reduce_ex__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, function, argument)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • function - Expression, for the function expression
  • argument - Expression, for the argument
Overrides: object.__init__

replace(self, variable, expression, replace_bound=False)

source code 

Replace every instance of 'variable' with 'expression'

Parameters:
  • variable - Variable The variable to replace
  • expression - Expression The expression with which to replace it
  • replace_bound - boolean Should bound variables be replaced?

variables(self)

source code 

Return a set of all the variables that are available to be replaced. This includes free (non-bound) variables as well as predicates.

Returns:
set of Variables
Overrides: Expression.variables

See Also: Expression.variables()

free(self, indvar_only=True)

source code 

Return a set of all the free (non-bound) variables in self. Variables serving as predicates are no included.

Parameters:
  • indvar_only - boolean only return individual variables?
Returns:
set of Variables
Overrides: Expression.free

See Also: Expression.free()

__eq__(self, other)
(Equality operator)

source code 
Overrides: Expression.__eq__