eta.discourse

Tools for storing and processing discourse in Eta dialogues.

Functions

compress

Replace auxiliary-NOT combinations by -N'T contractions.

decompress

Expand contractions into full phrases (e.g. 'don't' or 'dont' by 'do not').

get_prior_turn

Retrieve the immediately prior turn by the specified agent(s).

get_prior_words

Retrieve the prior utterance in the conversation, using a generic utterance if none is found.

parse_utt_str

Parse an utterance string into a word string and affect.

presubst

Prepare a string for calling the swap_duals function to avoid ungrammatical substitutions.

swap_duals

Swap first-person pronouns (I, me, ...) with second-person pronouns (you, ...), and vice-versa.

Classes

DialogueTurn

Represents a dialogue turn by an agent, which contains the utterance as well as any associated dialogue information.

Utterance

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.

agent
Type:

str

words
Type:

str

affect
Type:

str

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.

agent

The agent of this turn (copied from the utterance for convenience).

Type:

str

utterance
Type:

Utterance

gists
Type:

list[str]

semantics
Type:

list[s-expr]

pragmatics
Type:

list[s-expr]

obligations
Type:

list[s-expr]

ep
Type:

str or None

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:

str

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’).

compress(str)[source]

Replace auxiliary-NOT combinations by -N’T contractions.

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.

swap_duals(str)[source]

Swap first-person pronouns (I, me, …) with second-person pronouns (you, …), and vice-versa.