Checking a text¶
glofas_ewds.text ¶
Is every number of a text in the facts it was written from?
Pure: nothing here does I/O.
The rule of every AI feature of this package: the numbers come from the data,
a model may explain them, never invent them. :func:check_text is the part of
the rule a program can enforce. Give it a text (a model's answer, a press
note, a paragraph someone rewrote) and the facts it was written from, and it
returns the numbers of the text that are in none of the facts.
It catches a number that is not there. It does not catch a number said of the
wrong thing ("the peak is 112.1" when 112.1 is the 20-year threshold): the
figure exists, the sentence is wrong. benchmarks/faithful.py measures how
often that happens.
numbers ¶
numbers(text: str) -> list[str]
The numbers of a text, as written and in order.
3,510 is one number (a comma between groups of three digits is a
thousands separator), 2nd is 2, 2026-11-28 is three numbers, and
digits inside a word (v4) are not a number.
figures ¶
figures(value: Any) -> Iterator[float]
Every number in a tree of facts: values, keys, and the numbers inside strings.
Digits glued to a letter are part of a name, not a number: peak_m3s
and seamless_v4 hold none. A time stamp counts by its parts.
check_text ¶
check_text(text: str, facts: Any) -> list[str]
The numbers of text that are not in facts, as written (empty: all found).
A number of the text is found when a figure of the facts, rounded to the
decimals the text uses, is that number: 163 and 162.7 both match
162.68, 160 does not. Dates count by their parts (16 May 2023
matches 2023-05-16). Percentages are not converted: a share of 0.61
is found as 0.61, not as 61, so give the facts the figure you
want quoted.