Writing CHAT Data#

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

to_chat(path[, is_dir, filenames, tabular, ...])

Export to CHAT data files.

to_strs([tabular])

Yield CHAT data strings.

These methods are useful for saving CHAT data for re-use or distribution, especially when your data or Reader 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
>>> reader = pylangacq.Reader.from_strs(["*MOT: hey sweetie ."])
>>> reader.to_chat("data.cha")

If your Reader 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("https://childes.talkbank.org/data/Eng-NA/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(exclude="Adam")
>>> 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.