Skip to content

annotate

annotate asks a form of named questions and preserves each entry’s state.

Terminal window
thinkthen annotate questions.json messages.txt

Output

1	refund=true	topic=billing	urgency=0.05
2	refund=false	topic=shipping	urgency=0.16
3	refund=true	topic=billing	urgency=0.46
messages.txt
Please refund my order.
Where is my parcel?
I was charged twice for one invoice.
questions.json
{
"questions": {
"refund": {
"function": "decide",
"question": "Does the customer request a refund?"
},
"topic": {
"function": "choose",
"question": "What is the message about?",
"choices": ["billing", "shipping", "other"]
},
"urgency": {
"function": "score",
"question": "How urgent is the request?",
"levels": ["routine", "urgent"]
}
}
}

annotate asks several questions of each message and gives back one form per message. The questions go in a file. Save this as questions.json:

{
"questions": {
"refund": {"function": "decide", "question": "Does the customer request a refund?"},
"topic": {"function": "choose", "question": "What is the message about?", "choices": ["billing", "shipping", "other"]},
"urgency": {"function": "score", "question": "How urgent is the request?", "levels": ["routine", "urgent"]}
}
}
Terminal window
thinkthen annotate questions.json messages.txt --json |
jq -r '
if .status == "failed" then "try again later: \(.item)"
elif ([.answer.refund, .answer.topic, .answer.urgency]
| any(.status == "failed")) then
"try again later: \(.item)"
elif ([.answer.refund, .answer.topic, .answer.urgency]
| any(.status == "unsure")) then
"a person reads it: \(.item)"
elif ([.answer.refund, .answer.topic, .answer.urgency]
| all(.status == "answered")) then
if .answer.refund.answer then
"refund queue: \(.answer.topic.answer)" +
" \(.answer.urgency.answer * 100 | round / 100)"
else empty
end
else empty
end'

Each entry of a form is a result of its own function, with its own status. One entry can be not sure while the others answer. The example checks every entry it uses before reading any answer. The command exits 6 when a form or any entry in it failed; a not-sure entry is not a failure. Without --json, a form prints one tab-separated line of names and their printed result states.

Add an answer column for each question to a CSV file

Section titled “Add an answer column for each question to a CSV file”
Read the CSV file and save its answers

--column selects the CSV column to judge; --into names the answer column. Check the exit status before using the saved file.

messages.csv
message
Please refund my order.
Where is my parcel?
I was charged twice for one invoice.
questions.json
{
"questions": {
"refund": {
"function": "decide",
"question": "Does the customer request a refund?"
},
"topic": {
"function": "choose",
"question": "What is the message about?",
"choices": ["billing", "shipping", "other"]
},
"urgency": {
"function": "score",
"question": "How urgent is the request?",
"levels": ["routine", "urgent"]
}
}
}
Terminal window
thinkthen annotate questions.json messages.csv --column message
cat messages.thinkthen.csv

Output

messages.thinkthen.csv
message,refund,topic,urgency
Please refund my order.,TRUE,billing,0.05
Where is my parcel?,FALSE,shipping,0.16
I was charged twice for one invoice.,TRUE,billing,0.46
Options
OptionWhat it does
<TOOLBOX>Toolbox path or saved entry name
[FILE]...Input files; default: standard input
--name <NAME>Optional execution identity
--text <TEXT>Judge this text instead of reading input
--column <COLUMN>Field column; repeat; replaces a saved pointer
--details [=<DETAILS>]Add status, probability, error, detail and source columns
--in-place [=<IN-PLACE>]Replace source with backup
--into <INTO>Answer field for JSON Lines; column for tables
--output <OUTPUT>Destination path
--sheet <SHEET>Worksheet

Shared options