module documentation

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.

Function demo Undocumented
Function demo_legacy_grammar Check that interpret_sents() is compatible with legacy grammars that use a lowercase 'sem' feature.
Function demo_model0 Undocumented
Function evaluate_sents Add the truth-in-a-model value to each semantic representation for each syntactic parse of each input sentences.
Function interpret_sents Add the semantic representation to each syntactic parse tree of each input sentence.
Function parse_sents Convert input sentences into syntactic trees.
Function read_sents Undocumented
Function root_semrep Find the semantic representation at the root of a tree.
def demo(): (source)

Undocumented

def demo_legacy_grammar(): (source)

Check that interpret_sents() is compatible with legacy grammars that use a lowercase 'sem' feature.

Define 'test.fcfg' to be the following

def demo_model0(): (source)

Undocumented

def evaluate_sents(inputs, grammar, model, assignment, trace=0): (source)

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

Parameters
inputs:list(str)a list of sentences
grammar:nltk.grammar.FeatureGrammarFeatureGrammar or name of feature-based grammar
modelUndocumented
assignmentUndocumented
traceUndocumented
Returns
list(list(tuple(nltk.tree.Tree, nltk.sem.logic.ConstantExpression, bool or dict(str): bool)))a mapping from sentences to lists of triples (parse-tree, semantic-representations, evaluation-in-model)
def interpret_sents(inputs, grammar, semkey='SEM', trace=0): (source)

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

Parameters
inputs:list(str)a list of sentences
grammar:nltk.grammar.FeatureGrammarFeatureGrammar or name of feature-based grammar
semkeyUndocumented
traceUndocumented
Returns
list(list(tuple(nltk.tree.Tree, nltk.sem.logic.ConstantExpression)))a mapping from sentences to lists of pairs (parse-tree, semantic-representations)
def parse_sents(inputs, grammar, trace=0): (source)

Convert input sentences into syntactic trees.

Parameters
inputs:list(str)sentences to be parsed
grammar:nltk.grammar.FeatureGrammarFeatureGrammar or name of feature-based grammar
traceUndocumented
Returns
list(nltk.tree.Tree) or dict(list(str)): list(Tree)a mapping from input sentences to a list of ``Tree``s
def read_sents(filename, encoding='utf8'): (source)

Undocumented

def root_semrep(syntree, semkey='SEM'): (source)

Find the semantic representation at the root of a tree.

Parameters
syntreea parse Tree
semkeythe feature label to use for the root semantics in the tree
Returns
sem.Expressionthe semantic representation at the root of a Tree