Welcome to NLTK-DRT Extension’s documentation!

Curt client

nltk_drt.curt.main()[source]

Main function.

Admissibility Constraints:

An expression to be checked for admissibility should be a DRS which embeds a NewInfoDRS: The former represents previous discourse (if any), the latter is some new discourse that has been resolved with respect to that previous discourse. There are two groups of Admissibility Constraints (van der Sandt 1992):

Global Constraints:

Prover - negative check for consistency. Prover - negative check for informativity. Builder - positive check for consistency. Builder - positive check for informativity.

Global Consistency: Give a NegatedExpression of the resulting discourse to the prover.

If it returns True, the discourse is inconsistent. Give the resulting discourse to the builder. If it returns a model, the discourse is consistent.

Global Informativity: Negate new discourse. Give a NegatedExpression of the resulting

discourse to the prover. If the prover returns True, then the resulting discourse is uninformative. Give the resulting discourse to the builder. If it returns a model, the new reading is informative.

Local Constraints:

Superordinate DRSs should entail neither a DRS nor its negation. Generate a list of ordered pairs such that the first element of the pair is the DRS representing the entire discourse but without some subordinate DRS and the second is this subordinate DRS to be checked on entailment:

(i) From DrtNegatedExpression -K, if K is a DRS, take K and put it in the second place of the ordered pair. Remove the DrtNegatedExpression and place the rest in the first place of the order pair.

(ii) From a DrtImpCondition K->L, provided that both are DRSs, create two ordered pairs: (a) Put the antecedent DRS K into the second place, remove the DrtImpCondition and put the result into the first place of the ordered pair; (b) Put the consequent DRS L into the second place, merge the antecedent DRS K globally and put the result into the first place of the ordered pair.

(iii) From a DrtOrExpression K | L, provided that both are DRSs, create two ordered pairs: Put each of the disjuncts into the second place of each pair, remove the DrtORExpression and put the result into the first place of that pair.

class nltk_drt.inference.AdmissibilityError[source]
__weakref__

list of weak references to the object (if defined)

class nltk_drt.inference.Communicator(process, input=None)[source]

a thread communicating with a process, terminates once the communication is over

__init__(process, input=None)[source]

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is the argument tuple for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class nltk_drt.inference.ConsistencyError[source]
__weakref__

list of weak references to the object (if defined)

class nltk_drt.inference.InformativityError[source]
__weakref__

list of weak references to the object (if defined)

nltk_drt.inference.get_bk(drs, dictionary)[source]

Collects background knowledge relevant for a given expression. DrtConstantExpression variable names are used as keys

nltk_drt.inference.inference_check(expr, background_knowledge=False, verbose=True)[source]

General function for all kinds of inference-based checks: consistency, global and local informativity

NLTK DRT module extended with presuppositions

class nltk_drt.presuppdrt.Binding(iterable=(), /)[source]
Classes

Reading

class nltk_drt.presuppdrt.ConditionRemover(cond_index: int)[source]

A generic condition remover functor to be used in readings

__call__(drs: DRS)[source]

Call self as a function.

__init__(cond_index: int)[source]
__weakref__

list of weak references to the object (if defined)

class nltk_drt.presuppdrt.ConditionReplacer(index: int, conds: List[DrtExpression], ref: Optional[bool] = None)[source]

A generic condition replacer functor to be used in readings replace the condition at the given index with any number of conditions, optionally adds a referent

Parameters
  • index (int) – index of the condition

  • conds (List[DrtExpression]) – list of DrtExpression for conditions

__call__(drs: DRS)[source]

Call self as a function.

__init__(index: int, conds: List[DrtExpression], ref: Optional[bool] = None)[source]
__weakref__

list of weak references to the object (if defined)

class nltk_drt.presuppdrt.DRS(refs, conds, consequent=None)[source]

A Temporal Discourse Representation Structure.

deepcopy(operations=[])[source]

This method returns a deep copy of the DRS. Optionally, it can take a list of lists of tuples (DRS, function) as an argument and generate a reading by performing a substitution in the DRS as specified by the function. @param operations: a list of lists of tuples

free(indvar_only=True)[source]

@see: Expression.free(). TODO

get_refs(recursive=False)[source]

@see: AbstractExpression.get_refs()

readings(trail=[])[source]

get the readings for this DRS

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

class nltk_drt.presuppdrt.DefiniteDescriptionDRS(refs, conds, consequent=None)[source]
semantic_check(individuals, presupp_individuals, strict=False)[source]

