nltk.sem.drt module

exception nltk.sem.drt.AnaphoraResolutionException[source]

Bases: Exception

class nltk.sem.drt.DRS[source]

Bases: DrtExpression, Expression

A Discourse Representation Structure.

__init__(refs, conds, consequent=None)[source]
Parameters
  • refs – list of DrtIndividualVariableExpression for the discourse referents

  • conds – list of Expression for the conditions

eliminate_equality()[source]
fol()[source]
free()[source]
See

Expression.free()

get_refs(recursive=False)[source]
See

AbstractExpression.get_refs()

replace(variable, expression, replace_bound=False, alpha_convert=True)[source]

Replace all instances of variable v with expression E in self, where v is free in self.

visit(function, combinator)[source]
See

Expression.visit()

visit_structured(function, combinator)[source]
See

Expression.visit_structured()

class nltk.sem.drt.DrsDrawer[source]

Bases: object

BUFFER = 3
OUTERSPACE = 6
TOPSPACE = 10
__init__(drs, size_canvas=True, canvas=None)[source]
Parameters
  • drsDrtExpression, The DRS to be drawn

  • size_canvas – bool, True if the canvas size should be the exact size of the DRS

  • canvasCanvas The canvas on which to draw the DRS. If none is given, create a new canvas.

draw(x=6, y=10)[source]

Draw the DRS

class nltk.sem.drt.DrtAbstractVariableExpression[source]

Bases: DrtExpression, AbstractVariableExpression

eliminate_equality()[source]
fol()[source]
get_refs(recursive=False)[source]
See

AbstractExpression.get_refs()

class nltk.sem.drt.DrtApplicationExpression[source]

Bases: DrtExpression, ApplicationExpression

fol()[source]
get_refs(recursive=False)[source]
See

AbstractExpression.get_refs()

class nltk.sem.drt.DrtBinaryExpression[source]

Bases: DrtExpression, BinaryExpression

get_refs(recursive=False)[source]
See

AbstractExpression.get_refs()

class nltk.sem.drt.DrtBooleanExpression[source]

Bases: DrtBinaryExpression, BooleanExpression

class nltk.sem.drt.DrtConcatenation[source]

Bases: DrtBooleanExpression

DRS of the form ‘(DRS + DRS)’

__init__(first, second, consequent=None)[source]
eliminate_equality()[source]
fol()[source]
getOp()[source]
get_refs(recursive=False)[source]
See

AbstractExpression.get_refs()

replace(variable, expression, replace_bound=False, alpha_convert=True)[source]

Replace all instances of variable v with expression E in self, where v is free in self.

simplify()[source]
Returns

beta-converted version of this expression

visit(function, combinator)[source]
See

Expression.visit()

class nltk.sem.drt.DrtConstantExpression[source]

Bases: DrtAbstractVariableExpression, ConstantExpression

class nltk.sem.drt.DrtEqualityExpression[source]

Bases: DrtBinaryExpression, EqualityExpression

fol()[source]
class nltk.sem.drt.DrtEventVariableExpression[source]

Bases: DrtIndividualVariableExpression, EventVariableExpression

class nltk.sem.drt.DrtExpression[source]

Bases: object

This is the base abstract DRT Expression from which every DRT Expression extends.

applyto(other)[source]
draw()[source]
eliminate_equality()[source]
equiv(other, prover=None)[source]

Check for logical equivalence. Pass the expression (self <-> other) to the theorem prover. If the prover says it is valid, then the self and other are equal.

Parameters
  • other – an DrtExpression to check equality against

  • prover – a nltk.inference.api.Prover

classmethod fromstring(s)[source]
get_refs(recursive=False)[source]

Return the set of discourse referents in this DRS. :param recursive: bool Also find discourse referents in subterms? :return: list of Variable objects

is_pronoun_function()[source]

Is self of the form “PRO(x)”?

make_EqualityExpression(first, second)[source]
make_VariableExpression(variable)[source]
pretty_format()[source]

Draw the DRS :return: the pretty print string

