Package nltk :: Package inference :: Module discourse :: Class DiscourseTester
[hide private]
[frames] | no frames]

Class DiscourseTester

source code

object --+
         |
        DiscourseTester

Check properties of an ongoing discourse.

Instance Methods [hide private]
 
__init__(self, input, gramfile=None, background=None)
Initialize a DiscourseTester.
source code
 
sentences(self)
Display the list of sentences in the current discourse.
source code
 
add_sentence(self, sentence, informchk=False, consistchk=False)
Add a sentence to the current discourse.
source code
 
retract_sentence(self, sentence, quiet=False)
Remove a sentence from the current discourse.
source code
 
grammar(self)
Print out the grammar in use for parsing input sentences
source code
list of logic.Expression.
_get_readings(self, sentence)
Build a list of semantic readings for a sentence.
source code
 
_construct_readings(self)
Use self._sentences to construct a value for self._readings.
source code
 
_construct_threads(self)
Use self._readings to construct a value for self._threads and use the model builder to construct a value for self._filtered_threads
source code
 
_show_readings(self, sentence=None)
Print out the readings for the discourse (or a single sentence).
source code
 
_show_threads(self, filter=False)
Print out the value of self._threads or self._filtered_hreads
source code
 
readings(self, sentence=None, threaded=False, quiet=False, filter=False)
Construct and show the readings of the discourse (or of a single sentence).
source code
list of tuple
expand_threads(self, thread_id, threads=None)
Given a thread ID, find the list of logic.Expressions corresponding to the reading IDs in that thread.
source code
 
_check_consistency(self, threads, show=False, quiet=True) source code
 
models(self, thread_id=None, show=True, quiet=True)
Call Mace4 to build a model for each current discourse thread.
source code
 
add_background(self, background, quiet=True)
Add a list of background assumptions for reasoning about the discourse.
source code
 
background(self)
Show the current background assumptions.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Static Methods [hide private]
A list of lists
multiply(discourse, readings)
Multiply every thread in discourse by every reading in readings.
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, input, gramfile=None, background=None)
(Constructor)

source code 

Initialize a DiscourseTester.

Parameters:
  • input (list of str) - the discourse sentences
  • gramfile (str) - name of file where grammar can be loaded
  • background (list of logic.Expression.) - Formulas which express background assumptions
Overrides: object.__init__

add_sentence(self, sentence, informchk=False, consistchk=False)

source code 

Add a sentence to the current discourse.

Updates self._input and self._sentences.

Parameters:
  • sentence (str) - An input sentence
  • informchk - if True, check that the result of adding the sentence is thread-informative. Updates self._readings.
  • consistchk - if True, check that the result of adding the sentence is thread-consistent. Updates self._readings.

retract_sentence(self, sentence, quiet=False)

source code 

Remove a sentence from the current discourse.

Updates self._input, self._sentences and self._readings.

Parameters:
  • sentence (str) - An input sentence
  • quiet - If False, report on the updated list of sentences.

readings(self, sentence=None, threaded=False, quiet=False, filter=False)

source code 

Construct and show the readings of the discourse (or of a single sentence).

Parameters:
  • sentence (str) - test just this sentence
  • threaded - if True, print out each thread ID and the corresponding thread.
  • filter - if True, only print out consistent thread IDs and threads.

expand_threads(self, thread_id, threads=None)

source code 

Given a thread ID, find the list of logic.Expressions corresponding to the reading IDs in that thread.

Parameters:
  • thread_id (str) - thread ID
  • threads (dict) - a mapping from thread IDs to lists of reading IDs
Returns: list of tuple
A list of pairs (rid, reading) where reading is the logic.Expression associated with a reading ID

models(self, thread_id=None, show=True, quiet=True)

source code 

Call Mace4 to build a model for each current discourse thread.

Parameters:
  • thread_id (str) - thread ID
  • show - If True, display the model that has been found.

add_background(self, background, quiet=True)

source code 

Add a list of background assumptions for reasoning about the discourse.

When called, this method also updates the discourse model's set of readings and threads.

Parameters:
  • background (list of logic.Expression.) - Formulas which contain background information

multiply(discourse, readings)
Static Method

source code 

Multiply every thread in discourse by every reading in readings.

Given discourse = [['A'], ['B']], readings = ['a', 'b', 'c'] , returns [['A', 'a'], ['A', 'b'], ['A', 'c'], ['B', 'a'], ['B', 'b'], ['B', 'c']]

Parameters:
  • discourse (list of lists) - the current list of readings
  • readings (list of logic.Expressions) - an additional list of readings
Returns: A list of lists