Checking a text
egms_client.check ¶
Check a text against the facts it was written from: no number invented, swapped, or flipped.
The facts (:mod:egms_client.facts) hold every number of an answer. A text
for people, written by a template (:func:words) or by a language model,
should quote them and nothing else. Three checks, from the loosest:
- :func:
check_text: every number of the text is a figure of the facts, to the decimals written (145and145.2match 145.24;146does not). A percentage is read as a share (76%matches 0.762). - :func:
check_signs: a number said to go down (sinks by 4.0, scende di 4,0,-4.0) is a negative figure of the facts, and one said to go up a positive one. The worst fault in ground motion is the sign: a model that reads -4.0 mm/year as "rises 4 mm a year" quotes a number that exists. - :func:
check_claims: in the sentences of :func:words, each number is the one of its fact. "The vertical velocity is -4.5" where the facts give -4.5 to the regional median is a swap that the first check cannot see.
Texts can be in English (lang="en": 1,234.5) or Italian
(lang="it": 1.234,5). Digits inside a word (E47N19, L3) are
not numbers. Pure: no network, no model.
Number
dataclass
¶
A number as written: its text, its value, decimals, sign and percent.
Misquote
dataclass
¶
A number of the text said of a fact that holds another value.
said is the piece of text, key the fact (a dotted path into the
facts, "" when the sentence names none), fact what it holds there.
Sentence
dataclass
¶
A sentence of :func:words: its text in each language, with {key|fmt} holes.
numbers ¶
numbers(text: str, lang: Lang = 'en') -> list[Number]
The numbers of a text, in order (see the module for how they are read).
figures ¶
figures(facts: Any) -> Iterator[float]
Every number of a tree of facts, with its sign: values, and the digits in strings.
same ¶
same(n: Number, fact: Any) -> bool
Is fact the number n, to the decimals written (sign aside)?
check_text ¶
check_text(text: str, facts: Any, *, lang: Lang = 'en', question: str = '') -> list[str]
The numbers of text that no figure of facts gives (empty: all found).
Numbers written in question are allowed: an answer may repeat them.
directions ¶
directions(text: str, lang: Lang = 'en') -> list[int]
For each number of :func:numbers, the direction the text gives it.
-1 when a minus sign is written before it or a word of descent comes
right before it (sinks by, goes down, scende di, si abbassa di);
+1 with + or a word of rise; 0 otherwise, and for percentages.
check_signs ¶
check_signs(text: str, facts: Any, *, lang: Lang = 'en') -> list[Misquote]
Numbers said to go down that the facts hold only as rising, and the reverse.
The direction of a number is :func:directions. It is a misquote when
the facts hold that value (to the decimals written) only with the other
sign. Numbers with no direction are not read.
at ¶
at(facts: Any, key: str) -> Any
The fact at a dotted path (list positions as numbers); None when there is none.
words ¶
words(facts: dict[str, Any], lang: Lang = 'en') -> str
The answer in words, from a template: every number is one of the facts.
:class:ValueError if the text would quote a number the facts do not
hold (a bug of the template, never shipped): it is checked before it is
returned.
check_claims ¶
check_claims(text: str, facts: dict[str, Any], *, lang: Lang = 'en') -> list[Misquote]
In the sentences of :func:words, the numbers that are not the one of their fact.
A sentence written in other words is not read: a model that rephrases
goes through :func:check_text and :func:check_signs only.