Package nltk :: Package sem :: Module evaluate :: Class Model
[hide private]
[frames] | no frames]

Class Model

source code

object --+
         |
        Model

A first order model is a domain D of discourse and a valuation V.

A domain D is a set, and a valuation V is a map that associates expressions with values in the model. The domain of V should be a subset of D.

Instance Methods [hide private]
 
__init__(self, domain, valuation, prop=None)
Construct a new Model.
source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code
 
AND(self, arg1, arg2) source code
 
OR(self, arg1, arg2) source code
 
IMPLIES(self, arg1, arg2) source code
 
IFF(self, arg1, arg2) source code
 
EQ(self, arg1, arg2) source code
 
ALL(self, sat) source code
 
EXISTS(self, sat) source code
bool or 'Undefined'
evaluate(self, expr, g, trace=None)
Call the LogicParser to parse input expressions, and provide a handler for satisfy that blocks further propagation of the Undefined error.
source code
 
satisfy(self, parsed, g, trace=None)
Recursive interpretation function for a formula of first-order logic.
source code
 
i(self, parsed, g, trace=False)
An interpretation function.
source code
 
satisfiers(self, parsed, varex, g, trace=None, nesting=0)
Generate the entities from the model's domain that satisfy an open formula.
source code

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

Class Variables [hide private]
  OPS = {'&': AND, '|': OR, '->': IMPLIES, '<->': IFF, '=': EQ,}
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, domain, valuation, prop=None)
(Constructor)

source code 

Construct a new Model.

Parameters:
  • domain (set) - A set of entities representing the domain of discourse of the model.
  • valuation (Valuation) - the valuation of the model.
  • prop - If this is set, then we are building a propositional model and don't require the domain of V to be subset of D.
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

evaluate(self, expr, g, trace=None)

source code 

Call the LogicParser to parse input expressions, and provide a handler for satisfy that blocks further propagation of the Undefined error.

Parameters:
  • expr - An Expression of logic.
  • g (Assignment) - an assignment to individual variables.
Returns: bool or 'Undefined'

satisfy(self, parsed, g, trace=None)

source code 

Recursive interpretation function for a formula of first-order logic.

Raises an Undefined error when parsed is an atomic string but is not a symbol or an individual variable.

Parameters:
  • parsed - An expression of logic.
  • g (Assignment) - an assignment to individual variables.
Returns:
Returns a truth value or Undefined if parsed is complex, and calls the interpretation function i if parsed is atomic.

i(self, parsed, g, trace=False)

source code 

An interpretation function.

Assuming that parsed is atomic:

  • if parsed is a non-logical constant, calls the valuation V
  • else if parsed is an individual variable, calls assignment g
  • else returns Undefined.
Parameters:
  • parsed - an Expression of logic.
  • g (Assignment) - an assignment to individual variables.
Returns:
a semantic value

satisfiers(self, parsed, varex, g, trace=None, nesting=0)

source code 

Generate the entities from the model's domain that satisfy an open formula.

Parameters:
  • parsed (Expression) - an open formula
  • varex (VariableExpression or str) - the relevant free individual variable in parsed.
  • g (Assignment) - a variable assignment
Returns:
a set of the entities that satisfy parsed.