pretty_print()[source]
resolve_anaphora()[source]
property type
typecheck(signature=None)[source]
class nltk.sem.drt.DrtFunctionVariableExpression[source]

Bases: DrtAbstractVariableExpression, FunctionVariableExpression

class nltk.sem.drt.DrtIndividualVariableExpression[source]

Bases: DrtAbstractVariableExpression, IndividualVariableExpression

class nltk.sem.drt.DrtLambdaExpression[source]

Bases: DrtExpression, LambdaExpression

alpha_convert(newvar)[source]

Rename all occurrences of the variable introduced by this variable binder in the expression to newvar. :param newvar: Variable, for the new variable

fol()[source]
get_refs(recursive=False)[source]
See

AbstractExpression.get_refs()

class nltk.sem.drt.DrtNegatedExpression[source]

Bases: DrtExpression, NegatedExpression

fol()[source]
get_refs(recursive=False)[source]
See

AbstractExpression.get_refs()

class nltk.sem.drt.DrtOrExpression[source]

Bases: DrtBooleanExpression, OrExpression

fol()[source]
class nltk.sem.drt.DrtParser[source]

Bases: LogicParser

A lambda calculus expression parser.

__init__()[source]
Parameters

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

get_BooleanExpression_factory(tok)[source]

This method serves as a hook for other logic parsers that have different boolean operators

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_DRS(tok, context)[source]
handle_conds(context)[source]
handle_prop(tok, context)[source]
handle_refs()[source]
isvariable(tok)[source]
make_ApplicationExpression(function, argument)[source]
make_BooleanExpression(factory, first, second)[source]
make_EqualityExpression(first, second)[source]

This method serves as a hook for other logic parsers that have different equality expression classes

make_LambdaExpression(variables, term)[source]
make_NegatedExpression(expression)[source]
make_VariableExpression(name)[source]
class nltk.sem.drt.DrtProposition[source]

Bases: DrtExpression, Expression

__init__(variable, drs)[source]
eliminate_equality()[source]
fol()[source]
get_refs(recursive=False)[source]

Return the set of discourse referents in this DRS. :param recursive: bool Also find discourse referents in subterms? :return: list of Variable objects

replace(variable, expression, replace_bound=False, alpha_convert=True)[source]

Replace every instance of ‘variable’ with ‘expression’ :param variable: Variable The variable to replace :param expression: Expression The expression with which to replace it :param replace_bound: bool Should bound variables be replaced? :param alpha_convert: bool Alpha convert automatically to avoid name clashes?

visit(function, combinator)[source]
See

Expression.visit()

visit_structured(function, combinator)[source]
See

Expression.visit_structured()

class nltk.sem.drt.DrtTokens[source]

Bases: Tokens

CLOSE_BRACKET = ']'
COLON = ':'
DRS = 'DRS'
DRS_CONC = '+'
OPEN_BRACKET = '['
PRONOUN = 'PRO'
PUNCT = ['+', '[', ']', ':']
SYMBOLS = ['&', '^', '|', '->', '=>', '<->', '<=>', '=', '==', '!=', '\\', '.', '(', ')', ',', '-', '!', '+', '[', ']', ':']
TOKENS = ['and', '&', '^', 'or', '|', 'implies', '->', '=>', 'iff', '<->', '<=>', '=', '==', '!=', 'some', 'exists', 'exist', 'all', 'forall', 'iota', '\\', '.', '(', ')', ',', 'not', '-', '!', 'DRS', '+', '[', ']', ':']
nltk.sem.drt.DrtVariableExpression(variable)[source]

This is a factory method that instantiates and returns a subtype of DrtAbstractVariableExpression appropriate for the given variable.

class nltk.sem.drt.PossibleAntecedents[source]

Bases: list, DrtExpression, Expression

free()[source]

Set of free variables.

replace(variable, expression, replace_bound=False, alpha_convert=True)[source]

Replace all instances of variable v with expression E in self, where v is free in self.

nltk.sem.drt.demo()[source]
nltk.sem.drt.resolve_anaphora(expression, trail=[])[source]
nltk.sem.drt.test_draw()[source]