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

Module util

source code

Utility functions for batch-processing sentences: parsing and extraction of the semantic representation of the root node of the the syntax tree, followed by evaluation of the semantic representation in a first-order model.

Functions [hide private]
dict
text_parse(inputs, grammar, trace=0)
Convert input sentences into syntactic trees.
source code
logic.Expression
_semrep(node, beta_reduce=True)
Find the semantic representation at a given tree node.
source code
logic.Expression
root_semrep(syntree, beta_reduce=True, start='S')
Find the semantic representation at the root of a tree.
source code
dict
text_interpret(inputs, grammar, beta_reduce=True, start='S', syntrace=0)
Add the semantic representation to each syntactic parse tree of each input sentence.
source code
dict
text_evaluate(inputs, grammar, model, assignment, semtrace=0)
Add the truth-in-a-model value to each semantic representation for each syntactic parse of each input sentences.
source code
tuple
parse_valuation_line(s)
Parse a line in a valuation file.
source code
Valuation
parse_valuation(s)
Convert a valuation file into a valuation.
source code
list of Expression
parse_fol(s)
Convert a file of First Order Formulas into a list of {Expression}s.
source code
 
demo_model0() source code
 
read_sents(file) source code
 
demo() source code
Variables [hide private]
  _VAL_SPLIT_RE = re.compile(r'\s*=+>\s*')
  _ELEMENT_SPLIT_RE = re.compile(r'\s*,\s*')
  _TUPLES_RE = re.compile(r'(?x)\s*(\([^\)]+\))\s*')
Function Details [hide private]

text_parse(inputs, grammar, trace=0)

source code 

Convert input sentences into syntactic trees.

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

_semrep(node, beta_reduce=True)

source code 

Find the semantic representation at a given tree node.

Parameters:
  • node - node of a parse Tree
Returns: logic.Expression

root_semrep(syntree, beta_reduce=True, start='S')

source code 

Find the semantic representation at the root of a tree.

Parameters:
  • syntree - a parse Tree
  • beta_reduce - if True, carry out beta reduction on the logical forms that are returned
Returns: logic.Expression
the semantic representation at the root of a Tree

text_interpret(inputs, grammar, beta_reduce=True, start='S', syntrace=0)

source code 

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

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

text_evaluate(inputs, grammar, model, assignment, semtrace=0)

source code 

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

Returns: dict
a mapping from sentences to lists of triples (parse-tree, semantic-representations, evaluation-in-model)

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)

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

parse_fol(s)

source code 

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

Parameters:
  • s (str) - the contents of the file
Returns: list of Expression
a list of parsed formulas.