tdfs4ds.agent.dataset_request¶
tdfs4ds.agent.dataset_request
¶
What a dataset request already says, and what an options reply means (0.3.7.35). Pure.
The chat creates a dataset through a decision tree (graph.node_skill_build_dataset).
Anything the user has already said - the entity, the features, the kind and window of the
dataset, its options, its name - is read here without the model and carried through the
flow as prefilled: each step then asks for a confirmation ("I understood X. Keep it?")
instead of asking again.
- :func:
extract_dataset_requestreads a sentence against the store's entities, features and TimeManagers. - :func:
parse_dataset_optionsreads the options a dataset can have: the join type, following the domain clock or a named TimeManager, lags and leads per feature, and the delay of a sliding history window. It says what it did not understand (unread) and what it understood but cannot apply here (ignored). - :func:
is_yes/ :func:is_noread a confirmation.
Nothing here reads a database, a catalog or a model.
_YES_CORE
module-attribute
¶
_YES_CORE = {'yes', 'yep', 'yeah', 'ok', 'okay', 'oui', 'ouais', "d'accord", 'daccord', 'sure', 'confirm', 'confirmed', 'keep', 'garde', 'gardez', 'garder', 'valide', 'valider', 'confirme', 'parfait', 'go', 'correct', 'exact', 'right'}
_YES_FILLER
module-attribute
¶
_YES_FILLER = {'it', 'them', 'this', 'that', 'good', 'fine', 'please', 'svp', 'les', 'le', 'la', 'l', 'all', 'bien', 'bon', "c'est", 'cest', 'est', 'thanks', 'merci', 'as', 'is', 'they', 'are', 'tout', 'tous', 'toutes', 'default', 'defaults', 'défaut', 'defaut', 'défauts', 'par'}
_NO_WORDS
module-attribute
¶
_NO_WORDS = {'no', 'non', 'nope', 'change', 'other', 'another', 'different', 'autre', 'modifier', 'modify', 'wrong', 'faux', 'nah'}
_DEFAULT_WORDS
module-attribute
¶
_DEFAULT_WORDS = {'none', 'nothing', 'no', 'non', 'default', 'defaults', 'défaut', 'defaut', 'défauts', 'aucune', 'aucun', 'rien', 'par', 'as', 'is', 'keep', 'garde', 'gardez', 'garder'}
_UNIT
module-attribute
¶
_UNIT = '(?:years?|yrs?|months?|weeks?|days?|hours?|minutes?|ann[ée]es?|ans?|mois|semaines?|jours?|heures?)'
_UNIT_MAP
module-attribute
¶
_UNIT_MAP = {'year': 'year', 'years': 'years', 'yr': 'year', 'yrs': 'years', 'month': 'month', 'months': 'months', 'week': 'week', 'weeks': 'weeks', 'day': 'day', 'days': 'days', 'hour': 'hour', 'hours': 'hours', 'minute': 'minute', 'minutes': 'minutes', 'an': 'year', 'ans': 'years', 'année': 'year', 'années': 'years', 'annee': 'year', 'annees': 'years', 'mois': 'months', 'semaine': 'week', 'semaines': 'weeks', 'jour': 'day', 'jours': 'days', 'heure': 'hour', 'heures': 'hours'}
_LAGLEAD_A
module-attribute
¶
_LAGLEAD_A = re.compile(f"\\b{_DIR_RE}\\s*(?:of|de|d'|by|of\\s+about|:|=)?\\s*(?P<amt>{_AMOUNT})", re.IGNORECASE)
_LAGLEAD_B
module-attribute
¶
_NO_OFFSET_RE
module-attribute
¶
_NO_OFFSET_RE = re.compile('\\b(?:no|without|remove|drop|sans|aucun[es]?)\\s+(?:the\\s+|any\\s+|de\\s+)?(?:lags?|leads?|offsets?|d[ée]calages?|retards?)\\b', re.IGNORECASE)
_DELAY_A
module-attribute
¶
_DELAY_A = re.compile(f"\\b(?:with\\s+)?(?:an?\\s+|un\\s+)?(?:delay|d[ée]lai)\\s*(?:of|de|d'|by|:|=)?\\s*(?P<amt>{_AMOUNT})", re.IGNORECASE)
_DELAY_B
module-attribute
¶
_NO_DELAY_RE
module-attribute
¶
_NO_DELAY_RE = re.compile('\\b(?:no|without|sans|aucun)\\s+(?:de\\s+)?(?:delay|d[ée]lai)\\b', re.IGNORECASE)
_FOLLOW_WORD
module-attribute
¶
_FOLLOW_WORD = '(?:follow(?:s|ing)?|track(?:s|ing)?|suivre|suit|suivant|suive[nz]?|synchronis\\w+|sync(?:hronised|hronized)?\\s+with|align(?:ed)?\\s+(?:on|with))'
_NOT_FOLLOW_RE
module-attribute
¶
_NOT_FOLLOW_RE = re.compile("\\b(?:do\\s*n[o']?t|don't|do\\s+not|not|without|sans|ne\\s+pas)\\s+" + _FOLLOW_WORD + '(?:\\s+(?:the\\s+|any\\s+|la\\s+|le\\s+)?(?:domain\\s+)?(?:clock|time\\s*manager|horloge))?|\\bno\\s+(?:time\\s*manager|clock|horloge)\\b|\\bsans\\s+(?:time\\s*manager|horloge)\\b', re.IGNORECASE)
_CLOCK_RE
module-attribute
¶
_CLOCK_RE = re.compile("\\b(?:(?:the\\s+)?(?:domain|data\\s+domain)\\s+clock|(?:l')?horloge(?:\\s+du\\s+domaine)?|(?:the\\s+)?clock)\\b", re.IGNORECASE)
_TM_WORD_RE
module-attribute
¶
_INNER_RE
module-attribute
¶
_INNER_RE = re.compile('\\binner(?:\\s+join)?\\b|\\bjointure\\s+interne\\b|\\bintersection\\b|\\bcommon\\s+entities\\b|\\bentit[ée]s\\s+communes\\b|\\bonly\\s+(?:the\\s+)?entities\\s+(?:that\\s+have|with|having)\\s+(?:all|every)\\b|\\bseulement\\s+les\\s+entit[ée]s\\s+(?:qui\\s+ont|avec)\\b', re.IGNORECASE)
_FULL_RE
module-attribute
¶
_FULL_RE = re.compile('\\bfull\\s+outer(?:\\s+join)?\\b|\\bouter\\s+join\\b|\\ball\\s+(?:the\\s+)?entities\\b|\\bevery\\s+entity\\b|\\btoutes\\s+les\\s+entit[ée]s\\b|\\bjointure\\s+externe\\b|\\bunion\\b', re.IGNORECASE)
_NAME_PHRASE
module-attribute
¶
_NAME_PHRASE = re.compile('\\b(?:call(?:ed)?\\s+it|name\\s+it|named|call|appelle(?:-le|z-le)?|nomme(?:-le|z-le)?|nomm[ée])\\s+(?:the\\s+dataset\\s+|le\\s+dataset\\s+)?[`\'\\"]?(?P<name>[A-Za-z][A-Za-z0-9_$#]{0,127})[`\'\\"]?', re.IGNORECASE)
_NAME_STOP
module-attribute
¶
_NAME_STOP = {'it', 'the', 'a', 'an', 'dataset', 'datasets', 'please', 'as', 'that', 'this', 'le', 'la', 'les', 'un', 'une', 'nom', 'name', 'ds', 'jeu', 'de', 'données', 'donnees', 'merci', 'for', 'pour'}
_FILLER
module-attribute
¶
_FILLER = {'ok', 'okay', 'yes', 'oui', 'and', 'et', 'also', 'aussi', 'plus', 'with', 'avec', 'a', 'an', 'the', 'le', 'la', 'les', 'l', 'un', 'une', 'of', 'de', 'du', 'des', 'd', 'on', 'sur', 'for', 'pour', 'join', 'jointure', 'type', 'option', 'options', 'please', 'svp', 's', 'il', 'vous', 'plait', 'plaît', 'i', 'want', 'would', 'like', 'je', 'veux', 'voudrais', 'it', 'as', 'to', 'au', 'aux', 'in', 'en', 'then', 'puis', 'but', 'mais', 'keep', 'garde', 'gardez', 'garder', 'them', 'ones', 'one', 'that', 'this', 'is', 'are', 'be', 'so', 'just', 'only', 'seulement', 'juste', 'also', 'feature', 'features', 'value', 'values', 'valeur', 'valeurs', 'column', 'colonne', 'columns', 'colonnes', 'set', 'mettre', 'mets', 'use', 'utilise', 'utiliser', 'rows', 'lignes', 'per', 'par', 'each', 'chaque', 'default', 'defaults', 'défaut', 'defaut', 'no', 'non', 'none', 'nothing', 'rien', 'by', 'or', 'ou', 'me', 'moi', 'give', 'donne', 'donnez', 'change', 'modifier', 'make', 'faire', 'fais', "that's", 'all', 'tout', 'tous', 'toutes', 'everything', 'tel', 'quel'}
_ALL_FEATURES_RE
module-attribute
¶
_ALL_FEATURES_RE = re.compile('\\ball\\s+(?:the\\s+|of\\s+the\\s+)?(?:\\w+\\s+)?features\\b|\\btoutes?\\s+les\\s+features\\b|\\btous\\s+les\\s+features\\b|\\bevery\\s+feature\\b', re.IGNORECASE)
_HIST_STRONG
module-attribute
¶
_HIST_STRONG = re.compile('\\b(?:histor\\w*|over\\s+time|time\\s+series|[ée]volution|dans\\s+le\\s+temps)\\b', re.IGNORECASE)
_WINDOW_HINT
module-attribute
¶
_WINDOW_HINT = re.compile('\\b(?:last|past|previous|derni[eè]re?s?|pass[ée]s?|between|entre|from|since|depuis|du|until|jusqu\\w*|over|sur)\\b', re.IGNORECASE)
_ASOF_RE
module-attribute
¶
_ASOF_RE = re.compile('\\bas\\s+(?:of|at)\\b|\\b(?:[àa]\\s+la\\s+date|en\\s+date\\s+du|au)\\b', re.IGNORECASE)
_CURRENT_PHRASE
module-attribute
¶
_CURRENT_PHRASE = re.compile('\\b(?:current|latest|actuel\\w*|up[- ]to[- ]date)\\s+(?:snapshot|values?|state|valeurs?|instantan\\w*|version)\\b|\\bsnapshot\\s+(?:now|today|actuel\\w*|courant)\\b|\\binstantan[ée]\\s+(?:actuel|courant)\\b|\\bsnapshot\\s+of\\s+(?:the\\s+)?(?:current|latest)\\b', re.IGNORECASE)
_UNIT_FR
module-attribute
¶
_UNIT_FR = {'year': 'an', 'years': 'ans', 'month': 'mois', 'months': 'mois', 'week': 'semaine', 'weeks': 'semaines', 'day': 'jour', 'days': 'jours', 'hour': 'heure', 'hours': 'heures', 'minute': 'minute', 'minutes': 'minutes'}
_EN_TO_FR_UNITS
module-attribute
¶
_EN_TO_FR_UNITS = {'year': ('an', 'ans'), 'month': ('mois', 'mois'), 'week': ('semaine', 'semaines'), 'day': ('jour', 'jours'), 'hour': ('heure', 'heures'), 'minute': ('minute', 'minutes')}
__all__
module-attribute
¶
__all__ = ['parse_dataset_options', 'extract_dataset_request', 'merge_options', 'filter_options', 'feature_offsets_for_build', 'describe_options', 'is_yes', 'is_no', 'INNER', 'FULL_OUTER']
is_yes
¶
True when the whole reply is a confirmation ("yes", "ok", "oui, garde-le", "keep it").
is_no
¶
True when the reply only refuses / asks to change ("no", "change", "non, autre chose").
_amount_text
¶
'1 mois 2 jours' -> '1 month 2 days' (what parse_offset / parse_duration read).
_feature_regex
¶
A feature name as the user writes it: _ and a space are the same, case does not matter.
parse_dataset_options
¶
Read the options in text.
applicable says what this dataset can have: join (two features or more),
features (the selected feature names, the only ones a lag or lead can name),
clock ('db.view' of the domain clock, or None), managers (the
TimeManagers the features' processes read, 'db.view' each), follow (the
dataset is a current snapshot, so it may follow a manager) and delay (the
history window slides up to now). A missing key is permissive (True / []).
Returns::
{"join_type": "INNER" | "FULL OUTER" | None,
"follow": {"mode": "clock"} | {"mode": "manager", "manager": "db.view"} | {"mode": "none"} | None,
"offsets": {feature: ["-1 month", "+1 month"]}, # signed, what ``parse_offset`` reads
"clear_offsets": bool, "delay": "1 day" | "" (no delay) | None,
"name": str | None, "keep": bool, # "ok" / "defaults"
"ignored": [(what, why)], # understood, but not applicable to this dataset
"unread": [str], # text that means nothing here (the caller re-asks)
"rest": str} # the text with every read span removed
Pure; never raises.
_kind_in_request
¶
The kind of dataset a request states, or None when it states none.
Only explicit wording counts ("history", "as of problem is set when the kind is stated without what it needs (an "as of" with no date,
a history with no window).
extract_dataset_request
¶
Everything a sentence already says about the dataset to build. Pure.
store: {"entities": [{"entity", "domain"}], "features": [{"name", "entity", "domain"}],
"managers": ["db.view"], "clock": truthy when a domain has a clock}; each key optional.
Returns {"entity_matches": [candidates the text names], "features": [names, in text order],
"all_features": bool, "kind": kind dict | None, "options": options dict | None,
"name": str | None}. A key holds nothing ([] / None / False) when the text says
nothing about it. The caller decides what to do with several entity matches (ask).
filter_options
¶
(kept, ignored): options (the keys join_type / follow / offsets / delay) limited to
what this dataset can have. ignored is [(what, why)]; an option that cannot apply is
dropped, never silently turned into something else. follow == {"mode": "none"} is the
default and is kept as is. clear_offsets passes through. Pure.
merge_options
¶
new over base: a key new sets replaces it, the offsets of a feature new names replace
that feature's; clear_offsets empties them. Pure.
feature_offsets_for_build
¶
build_dataset's feature_offsets: the plain column is kept beside each shifted one
('0' first), so {'amount': ['0', '-1 month']} gives amount and amount_LAG_1MO.
duration_fr
¶
'1 day' -> '1 jour', '90 days' -> '90 jours'; anything else unchanged. Pure.
describe_options
¶
One readable line per option set (join type, TimeManager, lags/leads, delay); [] when none.