notice

This is unreleased documentation for Rasa Documentation Main/Unreleased version.
For the latest released documentation, see the latest version (3.x).

Version: Main/Unreleased

rasa.shared.nlu.training_data.formats.readerwriter

TrainingDataReader Objects

class TrainingDataReader(abc.ABC)

Reader for NLU training data.

__init__

def __init__() -> None

Creates reader instance.

read

def read(filename: Union[Text, Path], **kwargs: Any) -> "TrainingData"

Reads TrainingData from a file.

reads

@abc.abstractmethod
def reads(s: Text, **kwargs: Any) -> "TrainingData"

Reads TrainingData from a string.

TrainingDataWriter Objects

class TrainingDataWriter()

A class for writing training data to a file.

dump

def dump(filename: Text, training_data: "TrainingData") -> None

Writes a TrainingData object to a file.

dumps

def dumps(training_data: "TrainingData") -> Text

Turns TrainingData into a string.

prepare_training_examples

@staticmethod
def prepare_training_examples(
training_data: "TrainingData") -> Dict[Text, List[Union[Dict, Text]]]

Pre-processes training data examples by removing not trainable entities.

generate_list_item

@staticmethod
def generate_list_item(text: Text) -> Text

Generates text for a list item.

generate_message

@staticmethod
def generate_message(message: Dict[Text, Any]) -> Text

Generates text for a message object.

Arguments:

  • message - A message

Returns:

The text of the message, annotated with the entity data that is contained in the message

generate_entity_attributes

@staticmethod
def generate_entity_attributes(text: Text,
entity: Dict[Text, Any],
short_allowed: bool = True) -> Text

Generates text for the entity attributes.

Arguments:

  • text - The text that is annotated with the entity
  • entity - Entity data
  • short_allowed - If True, allow shorthand annotation with parenthesis

Returns:

The annotation text that should follow the given text

generate_entity

@staticmethod
def generate_entity(
text: Text, entity: Union[Dict[Text, Any], List[Dict[Text,
Any]]]) -> Text

Generates text for one or multiple entity objects.

Arguments:

  • text - The un-annotated text
  • entity - One or multiple entity annotations for one part of this text

Returns:

Annotated part of the text

JsonTrainingDataReader Objects

class JsonTrainingDataReader(TrainingDataReader)

A class for reading JSON files.

reads

def reads(s: Text, **kwargs: Any) -> "TrainingData"

Transforms string into json object and passes it on.

read_from_json

def read_from_json(js: Dict[Text, Any], **kwargs: Any) -> "TrainingData"

Reads TrainingData from a json object.