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.
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.
Judge each line
Section titled “Judge each line”--from lines makes each line its own text. This file holds three messages:
Please refund my order.Where is my parcel?I was charged twice for one invoice.thinkthen decide --from lines \ 'Does the customer request a refund?' messages.txtOutput
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.
Add an answer column to a CSV file
Section titled “Add an answer column to a CSV file”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.
id,texta1,Please refund my order.a2,Where is my parcel?a3,I was charged twice for one invoice.thinkthen decide 'Does the customer request a refund?' \ --from csv --column text --into is_refund < messages.csvOutput
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.
Read a TSV file
Section titled “Read a TSV file”A TSV file is a CSV file with tabs between the columns. Use --from tsv, or name a file that ends in .tsv.
id texta1 Please refund my order.a2 Where is my parcel?a3 I was charged twice for one invoice.thinkthen decide 'Does the customer request a refund?' \ --from tsv --column text --into is_refund < messages.tsvOutput
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.
Add an answer column to an Excel file
Section titled “Add an answer column to an Excel file”An Excel file (.xlsx) works by name, never from a pipe. This workbook holds one worksheet, Messages:
| id | text |
|---|---|
| a1 | Please refund my order. |
| a2 | Where is my parcel? |
| a3 | I was charged twice for one invoice. |
thinkthen decide 'Does the customer request a refund?' \ messages.xlsx --column text --into is_refundOutput
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.
Judge many files at once
Section titled “Judge many files at once”Name every file after the question. Here the shell expands messages/*.txt to three files, each holding one message:
Please refund my order.Where is my parcel?I was charged twice for one invoice.thinkthen decide 'Does the customer request a refund?' \ messages/*.txtOutput
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.
How ThinkThen picks the type
Section titled “How ThinkThen picks the type”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.