nltk.sem.Model¶
- class nltk.sem.Model[source]¶
Bases:
objectA 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.
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.
- evaluate(expr, g, trace=None)[source]¶
Read input expressions, and provide a handler for
satisfythat blocks further propagation of theUndefinederror. :param expr: AnExpressionoflogic. :type g: Assignment :param g: an assignment to individual variables. :rtype: bool or ‘Undefined’
- satisfy(parsed, g, trace=None)[source]¶
Recursive interpretation function for a formula of first-order logic.
Raises an
Undefinederror whenparsedis an atomic string but is not a symbol or an individual variable.- Returns
Returns a truth value or
Undefinedifparsedis complex, and calls the interpretation functioniifparsedis atomic.- Parameters
parsed – An expression of
logic.g (Assignment) – an assignment to individual variables.
- i(parsed, g, trace=False)[source]¶
An interpretation function.
Assuming that
parsedis atomic:if
parsedis a non-logical constant, calls the valuation Velse if
parsedis an individual variable, calls assignment gelse returns
Undefined.
- Parameters
parsed – an
Expressionoflogic.g (Assignment) – an assignment to individual variables.
- Returns
a semantic value
- satisfiers(parsed, varex, g, trace=None, nesting=0)[source]¶
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.