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

Module evaluate

source code

This module provides data structures for representing first-order models.

Classes [hide private]
  Error
  Undefined
  Valuation
A dictionary which represents a model-theoretic Valuation of non-logical constants.
  Assignment
A dictionary which represents an assignment of values to variables.
  Model
A first order model is a domain D of discourse and a valuation V.
Functions [hide private]
 
trace(f, *args, **kw) source code
bool
is_rel(s)
Check whether a set represents a relation (of any arity).
source code
set of tuple of str
set2rel(s)
Convert a set containing individuals (strings or numbers) into a set of unary tuples.
source code
int of tuple of str
arity(rel)
Check the arity of a relation.
source code
bool or a set of tuples
app(rel, arg, trace=False)
Apply a relation (as set of tuples) to an argument.
source code
VariableExpression or IndividualVariableExpression
make_VariableExpression(var)
Convert a string into an instance of VariableExpression
source code
 
propdemo(trace=None)
Example of a propositional model.
source code
 
folmodel(trace=None)
Example of a first-order model.
source code
 
foldemo(trace=None)
Interpretation of closed expressions in a first-order model.
source code
 
satdemo(trace=None)
Satisfiers of an open formula in a first order model.
source code
 
demo(num=0, trace=None)
Run exists demos.
source code
Variables [hide private]
  mult = 30
Function Details [hide private]

is_rel(s)

source code 

Check whether a set represents a relation (of any arity).

Parameters:
  • s (set) - a set containing tuples of str elements
Returns: bool

set2rel(s)

source code 

Convert a set containing individuals (strings or numbers) into a set of unary tuples. Any tuples of strings already in the set are passed through unchanged.

For example:

  • set(['a', 'b']) => set([('a',), ('b',)])
  • set([3, 27]) => set([('3',), ('27',)])
Parameters:
  • s (set)
Returns: set of tuple of str

arity(rel)

source code 

Check the arity of a relation.

Parameters:
  • rel (set of tuples)
Returns: int of tuple of str

app(rel, arg, trace=False)

source code 

Apply a relation (as set of tuples) to an argument.

If rel has arity n <= 1, then app returns a Boolean value. If If rel has arity n > 1, then app returns a relation of arity n-1.

Parameters:
  • arg - any appropriate semantic argument
  • rel (set of tuples)
Returns: bool or a set of tuples
Decorators:
  • @decorator(trace)

make_VariableExpression(var)

source code 

Convert a string into an instance of VariableExpression

Parameters:
  • var (str)
Returns: VariableExpression or IndividualVariableExpression

demo(num=0, trace=None)

source code 

Run exists demos.

  • num = 1: propositional logic demo
  • num = 2: first order model demo (only if trace is set)
  • num = 3: first order sentences demo
  • num = 4: satisfaction of open formulas demo
  • any other value: run all the demos
Parameters:
  • trace - trace = 1, or trace = 2 for more verbose tracing