eta.discourse
Tools for storing and processing discourse in Eta dialogues.
Functions
Replace auxiliary-NOT combinations by -N'T contractions. |
|
Expand contractions into full phrases (e.g. 'don't' or 'dont' by 'do not'). |
|
Retrieve the immediately prior turn by the specified agent(s). |
|
Retrieve the prior utterance in the conversation, using a generic utterance if none is found. |
|
Parse an utterance string into a word string and affect. |
|
Prepare a string for calling the swap_duals function to avoid ungrammatical substitutions. |
|
Swap first-person pronouns (I, me, ...) with second-person pronouns (you, ...), and vice-versa. |
Classes
Represents a dialogue turn by an agent, which contains the utterance as well as any associated dialogue information. |
|
Represents a single utterance, which contains both the words of the utterance and an affect. |
- class Utterance(agent, words, affect='neutral')[source]
Bases:
object
Represents a single utterance, which contains both the words of the utterance and an affect.
- Parameters:
agent –
- wordsstr
The content of the utterance.
- affectstr, default=’neutral’
The affect of the utterance. Must be contained within the list of supported emotions.
- class DialogueTurn(utterance, gists=[], semantics=[], pragmatics=[], obligations=[], ep=None)[source]
Bases:
object
Represents a dialogue turn by an agent, which contains the utterance as well as any associated dialogue information.
- Parameters:
utterance (Utterance) – The utterance of this turn.
gists (list[str], optional) – A list of gist clauses capturing the meaning of this turn.
semantics (list[s-expr], optional) – A list of semantic interpretations of this turn.
pragmatics (list[s-expr], optional) – A list of pragmatic inferences drawn from this turn.
obligations (list[s-expr], optional) – A list of obligations created by this turn.
ep (str, optional) – The episode that this turn corresponds to.
- get_prior_turn(turns, agent=None)[source]
Retrieve the immediately prior turn by the specified agent(s).
- Parameters:
turns (list[DialogueTurn]) – A list of dialogue turns in the conversation, in chronological order.
agent (str, optional) – The agent whose prior turn should be found (by default, find the prior turn by any agent).
- Returns:
The prior turn by the given agent (if one exists).
- Return type:
DialogueTurn or None
- get_prior_words(turns, agent=None)[source]
Retrieve the prior utterance in the conversation, using a generic utterance if none is found.
- Parameters:
turns (list[DialogueTurn]) – A list of dialogue turns in the conversation, in chronological order.
agent (str, optional) – The agent whose prior words should be found (by default, find the prior turn by any agent).
- Returns:
The prior words by the given agent, if one exists, or a generic utterance.
- Return type:
- parse_utt_str(str)[source]
Parse an utterance string into a word string and affect.
- Parameters:
str (str) – A string representing an utterance, potentially prefixed by an emotion tag, e.g.,
[happy]
or[sad]
.- Returns:
affect (str) – The affect/emotion of the utterance.
words (str) – The word string of the utterance.
- decompress(str)[source]
Expand contractions into full phrases (e.g. ‘don’t’ or ‘dont’ by ‘do not’).
- presubst(str)[source]
Prepare a string for calling the swap_duals function to avoid ungrammatical substitutions.
For example, in swapping dual pronouns, we want to avoid outputs such as “why do you say i are stupid”, while still correctly producing “why do you say your brothers are stupid”.
This function replaces “are” by “are2” when preceded or followed by “you”; similarly, it replaces
“were” by “were2” and “was” by “was2”.
It also replaces “you” by “you2” when it is the last word, or when it is not one of the first two
- words and is not preceded by certain conjunctions (“and”, “or”, “but”, “that”, “because”, “if”,
“when”, “then”, “why”, …), or certain subordinating verbs (“think”, “believe”, “know”, …), or
when it follows “to”.
This is in preparation for replacement of “you2” by “me” (rather than “i”) when swap_duals is applied.