Skip to content

relate

relate finds the names in a piece of text and prints each connection between them that one of your rules describes, returning several connections or none. A rule gives the connection a name, then the kind of name it starts from and the kind it points to.

Terminal window
echo 'Morgan works for Example Group.' |
thinkthen relate --rule works_for person organization

Output

Morgan --works_for--> Example Group

One connection: the rule works_for person organization matches Morgan, a person, and Example Group, an organization.

Terminal window
echo 'Please refund my order.' |
thinkthen relate --rule works_for person 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 connection's name and its chance.

Terminal window
echo 'Morgan works for Example Group.' |
thinkthen relate --json \
--rule works_for person organization |
jq -c '.answer[] | {relation, probability}'

Output

{"relation":"works_for","probability":0.96}

relate keeps each connection whose chance reaches the bar, 0.5 by default. JSON output lists every field, including each name and where it sits in the text.

Move the bar

Raise the bar to 0.99 and the connection is dropped, because it has 0.97.

Terminal window
echo 'Morgan works for Example Group.' |
thinkthen relate --threshold 0.99 \
--rule works_for person organization

Output

(an empty line)


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

Relate 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 relate --rule works_for person organization \
--from csv --column text --into relations < messages.csv

Output

id,text,relations
b1,Morgan works for Example Group.,Morgan works_for Example Group
b2,Please refund my order.,

--column names the column to read, and --into names the new answer column. Each cell lists its connections as source relation target, joined by ; . File types covers TSV, Excel and other files.

Options

Repeat --rule for each connection you want. --either lets every rule point both ways.

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
--rule <NAME> <SOURCE> <TARGET>NAME SOURCE TARGET; repeat
--either [=<EITHER>]Override every rule direction
--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 relate 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: annotate asks several questions about each line at once.