Users can plug in their more sophisticated semantic checks here. As for this project, we confine ourselves to ontologies provided by WordNet. See the other file for how this is supposed to work.

class nltk_drt.presuppdrt.DrtAbstractVariableExpression(variable)[source]
class nltk_drt.presuppdrt.DrtApplicationExpression(function, argument)[source]
is_propername()[source]

A proper name is capitalised. We assume that John(x) uniquely identifies the bearer of the name John and so, when going from Kamp & Reyle’s DRT format into classical FOL logic, we change a condition like that into John = x.

@return: C{boolean} True if expr is of the correct form

class nltk_drt.presuppdrt.DrtBooleanExpression(first, second)[source]
simplify()[source]

When dealing with DRSs, it is good to have unique names for the referents bound by each DRS.

class nltk_drt.presuppdrt.DrtConcatenation(first, second, consequent=None)[source]
__eq__(other)[source]

Defines equality modulo alphabetic variance. If we are comparing x.M and y.N, then check equality of M and N[x/y].

__hash__()[source]

Return hash(self).

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

class nltk_drt.presuppdrt.DrtConstantExpression(variable)[source]
class nltk_drt.presuppdrt.DrtEqualityExpression(first, second)[source]
class nltk_drt.presuppdrt.DrtEventVariableExpression(variable)[source]
class nltk_drt.presuppdrt.DrtEventualityApplicationExpression(function, argument)[source]

application expression with state or event argument

class nltk_drt.presuppdrt.DrtExpression[source]

A base abstract DRT Expression from which every DRT Expression inherits.

__gt__(other)[source]

Return self>value.

__lt__(other)[source]

Return self<value.

make_EqualityExpression(first: DrtExpression, second: DrtExpression)[source]

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

make_VariableExpression(variable: Variable)[source]

Make variable expression

normalize()[source]

Rename auto-generated unique variables

resolve(inference_check=None, verbose=True)[source]

This method does the whole job of collecting multiple readings. We aim to get new readings from the old ones by resolving presuppositional DRSs one by one. Every time one presupposition is resolved, new readings are created and replace the old ones, until there are no presuppositions left to resolve.

substitute_bindings(bindings) DrtExpression[source]

Substitute bindings. TODO

class nltk_drt.presuppdrt.DrtFeatureConstantExpression(variable, features: Iterable[DrtFeatureExpression])[source]

A constant expression with syntactic features attached

__init__(variable, features: Iterable[DrtFeatureExpression])[source]
Parameters

variableVariable, for the variable

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

@see: Expression.replace()

visit(function, combinator, default)[source]

@see: Expression.visit()

class nltk_drt.presuppdrt.DrtFeatureExpression(variable)[source]

expression for a single syntactic feature

class nltk_drt.presuppdrt.DrtFunctionVariableExpression(variable)[source]
class nltk_drt.presuppdrt.DrtIffExpression(first, second)[source]
class nltk_drt.presuppdrt.DrtImpExpression(first, second)[source]
__eq__(other)[source]

Return self==value.

__hash__ = None
class nltk_drt.presuppdrt.DrtIndividualVariableExpression(variable)[source]
class nltk_drt.presuppdrt.DrtLambdaExpression(variable, term)[source]
alpha_convert(newvar)[source]

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

get_refs(recursive=False)[source]

@see: AbstractExpression.get_refs()

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

@see: Expression.replace()

class nltk_drt.presuppdrt.DrtNegatedExpression(term)[source]
class nltk_drt.presuppdrt.DrtOrExpression(first, second)[source]
class nltk_drt.presuppdrt.DrtParser[source]
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]

We add new types of DRS to represent presuppositions

handle_PresuppositionDRS(tok, context)[source]

Parse all the Presuppositon DRSs.

make_EqualityExpression(first, second)[source]

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

class nltk_drt.presuppdrt.DrtProperNameExpression(variable)[source]

proper names

class nltk_drt.presuppdrt.DrtStateVariableExpression(variable)[source]

expression of discourse referents of state

class nltk_drt.presuppdrt.DrtTimeVariableExpression(variable)[source]

expression of discourse referents of time

class nltk_drt.presuppdrt.DrtTokens[source]

Extended tokens from drt.DrtTokens

class nltk_drt.presuppdrt.DrtUtterVariableExpression(variable)[source]

expression of utterance time referent

