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

Package sem

source code

This package contains classes for representing semantic structure in formulas of first-order logic and for evaluating such formulas in set-theoretic models.

Submodules [hide private]

Classes [hide private]
Assignment
A dictionary which represents an assignment of values to variables.
Valuation
A dictionary which represents a model-theoretic Valuation of non-logical constants.
Undefined
Model
A first order model is a domain D of discourse and a valuation V.
LogicParser
A lambda calculus expression parser.
DrtParser
A lambda calculus expression parser.
Boxer
This class is an interface to Johan Bos's program Boxer, a wide-coverage semantic parser that produces Discourse Representation Structures (DRSs).
Functions [hide private]
dict
batch_interpret(inputs, grammar, semkey='SEM', trace=0)
Add the semantic representation to each syntactic parse tree of each input sentence.
source code
dict
batch_evaluate(inputs, grammar, model, assignment, trace=0)
Add the truth-in-a-model value to each semantic representation for each syntactic parse of each input sentences.
source code
dict
batch_parse(inputs, grammar, trace=0)
Convert input sentences into syntactic trees.
source code
list of Expression
parse_logic(s, logic_parser=None)
Convert a file of First Order Formulas into a list of {Expression}s.
source code
tuple
parse_valuation_line(s)
Parse a line in a valuation file.
source code
logic.Expression
root_semrep(syntree, semkey='SEM')
Find the semantic representation at the root of a tree.
source code
 
skolemize(expression, univ_scope=None, used_variables=None)
Skolemize the expression and convert to conjunctive normal form (CNF)
source code
Valuation
parse_valuation(s)
Convert a valuation file into a valuation.
source code
bool
is_rel(s)
Check whether a set represents a relation (of any arity).
source code
int of tuple of str
arity(rel)
Check the arity of a relation.
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
 
equality_preds()
Equality predicates
source code
 
binding_ops()
Binding operators
source code
 
boolean_ops()
Boolean operators
source code
Variables [hide private]
  APP = 'APP'
Function Details [hide private]

batch_interpret(inputs, grammar, semkey='SEM', trace=0)

source code 

Add the semantic representation to each syntactic parse tree of each input sentence.

Parameters:
  • inputs - a list of sentences
  • grammar - FeatureGrammar or name of feature-based grammar
Returns: dict
a mapping from sentences to lists of pairs (parse-tree, semantic-representations)

batch_evaluate(inputs, grammar, model, assignment, trace=0)

source code 

Add the truth-in-a-model value to each semantic representation for each syntactic parse of each input sentences.

Parameters:
  • inputs - a list of sentences
  • grammar - FeatureGrammar or name of feature-based grammar
Returns: dict
a mapping from sentences to lists of triples (parse-tree, semantic-representations, evaluation-in-model)

batch_parse(inputs, grammar, trace=0)

source code 

Convert input sentences into syntactic trees.

Parameters:
  • inputs (list of str) - sentences to be parsed
  • grammar - FeatureGrammar or name of feature-based grammar
Returns: dict
a mapping from input sentences to a list of Trees

parse_logic(s, logic_parser=None)

source code 

Convert a file of First Order Formulas into a list of {Expression}s.

Parameters:
  • s (str) - the contents of the file
  • logic_parser (LogicParser) - The parser to be used to parse the logical expression
Returns: list of Expression
a list of parsed formulas.

parse_valuation_line(s)

source code 

Parse a line in a valuation file.

Lines are expected to be of the form:

 noosa => n
 girl => {g1, g2}
 chase => {(b1, g1), (b2, g1), (g1, d1), (g2, d2)}
Parameters:
  • s (str) - input line
Returns: tuple
a pair (symbol, value)

root_semrep(syntree, semkey='SEM')

source code 

Find the semantic representation at the root of a tree.

Parameters:
  • syntree - a parse Tree
  • semkey - the feature label to use for the root semantics in the tree
Returns: logic.Expression
the semantic representation at the root of a Tree

parse_valuation(s)

source code 

Convert a valuation file into a valuation.

Parameters:
  • s (str) - the contents of a valuation file
Returns: Valuation
a nltk.sem valuation

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

arity(rel)

source code 

Check the arity of a relation.

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

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