tdfs4ds.agent.aggregate_question¶
tdfs4ds.agent.aggregate_question
¶
Questions that ask for a number computed over data (0.3.7.34).
"by joining
Pure helpers + one reader of the business dictionary / dataset catalog
(resolve_targets); everything is fail-open (an unreadable catalog gives no
target, so the question keeps its usual routing).
_AGGREGATE_RE
module-attribute
¶
_AGGREGATE_RE = re.compile('\\bcalculat(?:e|ing)\\b|\\bcompute\\b|\\bhow\\s+many\\b|\\bnumber\\s+of\\b|\\bcount\\b|\\bsum\\s+of\\b|\\baverage\\s+of\\b|\\bavg\\b|\\bcalcul(?:e|er|ez)\\b|\\bcompt(?:e|er|ez)\\b|\\bcombien\\b|\\bnombre\\s+de\\b|\\bsomme\\s+(?:de|des)\\b|\\bmoyenne\\s+(?:de|des)\\b', re.IGNORECASE)
_CATALOG_COUNT_RE
module-attribute
¶
_CATALOG_COUNT_RE = re.compile('\\b(?:how\\s+many|number\\s+of|count|combien|nombre\\s+de)\\s+(?:\\w+\\s+){0,2}?(?:features?|datasets?|entit(?:y|ies)|data\\s+domains?|domains?|processes|process|tables?|views?|columns?|runs?|jeux?\\s+de\\s+donn[ée]es|entit[ée]s?|processus|colonnes?)\\b', re.IGNORECASE)
_OPERATORS
module-attribute
¶
_OPERATORS = ((re.compile('\\b(?:greater|more|larger|longer|bigger|higher|above|over|exceed\\w*|plus\\s+(?:grand|long)\\w*|sup[ée]rieur\\w*|au-dessus)\\b|>', re.I), '>'), (re.compile('\\b(?:less|lower|smaller|shorter|below|under|fewer|moins|inf[ée]rieur\\w*|au-dessous)\\b|<', re.I), '<'))
_OPERATOR_WORD_RE
module-attribute
¶
_OPERATOR_WORD_RE = re.compile('\\b(?:greater|more|larger|longer|bigger|higher|above|over|exceed\\w*|less|lower|smaller|shorter|below|under|fewer|sup[ée]rieur\\w*|inf[ée]rieur\\w*)\\b', re.I)
_QUANTITY_RE
module-attribute
¶
_QUANTITY_RE = re.compile('(?P<n>\\d+(?:[.,]\\d+)?)\\s*(?P<u>km|kilomet\\w*|kilom[èe]tres?|m|met\\w*|m[èe]tres?|cm|mm)?\\b', re.I)
_UNIT_FACTOR
module-attribute
¶
_UNIT_FACTOR = {'km': 1000.0, 'kilomet': 1000.0, 'kilom': 1000.0, 'm': 1.0, 'met': 1.0, 'cm': 0.01, 'mm': 0.001}
_GENERIC_WORDS
module-attribute
¶
_GENERIC_WORDS = frozenset({'calculate', 'compute', 'count', 'number', 'many', 'could', 'you', 'the', 'and', 'with', 'that', 'have', 'has', 'joining', 'join', 'joined', 'by', 'of', 'a', 'an', 'to', 'is', 'are', 'dealing', 'deal', 'dataset', 'datasets', 'view', 'table', 'greater', 'than', 'less', 'more', 'fewer', 'entity', 'from', 'for', 'in', 'on', 'please', 'can', 'what', 'which', 'whose', 'where', 'when', 'per', 'each', 'all', 'any', 'me', 'give', 'above', 'below', 'over', 'under', 'exceed', 'exceeds', 'lower', 'higher', 'larger', 'smaller', 'longer', 'shorter', 'bigger', 'using', 'use', 'between', 'total', 'id', 'ids'})
is_aggregate_question
¶
The question asks for a figure computed over data, not for the catalog's content.
entities_named
¶
The entity (columns joined by commas) whose EVERY column the question writes;
the widest wins. candidates is [{entity, domain, ...}]. Pure.
comparison
¶
{op, value, unit, sql_value, assumption} of "greater than 1 km", else None. Pure.
measure_word
¶
The words naming what is compared: those just before the comparison word
("a fiber length greater than ..." -> ['length', 'fiber']), most specific first.
rank_measure_columns
¶
columns = [{name, description, source}] -> those matching the measure words,
best first: a word in the column's name beats one in its description; the first
(most specific) word weighs most. Pure.
_documented_views
¶
Documented tables / views (not datasets, process views, FS_ objects) the question names.
resolve_targets
¶
{views: [...], entity: {...}|None, datasets: [...], sample} of what an aggregate
question names. A dataset is kept when its entity is the one named (or it is named
itself); among several of that entity, the ones sharing most words with the question
come first. Fail-open.
is_aggregate_data_question
¶
An aggregate question that names a documented view, a dataset or an entity. Reads the catalogs.
mcp_hint
¶
The objects to give the MCP tools, as one sentence ('' when none): the views and datasets are database-qualified, the entity key says which dataset is meant.
aggregate_answer
¶
The MCP-less answer: the SQL to run, from verified names. None when nothing was resolved.