nltk_drt.presuppdrt.DrtVariableExpression(variable)[source]

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

class nltk_drt.presuppdrt.GlobalAccommodation(iterable=(), /)[source]

Global accomodation

Classes

Reading

class nltk_drt.presuppdrt.IntermediateAccommodation(iterable=(), /)[source]

Intermediate accomodation

Classes

Reading

class nltk_drt.presuppdrt.LocalAccommodation(iterable=(), /)[source]

Local accomodation

Classes

Reading

class nltk_drt.presuppdrt.PresuppositionDRS(refs, conds, consequent=None)[source]
class Accommodate(presupp_drs, condition_index)[source]
__call__(drs)[source]

Accommodation: put all referents and conditions from the presupposition DRS into the given DRS

__init__(presupp_drs, condition_index)[source]
class Bind(presupp_drs, presupp_variable, presupp_funcname, antecedent_cond, condition_index)[source]
__call__(drs)[source]

Put all conditions from the presuppositional DRS into the DRS (but do not create duplicates), and replace the presupposition condition referent in them with antecedent referent

__init__(presupp_drs, presupp_variable, presupp_funcname, antecedent_cond, condition_index)[source]
class DoMultipleOperations(operations_list)[source]
__call__(drs)[source]

Do the operations one by one

__init__(operations_list)[source]
class InnerReplace(presupp_variable, antecedent_ref)[source]
__call__(drs)[source]

In the conditions of the local DRS, replace the referent of the presupposition condition with antecedent_ref

__init__(presupp_variable, antecedent_ref)[source]
class MoveTemporalConditions(temporal_conditions)[source]
__call__(drs)[source]

Call self as a function.

__init__(temporal_conditions)[source]
class Operation[source]

An interface for all operations

__call__(drs)[source]

Call self as a function.

__weakref__

list of weak references to the object (if defined)

readings(trail=[])[source]

get the readings for this DRS

class nltk_drt.presuppdrt.PronounDRS(refs, conds, consequent=None)[source]

A class for DRSs for personal, reflexive, and possessive pronouns

class nltk_drt.presuppdrt.ProperNameDRS(refs, conds, consequent=None)[source]
class nltk_drt.presuppdrt.Reading(iterable=(), /)[source]

A single reading, consists of a list of operations each operation is a tuple of a DRS and a function, where the function would be executed on the given DRS when the reading is generated

__weakref__

list of weak references to the object (if defined)

exception nltk_drt.presuppdrt.ResolutionException[source]
__weakref__

list of weak references to the object (if defined)

class nltk_drt.presuppdrt.StateType[source]

Basic type of states added on top of nltk.sem.logic.

__str__()[source]

Return str(self).

class nltk_drt.presuppdrt.StateVariableExpression(variable)[source]

This class represents variables that take the form of a single lowercase ‘s’ character followed by zero or more digits.

Classes

IndividualVariableExpression

class nltk_drt.presuppdrt.TimeType[source]

Basic type of times added on top of nltk.sem.logic.

__str__()[source]

Return str(self).

class nltk_drt.presuppdrt.TimeVariableExpression(variable)[source]

This class represents variables that take the form of a single lowercase ‘i’ character followed by zero or more digits.

Classes

IndividualVariableExpression

class nltk_drt.presuppdrt.VariableReplacer(var: Variable, new_var: Variable, remove_ref: bool = True)[source]

A generic variable replacer functor to be used in readings

Parameters
  • var (Variable) – replaced variable

  • new_var (Variable) – replacement variable

  • remove_ref (bool) – remove reference (??)

__call__(drs: DRS) DRS[source]

Call self as a function.

__init__(var: Variable, new_var: Variable, remove_ref: bool = True)[source]
__weakref__

list of weak references to the object (if defined)

nltk_drt.presuppdrt.is_indvar(expr: str) bool[source]

An individual variable must be a single lowercase character other than ‘e’, ‘t’, ‘n’, ‘s’, followed by zero or more digits.

Parameters

expr (str) – expression

Returns

True if expr is of the correct form

Return type

bool

nltk_drt.presuppdrt.is_statevar(expr: str) bool[source]

An state variable must be a single lowercase ‘s’ character followed by zero or more digits.

Parameters

expr (str) – expression

Returns

True if expr is of the correct form

Return type

bool

nltk_drt.presuppdrt.is_timevar(expr: str) bool[source]

