nltk.sem.linearlogic module

class nltk.sem.linearlogic.Tokens[source]

Bases: object

OPEN = '('
CLOSE = ')'
IMP = '-o'
PUNCT = ['(', ')']
TOKENS = ['(', ')', '-o']
class nltk.sem.linearlogic.LinearLogicParser[source]

Bases: nltk.sem.logic.LogicParser

A linear logic expression parser.

__init__()[source]
Parameters

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

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

get_BooleanExpression_factory(tok)[source]

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

make_BooleanExpression(factory, first, second)[source]
attempt_ApplicationExpression(expression, context)[source]

Attempt to make an application expression. If the next tokens are an argument in parens, then the argument expression is a function being applied to the arguments. Otherwise, return the argument expression.

make_VariableExpression(name)[source]
class nltk.sem.linearlogic.Expression[source]

Bases: object

classmethod fromstring(s)[source]
applyto(other, other_indices=None)[source]
class nltk.sem.linearlogic.AtomicExpression[source]

Bases: nltk.sem.linearlogic.Expression

__init__(name, dependencies=None)[source]
Parameters
  • name – str for the constant name

  • dependencies – list of int for the indices on which this atom is dependent

simplify(bindings=None)[source]

If ‘self’ is bound by ‘bindings’, return the atomic to which it is bound. Otherwise, return self.

Parameters

bindingsBindingDict A dictionary of bindings used to simplify

Returns

AtomicExpression

compile_pos(index_counter, glueFormulaFactory)[source]

From Iddo Lev’s PhD Dissertation p108-109

Parameters
  • index_counterCounter for unique indices

  • glueFormulaFactoryGlueFormula for creating new glue formulas

Returns

(Expression,set) for the compiled linear logic and any newly created glue formulas

compile_neg(index_counter, glueFormulaFactory)[source]

From Iddo Lev’s PhD Dissertation p108-109

Parameters
  • index_counterCounter for unique indices

  • glueFormulaFactoryGlueFormula for creating new glue formulas

Returns

(Expression,set) for the compiled linear logic and any newly created glue formulas

initialize_labels(fstruct)[source]
class nltk.sem.linearlogic.ConstantExpression[source]

Bases: nltk.sem.linearlogic.AtomicExpression

unify(other, bindings)[source]

If ‘other’ is a constant, then it must be equal to ‘self’. If ‘other’ is a variable, then it must not be bound to anything other than ‘self’.

Parameters
  • otherExpression

  • bindingsBindingDict A dictionary of all current bindings

Returns

BindingDict A new combined dictionary of of ‘bindings’ and any new binding

Raises

UnificationException – If ‘self’ and ‘other’ cannot be unified in the context of ‘bindings’

class nltk.sem.linearlogic.VariableExpression[source]

Bases: nltk.sem.linearlogic.AtomicExpression

unify(other, bindings)[source]

‘self’ must not be bound to anything other than ‘other’.

Parameters
  • otherExpression

  • bindingsBindingDict A dictionary of all current bindings

Returns

BindingDict A new combined dictionary of of ‘bindings’ and the new binding

Raises

UnificationException – If ‘self’ and ‘other’ cannot be unified in the context of ‘bindings’

class nltk.sem.linearlogic.ImpExpression[source]

Bases: nltk.sem.linearlogic.Expression

__init__(antecedent, consequent)[source]
Parameters
  • antecedentExpression for the antecedent

  • consequentExpression for the consequent

simplify(bindings=None)[source]
unify(other, bindings)[source]

Both the antecedent and consequent of ‘self’ and ‘other’ must unify.

Parameters
  • otherImpExpression

  • bindingsBindingDict A dictionary of all current bindings

Returns

BindingDict A new combined dictionary of of ‘bindings’ and any new bindings

Raises

UnificationException – If ‘self’ and ‘other’ cannot be unified in the context of ‘bindings’

compile_pos(index_counter, glueFormulaFactory)[source]

From Iddo Lev’s PhD Dissertation p108-109

Parameters
  • index_counterCounter for unique indices

  • glueFormulaFactoryGlueFormula for creating new glue formulas

Returns

(Expression,set) for the compiled linear logic and any newly created glue formulas

compile_neg(index_counter, glueFormulaFactory)[source]

From Iddo Lev’s PhD Dissertation p108-109

Parameters
  • index_counterCounter for unique indices

  • glueFormulaFactoryGlueFormula for creating new glue formulas

Returns

(Expression,list of GlueFormula) for the compiled linear logic and any newly created glue formulas

initialize_labels(fstruct)[source]
class nltk.sem.linearlogic.ApplicationExpression[source]

Bases: nltk.sem.linearlogic.Expression

__init__(function, argument, argument_indices=None)[source]
Parameters
  • functionExpression for the function

  • argumentExpression for the argument

  • argument_indices – set for the indices of the glue formula from which the argument came

Raises

LinearLogicApplicationException – If ‘function’ cannot be applied to ‘argument’ given ‘argument_indices’.

simplify(bindings=None)[source]

Since function is an implication, return its consequent. There should be no need to check that the application is valid since the checking is done by the constructor.

Parameters

bindingsBindingDict A dictionary of bindings used to simplify

Returns

Expression

class nltk.sem.linearlogic.BindingDict[source]

Bases: object

__init__(bindings=None)[source]
Parameters

bindings – list [(VariableExpression, AtomicExpression)] to initialize the dictionary dict {VariableExpression: AtomicExpression} to initialize the dictionary

exception nltk.sem.linearlogic.VariableBindingException[source]

Bases: Exception

exception nltk.sem.linearlogic.UnificationException[source]

Bases: Exception

__init__(a, b, bindings)[source]
exception nltk.sem.linearlogic.LinearLogicApplicationException[source]

Bases: Exception

nltk.sem.linearlogic.demo()[source]