Package nltk_lite :: Package semantics :: Module evaluate :: Class Model
[hide private]
[frames] | no frames]

Class Model

source code

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) source code
 
__str__(self) source code
 
app(self, fun, arg)
Wrapper for handling KeyErrors and TypeErrors raised by function application.
source code
bool or 'Undefined'
evaluate(self, expr, g, trace=None)
Provides a handler for satisfy that blocks further propagation of Undefined error.
source code
 
satisfy(self, expr, g, trace=None)
Recursive interpretation function for a formula of first-order logic.
source code
 
i(self, expr, g, trace=True)
An interpretation function.
source code
bool
freevar(self, var, expr)
Is var one of the free variables in expr?
source code
 
satisfiers(self, expr, var, g, trace=True, nesting=0)
Generate the entities from the model's domain that satisfy an open formula.
source code
 
decompose(self, expr)
Function to communicate with a first-order functional language.
source code
bool
any(self, seq)
Returns True if there is at least one element in the iterable.
source code
Class Variables [hide private]
  NOT = {False: True, True: False}
  AND = {False: {False: False, True: False}, True: {False: False...
  OR = {False: {False: False, True: True}, True: {False: True, T...
  IMPLIES = {False: {False: True, True: True}, True: {False: Fal...
  IFF = {False: {False: True, True: False}, True: {False: False,...
  OPS = {'and': {False: {False: False, True: False}, True: {Fals...
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.

app(self, fun, arg)

source code 

Wrapper for handling KeyErrors and TypeErrors raised by function application.

This constrains instances of CharFun to return False in the right circumstances.

Parameters:
  • fun - an instance of CharFun.
  • arg - an arbitrary semantic object
Returns:
If arg is in fun's domain, then returns fun[arg], else if arg is in self.domain, returns False, else raises Undefined error.

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

source code 

Provides a handler for satisfy that blocks further propagation of Undefined error.

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

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

source code 

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

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

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

i(self, expr, g, trace=True)

source code 

An interpretation function.

Assuming that expr is atomic:

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

freevar(self, var, expr)

source code 

Is var one of the free variables in expr?

Parameters:
  • var (an Indvar of logic) - the variable to test for.
  • expr - an Expression of logic.
Returns: bool

satisfiers(self, expr, var, g, trace=True, nesting=0)

source code 

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

Parameters:
  • expr - the open formula
  • var - the relevant free variable in expr.
  • g - the variable assignment
Returns:
an iterator over the entities that satisfy expr.

decompose(self, expr)

source code 

Function to communicate with a first-order functional language.

This function tries to make weak assumptions about the parse structure provided by the logic module. It makes the assumption that an expression can be broken down into a pair of subexpressions:

  • The (binder, body) pair is for decomposing quantified formulae.
  • The (op, args) pair is for decomposing formulae with a boolean operator.
  • The (fun, args) pair should catch other relevant cases.
Parameters:
  • expr - A string representation of a first-order formula.

any(self, seq)

source code 

Returns True if there is at least one element in the iterable.

Parameters:
  • seq - an iterator
Returns: bool

Class Variable Details [hide private]

AND

Value:
{False: {False: False, True: False}, True: {False: False, True: True}}

OR

Value:
{False: {False: False, True: True}, True: {False: True, True: True}}

IMPLIES

Value:
{False: {False: True, True: True}, True: {False: False, True: True}}

IFF

Value:
{False: {False: True, True: False}, True: {False: False, True: True}}

OPS

Value:
{'and': {False: {False: False, True: False},
         True: {False: False, True: True}},
 'iff': {False: {False: True, True: False},
         True: {False: False, True: True}},
 'implies': {False: {False: True, True: True},
             True: {False: False, True: True}},
 'or': {False: {False: False, True: True},
        True: {False: True, True: True}}}