Skip to content

The numbers of a text

A model that writes from facts can invent a number, put it in the wrong unit, or say a true number of the wrong thing. These functions list such numbers; they do not change the text: a person decides.

from limen_core.idrogeo_grounding import misattributed_numbers, unsupported_numbers
from limen_core.rain_grounding import check_rain_text

facts = {"frane": 12000, "frane_al_giorno": 4038}
misattributed_numbers("In Puglia IFFI censisce 4.038 frane.", facts)
# [Misquote(said='4.038', key='frane', fact=12000.0)]

idrogeo_grounding needs the idrogeo extra; rain_grounding needs none.

limen_core.idrogeo_grounding

The source and the numbers of IdroGEO data in the texts Limen writes.

Every answer read from ispra-idrogeo carries source (the right citation and licence: IFFI and events CC BY-SA 4.0, indicators CC BY 4.0), and ispra_idrogeo.grounding.check_text lists the numbers of a text that the data do not support. Here, thin functions over those, for the texts written with IdroGEO data in them:

  • :func:source_of: the source of an answer;
  • :func:unsupported_numbers: the numbers that no fact supports;
  • :func:misattributed_numbers: the numbers said of a figure that is not theirs.

check_text says that a number exists in the facts, not that it is said of the right thing: "Bari has 53 landslides" passes if 53 is any number of the facts. Pass only the facts the text was written from. check_claims reads what a number is said of and compares it with that figure: its rules speak the names of the ISPRA API, and :data:LIMEN_RULES adds rules for the names of :class:limen_core.iffi.IffiReliability, which is what Limen's briefing receives. Counts only: shares are fractions in the facts and percentages in the text.

Needs the idrogeo extra (pip install "limen-core[idrogeo]"): ispra_idrogeo is imported with this module.

source_of

source_of(response: Mapping[str, Any]) -> str | None

The source (or idrogeo_source) of an IdroGEO answer, stripped, if there is one.

unsupported_numbers

unsupported_numbers(text: str, facts: Any, question: str = '') -> list[str]

The numbers and dates of text that no number of facts supports.

question is the text the answer started from (the request, the message to the model): its numbers count as supported too. Empty: all found.

misattributed_numbers

misattributed_numbers(text: str, facts: Any) -> list[Misquote]

The numbers of text said of a figure of facts that is not theirs.

"Puglia has 4,038 landslides" when 4,038 in the facts are the landslides dated to the day: :func:unsupported_numbers lets it pass, this does not. Empty: nothing misattributed; a number it cannot place is left to the other.

limen_core.rain_grounding

The rain numbers of a text, checked against the rain facts it was written from.

A model that tells a rainfall event in words can invent a number, write the threshold in mm as if it were mm/h, or round a figure the wrong way. rainfall_thresholds.check.check_text finds the three; :func:check_rain_text is that check, reached through limen-core so that an agent depends on one package for the grounding of rain and of IdroGEO (:mod:limen_core.idrogeo_grounding).

The facts are mappings whose keys name their unit (cumulated_mm, duration_h, intensity_mm_h, threshold_intensity_mm_h): the unit of a fact is read from the end of its key. Dates and clock times in the text are not checked, nor the numbers that are in the question.

No extra needed: rainfall-thresholds is a dependency of limen-core.

check_rain_text

check_rain_text(text: str, facts: Any, *, question: str = '') -> list[Misquote]

The numbers of text that are not facts of their unit. Empty: faithful.

Each :class:Misquote says the number as written, its unit, the fault (invented, unit, rounded) and the nearest fact. A number such as 10.10.26 may raise :class:ValueError: a caller that only warns should catch it.