nltk.inference.DiscourseTester¶
- class nltk.inference.DiscourseTester[source]¶
Bases:
object
Check properties of an ongoing discourse.
- __init__(input, reading_command=None, background=None)[source]¶
Initialize a
DiscourseTester
.- Parameters
input (list of str) – the discourse sentences
background (list(Expression)) – Formulas which express background assumptions
- add_sentence(sentence, informchk=False, consistchk=False)[source]¶
Add a sentence to the current discourse.
Updates
self._input
andself._sentences
. :param sentence: An input sentence :type sentence: str :param informchk: ifTrue
, check that the result of adding the sentence is thread-informative. Updatesself._readings
. :param consistchk: ifTrue
, check that the result of adding the sentence is thread-consistent. Updatesself._readings
.
- retract_sentence(sentence, verbose=True)[source]¶
Remove a sentence from the current discourse.
Updates
self._input
,self._sentences
andself._readings
. :param sentence: An input sentence :type sentence: str :param verbose: IfTrue
, report on the updated list of sentences.
- readings(sentence=None, threaded=False, verbose=True, filter=False, show_thread_readings=False)[source]¶
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(thread_id, threads=None)[source]¶
Given a thread ID, find the list of
logic.Expression
objects 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
A list of pairs
(rid, reading)
where reading is thelogic.Expression
associated with a reading ID- Return type
list of tuple
- models(thread_id=None, show=True, verbose=False)[source]¶
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(background, verbose=False)[source]¶
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. :param background: Formulas which contain background information :type background: list(Expression)
- static multiply(discourse, readings)[source]¶
Multiply every thread in
discourse
by every reading inreadings
.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(Expression)) – an additional list of readings
- Return type
A list of lists