An time variable must be a single lowercase ‘t’ or ‘n’ character followed by zero or more digits. Do we need a separate type for utterance time n?

Parameters

expr (str) – expression

Returns

True if expr is of the correct form

Return type

bool

nltk_drt.presuppdrt.is_unary_predicate(expr)[source]

Check whether the given expression is an unary predicate

Classes

IndividualVariableExpression

nltk_drt.presuppdrt.is_uttervar(expr: str) bool[source]

An utterance time variable must be a single lowercase ‘n’ character followed by zero or more digits.

Parameters

expr (str) – expression

Returns

True if expr is of the correct form

Return type

bool

nltk_drt.presuppdrt.unique_variable(pattern: Optional[Variable] = None, ignore: Optional[Set[Variable]] = None) Variable[source]

Return a new, unique variable.

Parameters
  • pattern (Variable) – Variable that is being replaced. The new variable must be the same type.

  • ignore (Set[Variable]) – a set of Variable that should not be returned from this function.

Return type

Variable

Temporal extension of presuppdrt

class nltk_drt.temporaldrt.DefiniteDescriptionDRS(refs, conds, consequent=None)[source]
class nltk_drt.temporaldrt.DrtFindEventualityExpression(function, argument)[source]

Comprises reference point REFER condition and aspectual PERF condition. DRS-condition REFER(e) or REFER(s) returns a temporal condition that relates given eventuality and some previous event or state. In the simplified version of the reference point selection algorithm, the condition picks out the most recent event and, depending on the type of its argument, returns either an earlier(e*,e) or include(s,e*), where e* is the reference point and e/s is the given eventuality. In case there is no event in the previous discourse, the most recent state is taken as the reference point and overlap(s*,s) or include(s*,e) is introduced depending on the type of the given eventuality.

PERF(e) locates the most recent state referent s and resolves to a condition abut(e,s). PERF(s) locates the most recent state referent s* and resolves to a condition abut(e*,s*), e* = end(s) and adds a new event referent e*. Note that end(.) is an operator on states that returns events.

class nltk_drt.temporaldrt.DrtFindUtterTimeExpression(function, argument)[source]

Type of application expression looking to equate its argument with utterance time

class nltk_drt.temporaldrt.DrtLocationTimeApplicationExpression(function, argument)[source]

LOCPRO(t) condition from a non-finite verb. Gets resolved to the closest location time referent introduced by a finite auxiliary.

class nltk_drt.temporaldrt.DrtParser[source]

DrtParser producing conditions and referents for temporal logic

handle_PresuppositionDRS(tok, context)[source]

Parse all the Presuppositon DRSs

class nltk_drt.temporaldrt.DrtTimeApplicationExpression(function, argument)[source]
class nltk_drt.temporaldrt.DrtTokens[source]
exception nltk_drt.temporaldrt.LocationTimeResolutionException[source]
__weakref__

list of weak references to the object (if defined)

class nltk_drt.temporaldrt.NewInfoDRS(refs, conds, consequent=None)[source]
class nltk_drt.temporaldrt.PresuppositionDRS(refs, conds, consequent=None)[source]
exception nltk_drt.temporaldrt.UtteranceTimeTimeResolutionException[source]
__weakref__

list of weak references to the object (if defined)

Common Utilities for parsing and testing

exception nltk_drt.util.ComparisonFailed[source]
__weakref__

list of weak references to the object (if defined)

exception nltk_drt.util.FailedReading[source]
__weakref__

list of weak references to the object (if defined)

exception nltk_drt.util.NoReadingProduced[source]
__weakref__

list of weak references to the object (if defined)

exception nltk_drt.util.UngrammaticalException[source]
__weakref__

list of weak references to the object (if defined)

Extension of temporaldrt using WordNet ontology

class nltk_drt.wntemporaldrt.DefiniteDescriptionDRS(refs, conds)[source]
__init__(refs, conds)[source]
Parameters
  • refs – list of DrtIndividualVariableExpression for the discourse referents

  • conds – list of Expression for the conditions

semantic_check(individuals, presupp_individuals, strict=False)[source]

Users can plug in their more sophisticated semantic checks here. As for this project, we confine ourselves to ontologies provided by WordNet. See the other file for how this is supposed to work.

class nltk_drt.wntemporaldrt.DrtParser[source]
handle_PresuppositionDRS(tok, context)[source]

Parse all the Presuppositon DRSs

nltk_drt.wntemporaldrt.test()[source]

Test function

Indices and tables