Skip to content

File types

Every function reads the text to judge from a pipe, from --text, or from files. It reads plain text, one item per line, CSV, TSV and Excel files, and many files in one command.

Terminal window
echo 'Please refund my order.' |
thinkthen decide 'Does the customer request a refund?'

Output

true

Yes: the message asks for a refund. A pipe is one text, and its answer is one line. --text 'Please refund my order.' does the same without a pipe, and a file name after the question reads that file as one text.

--from lines makes each line its own text. This file holds three messages:

messages.txt
Please refund my order.
Where is my parcel?
I was charged twice for one invoice.
Terminal window
thinkthen decide --from lines \
'Does the customer request a refund?' messages.txt

Output

1	true
2	false
3	true

Lines 1 and 3 ask for a refund. Each answer starts with the line's number and a tab. Blank lines are skipped. filter, rank and annotate read lines without --from lines; the other functions read the whole input as one text.

A CSV file is a table of text with a header line. Name the column to judge with --column, and the new answer column with --into.

messages.csv
id,text
a1,Please refund my order.
a2,Where is my parcel?
a3,I was charged twice for one invoice.
Terminal window
thinkthen decide 'Does the customer request a refund?' \
--from csv --column text --into is_refund < messages.csv

Output

id,text,is_refund
a1,Please refund my order.,TRUE
a2,Where is my parcel?,FALSE
a3,I was charged twice for one invoice.,TRUE

The same table comes back with an is_refund column. Excel reads TRUE and FALSE as yes and no. A not sure answer, or a row that failed, leaves the cell empty, so it never reads as a no. Each failed row is named on standard error, and the command exits 6 (Exit codes).

Where the new table goes depends on how you give the file:

You give The new table goes to
--from csv < messages.csv the screen, as above
messages.csv a new file beside it, messages.thinkthen.csv, and the command prints that name
messages.csv --output reviewed.csv reviewed.csv
messages.csv --in-place messages.csv itself, after it keeps the original as messages.backup.csv. If filter fails on any row, messages.csv stays as it was and the command exits 6

ThinkThen never overwrites an output file. If messages.thinkthen.csv already exists, the command stops with exit code 2; choose a new --output name or remove the old file. Repeat --column to judge several columns of each row together. --details adds five more columns for each answer, such as its status and probability.

A TSV file is a CSV file with tabs between the columns. Use --from tsv, or name a file that ends in .tsv.

messages.tsv
id text
a1 Please refund my order.
a2 Where is my parcel?
a3 I was charged twice for one invoice.
Terminal window
thinkthen decide 'Does the customer request a refund?' \
--from tsv --column text --into is_refund < messages.tsv

Output

id	text	is_refund
a1	Please refund my order.	TRUE
a2	Where is my parcel?	FALSE
a3	I was charged twice for one invoice.	TRUE

The same table comes back, with tabs, and the is_refund column added.

An Excel file (.xlsx) works by name, never from a pipe. This workbook holds one worksheet, Messages:

messages.xlsx, worksheet Messages
idtext
a1Please refund my order.
a2Where is my parcel?
a3I was charged twice for one invoice.
Terminal window
thinkthen decide 'Does the customer request a refund?' \
messages.xlsx --column text --into is_refund

Output

messages.thinkthen.xlsx

The command writes messages.thinkthen.xlsx beside the input and prints its name. Its is_refund column holds real TRUE and FALSE cells, and #N/A for not sure or a failed message, so an Excel formula can't mistake either for a no.

Every other worksheet, style and formula stays as it was. When a workbook holds more than one worksheet, name one with --sheet Messages. Formula cells are read from their saved values and never recalculated. Older .xls files, macro-enabled workbooks and signed workbooks are refused; save an unsigned .xlsx copy first.

Name every file after the question. Here the shell expands messages/*.txt to three files, each holding one message:

messages/a1.txt
Please refund my order.
messages/a2.txt
Where is my parcel?
messages/a3.txt
I was charged twice for one invoice.
Terminal window
thinkthen decide 'Does the customer request a refund?' \
messages/*.txt

Output

messages/a1.txt	true
messages/a2.txt	false
messages/a3.txt	true

a1 and a3 ask for a refund. Each file is one text, and each answer starts with its file name and a tab. Add - among the files to read the pipe too. A CSV, TSV or Excel file goes alone, one per command.

A file's ending picks its type: .csv, .tsv, .xlsx and .jsonl. Anything else, and a pipe, is plain text. --from names the type outright: text, lines, jsonl, csv, tsv or xlsx. In a script, say --from so the type never depends on a file's name. JSON Lines covers .jsonl files.

JSON Lines judges one field of each JSON object and adds the answer to it.