Skip to content

recognize

recognize picks out every name in a piece of text that belongs to one of the kinds you list, whether there are several or none. It prints each name with its kind and where it sits in the text, separated by tabs.

Terminal window
echo 'Morgan works for Example Group.' |
thinkthen recognize --kind person --kind organization

Output

person: Morgan (0..6)	organization: Example Group (17..30)

Two names: Morgan is a person, from character 0 to 6, and Example Group is an organization, from character 17 to 30.

Terminal window
echo 'Please refund my order.' |
thinkthen recognize --kind person --kind organization

Output

(an empty line)


The message names no person and no organization, so the answer is empty.

See why

--json prints the details. This jq keeps each name, its kind and its chance.

Terminal window
echo 'Morgan works for Example Group.' |
thinkthen recognize --json \
--kind person --kind organization |
jq -c '.answer[] | {text, kind, probability}'

Output

{"text":"Morgan","kind":"person","probability":1.0}
{"text":"Example Group","kind":"organization","probability":0.9702}

recognize keeps each name whose chance reaches the bar, 0.5 by default. JSON output lists every field.

Move the bar

Raise the bar to 0.99 and only Morgan is kept, because Example Group has 0.9702.

Terminal window
echo 'Morgan works for Example Group.' |
thinkthen recognize --threshold 0.99 \
--kind person --kind organization

Output

person: Morgan (0..6)

Lower the bar to catch more names. Raise it to keep only the clear ones.

Recognize names in every row of a CSV file

Section titled “Recognize names in every row of a CSV file”
Recognize names in every row of a CSV file
messages.csv
id,text
b1,Morgan works for Example Group.
b2,Please refund my order.
Terminal window
thinkthen recognize --kind person --kind organization \
--from csv --column text --into names < messages.csv

Output

id,text,names
b1,Morgan works for Example Group.,Morgan (person); Example Group (organization)
b2,Please refund my order.,

--column names the column to read, and --into names the new answer column. Each cell lists its names as name (kind), joined by ; . File types covers TSV, Excel and other files.

Options
OptionWhat it does
[FILE]...Input files; default: standard input
--name <NAME>Optional execution identity
--text <TEXT>Judge this text instead of reading input
--threshold <THRESHOLD>Required probability
--kind <KIND>Kind; repeat in order
--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 recognize can't answer a text, 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: relate finds how the names in a text are connected.