Skip to content

rank

rank places every line of its input on a scale of levels you name, from lowest to highest, and prints the lines from highest to lowest. --top keeps only the first few.

Terminal window
thinkthen rank --level routine --level urgent \
'How urgent is the request?' messages.txt

Output

I was charged twice for one invoice.
Where is my parcel?
Please refund my order.
messages.txt
Please refund my order.
Where is my parcel?
I was charged twice for one invoice.

Most urgent first: the double charge, then the parcel question, then the refund request.

Terminal window
thinkthen rank --level routine --level urgent --top 2 \
'How urgent is the request?' messages.txt

Output

I was charged twice for one invoice.
Where is my parcel?

--top 2 keeps the two most urgent lines and drops the rest.

See why

--json prints the details. This jq keeps three of them for each line.

Terminal window
thinkthen rank --json --level routine --level urgent \
'How urgent is the request?' messages.txt |
jq -c '{position, answer, levels: .detail.levels}'

Output

{"position":3,"answer":1,"levels":[0.55,0.45]}
{"position":2,"answer":2,"levels":[0.86,0.14]}
{"position":1,"answer":3,"levels":[0.95,0.05]}

position is the line's place in the input, answer is its rank, and levels holds the chance of each level, lowest first. Lines with equal scores keep their input order. JSON output lists every field.

Rank every row of a CSV file
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 rank 'How urgent is the request?' \
--level routine --level urgent --from csv \
--column text --into urgency_rank < messages.csv

Output

id,text,urgency_rank
a1,Please refund my order.,3
a2,Where is my parcel?,2
a3,I was charged twice for one invoice.,1

--column names the column to read, and --into names the new rank column. The rows stay in their order, each with its rank. With --top, a row outside the top gets an empty cell. File types covers TSV, Excel and other files.

Options
OptionWhat it does
<QUESTION>Question to ask
[FILE]...Input files; default: standard input
--name <NAME>Optional execution identity
--text <TEXT>Judge this text instead of reading input
--level <LEVEL>Scale level; repeat low to high
--top <TOP>Maximum answered ranks
--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

If rank can't answer a line, it prints an error and exits with code 2, 4, 5 or 6. Troubleshooting lists each error and its fix.

In code: Python · TypeScript · Go · Java · Kotlin · C# · R · Ruby · Rust · Swift · Zig · C · C++ · DuckDB · SQLite · PostgreSQL

Next: find points to the line in a text that answers a question.