Writing CHAT Data

To output CHAT data, a CHAT object can either export data to local files or write its data to strings.

to_chat(path, *[, is_dir, filenames])

Write CHAT data to disk.

to_strs()

Return CHAT data strings, one per file.

These methods are useful for saving CHAT data for re-use or distribution, especially when your data or CHAT object is customized in some way, e.g., by adding or removing data from an existing dataset, or through an in-memory CHAT data string – see Reading CHAT Data.

import pylangacq
chat_data = pylangacq.CHAT.from_strs(["*MOT:\they sweetie ."])
chat_data.to_chat("data.cha")

If your CHAT object has data organized in multiple CHAT files, to_chat() supports writing CHAT data files in a local directory:

import pylangacq
brown = pylangacq.read_chat("path/to/your/local/Brown.zip")
# Brown has data for Adam, Eve, and Sarah.
# Now we want to save only Eve and Sarah's data somewhere on disk.
eve_and_sarah = brown.filter(files="Eve|Sarah")
eve_and_sarah.to_chat("your/new/directory", is_dir=True)

By default, the files are named 0001.cha, 0002.cha, etc. To customize the filenames, to_chat() has the filenames keyword argument.

If you would like the CHAT data as strings in memory for use cases other than local file export, to_strs() is available.