nltk.sem.boxer module

An interface to Boxer.

This interface relies on the latest version of the development (subversion) version of C&C and Boxer.

Usage

Set the environment variable CANDC to the bin directory of your CandC installation. The models directory should be in the CandC root directory. For example:

/path/to/candc/
bin/
    candc
    boxer
models/
    boxer/
class nltk.sem.boxer.AbstractBoxerDrs[source]

Bases: object

atoms()[source]
clean()[source]
renumber_sentences(f)[source]
variable_types()[source]
variables()[source]
Returns:

(set<variables>, set<events>, set<propositions>)

class nltk.sem.boxer.Boxer[source]

Bases: object

This class is an interface to Johan Bos’s program Boxer, a wide-coverage semantic parser that produces Discourse Representation Structures (DRSs).

__init__(boxer_drs_interpreter=None, elimeq=False, bin_dir=None, verbose=False, resolve=True)[source]
Parameters:
  • boxer_drs_interpreter – A class that converts from the AbstractBoxerDrs object hierarchy to a different object. The default is NltkDrtBoxerDrsInterpreter, which converts to the NLTK DRT hierarchy.

  • elimeq – When set to true, Boxer removes all equalities from the DRSs and discourse referents standing in the equality relation are unified, but only if this can be done in a meaning-preserving manner.

  • resolve – When set to true, Boxer will resolve all anaphoric DRSs and perform merge-reduction. Resolution follows Van der Sandt’s theory of binding and accommodation.

interpret(input, discourse_id=None, question=False, verbose=False)[source]

Use Boxer to give a first order representation.

Parameters:
  • input – str Input sentence to parse

  • occur_index – bool Should predicates be occurrence indexed?

  • discourse_id – str An identifier to be inserted to each occurrence-indexed predicate.

Returns:

drt.DrtExpression

interpret_multi(input, discourse_id=None, question=False, verbose=False)[source]

Use Boxer to give a first order representation.

Parameters:
  • input – list of str Input sentences to parse as a single discourse

  • occur_index – bool Should predicates be occurrence indexed?

  • discourse_id – str An identifier to be inserted to each occurrence-indexed predicate.

Returns:

drt.DrtExpression

interpret_multi_sents(inputs, discourse_ids=None, question=False, verbose=False)[source]

Use Boxer to give a first order representation.

Parameters:
  • inputs – list of list of str Input discourses to parse

  • occur_index – bool Should predicates be occurrence indexed?

  • discourse_ids – list of str Identifiers to be inserted to each occurrence-indexed predicate.

Returns:

drt.DrtExpression

interpret_sents(inputs, discourse_ids=None, question=False, verbose=False)[source]

Use Boxer to give a first order representation.

Parameters:
  • inputs – list of str Input sentences to parse as individual discourses

  • occur_index – bool Should predicates be occurrence indexed?

  • discourse_ids – list of str Identifiers to be inserted to each occurrence-indexed predicate.

Returns:

list of drt.DrtExpression

set_bin_dir(bin_dir, verbose=False)[source]
class nltk.sem.boxer.BoxerCard[source]

Bases: BoxerIndexed

__init__(discourse_id, sent_index, word_indices, var, value, type)[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.BoxerDrs[source]

Bases: AbstractBoxerDrs

__init__(refs, conds, consequent=None)[source]
atoms()[source]
clean()[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.BoxerDrsParser[source]

Bases: DrtParser

Reparse the str form of subclasses of AbstractBoxerDrs

__init__(discourse_id=None)[source]
Parameters:

type_check (bool) – should type checking be performed to their types?

attempt_adjuncts(expression, context)[source]
get_all_symbols()[source]

This method exists to be overridden

get_next_token_variable(description)[source]
handle(tok, context)[source]

This method is intended to be overridden for logics that use different operators or expressions

nullableIntToken()[source]
class nltk.sem.boxer.BoxerEq[source]

Bases: BoxerIndexed

__init__(discourse_id, sent_index, word_indices, var1, var2)[source]
atoms()[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.BoxerIndexed[source]

Bases: AbstractBoxerDrs

__init__(discourse_id, sent_index, word_indices)[source]
atoms()[source]
class nltk.sem.boxer.BoxerNamed[source]

Bases: BoxerIndexed

__init__(discourse_id, sent_index, word_indices, var, name, type, sense)[source]
change_var(var)[source]
clean()[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.BoxerNot[source]

Bases: AbstractBoxerDrs

__init__(drs)[source]
atoms()[source]
clean()[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.BoxerOr[source]

Bases: BoxerIndexed

__init__(discourse_id, sent_index, word_indices, drs1, drs2)[source]
atoms()[source]
clean()[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.BoxerOutputDrsParser[source]

Bases: DrtParser

__init__(discourse_id=None)[source]

This class is used to parse the Prolog DRS output from Boxer into a hierarchy of python objects.

attempt_adjuncts(expression, context)[source]
get_all_symbols()[source]

This method exists to be overridden

handle(tok, context)[source]

This method is intended to be overridden for logics that use different operators or expressions

handle_condition(tok, indices)[source]

Handle a DRS condition

Parameters:

indices – list of int

Returns:

list of DrtExpression

handle_drs(tok)[source]
parse(data, signature=None)[source]

Parse the expression.

Parameters:
  • data – str for the input to be parsed

  • signaturedict<str, str> that maps variable names to type strings

Returns:

a parsed Expression

parse_condition(indices)[source]

Parse a DRS condition

Returns:

list of DrtExpression

parse_drs()[source]
parse_index()[source]
parse_variable()[source]
class nltk.sem.boxer.BoxerPred[source]

Bases: BoxerIndexed

__init__(discourse_id, sent_index, word_indices, var, name, pos, sense)[source]
change_var(var)[source]
clean()[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.BoxerProp[source]

Bases: BoxerIndexed

__init__(discourse_id, sent_index, word_indices, var, drs)[source]
atoms()[source]
clean()[source]
referenced_labels()[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.BoxerRel[source]

Bases: BoxerIndexed

__init__(discourse_id, sent_index, word_indices, var1, var2, rel, sense)[source]
clean()[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.BoxerWhq[source]

Bases: BoxerIndexed

__init__(discourse_id, sent_index, word_indices, ans_types, drs1, variable, drs2)[source]
atoms()[source]
clean()[source]
renumber_sentences(f)[source]
class nltk.sem.boxer.NltkDrtBoxerDrsInterpreter[source]

Bases: object

__init__(occur_index=False)[source]
interpret(ex)[source]
Parameters:

exAbstractBoxerDrs

Returns:

DrtExpression

class nltk.sem.boxer.PassthroughBoxerDrsInterpreter[source]

Bases: object

interpret(ex)[source]
exception nltk.sem.boxer.UnparseableInputException[source]

Bases: Exception