Skip to content

tdfs4ds.agent.values_skill

tdfs4ds.agent.values_skill

VALUES skill: the values an entity takes, and the ends of a feature's distribution.

"Give me 5 TICKER values" and "which customers have the highest sum_Transaction_Amount?" used to reach SUMMARY (the feature list) or an invented answer. They are now answered by code from in-database reads (:mod:tdfs4ds.feature_values). No rows leave Teradata beyond the ones shown.

========= ===================================================== ================== Kind Question Read ========= ===================================================== ================== entity "give me 5 TICKER values" entity_sample extremes "which customers have the highest ?" feature_extremes lookup " for customer 33357", " of NVDA" feature_values_for profile "customer 33357", "the features of TICKER NVDA" entity_profile ========= ===================================================== ==================

An entity value is recognised only when the store holds it (one typed-equality query per storage table), never guessed from the wording.

logger module-attribute

logger = getLogger('tdfs4ds')

_ENTITY_VALUES_RE module-attribute

_ENTITY_VALUES_RE = compile('\\b(values?|examples?|samples?|instances?|valeurs?|exemples?|[ée]chantillons?|(?:give|show|list)\\s+(?:me\\s+)?(?:\\d{1,3}|some|a\\s+few|the)|liste[rz]?|donne[sz]?(?:[-\\s]moi)?\\s+(?:\\d{1,3}|des|quelques|les)|montre[sz]?(?:[-\\s]moi)?\\s+(?:\\d{1,3}|des|quelques)|(?:which|what)\\b.*\\b(?:available|exist\\w*|stored|known)|quel(?:le)?s?\\b.*\\b(?:disponibles?|existe\\w*))\\b', IGNORECASE)

_CATALOG_WORDS_RE module-attribute

_CATALOG_WORDS_RE = compile('\\b(features?|caract[ée]ristiques?|datasets?|jeux?\\s+de\\s+donn[ée]es|process(?:es|us)?|domains?|domaines?|columns?|colonnes?|definitions?|d[ée]finitions?|lineage|lign[ée]e)\\b', IGNORECASE)

_EXTREMES_RE module-attribute

_EXTREMES_RE = compile('\\b(top|bottom|tail|highest|lowest|largest|smallest|biggest|max(?:imum)?|min(?:imum)?|outliers?|extremes?|extr[êe]mes?|anomal\\w*|unusual|atypiques?|aberrant\\w*|plus\\s+(?:grand|[ée]lev[ée]|petit|faible|bas|haut)\\w*|distribution|r[ée]partition)\\b', IGNORECASE)

_COUNT_RE module-attribute

_COUNT_RE = compile('\\b(\\d{1,3})\\b')

_NOT_LOOKUP_RE module-attribute

_NOT_LOOKUP_RE = compile('\\b(mean(?:s|ing)?|definitions?|define|signifi\\w*|veut\\s+dire|formula|formule|comput\\w*|calcul\\w*|lineage|lign[ée]e|depend\\w*|fresh\\w*|up\\s+to\\s+date|[àa]\\s+jour|derni[eè]re\\s+mise)\\b', IGNORECASE)

_STOP_WORDS module-attribute

_STOP_WORDS = {'THE', 'A', 'AN', 'OF', 'FOR', 'IN', 'ON', 'AT', 'TO', 'IS', 'ARE', 'WHAT', 'WHICH', 'WHO', 'HOW', 'AND', 'OR', 'ME', 'MY', 'GIVE', 'SHOW', 'TELL', 'ABOUT', 'VALUE', 'VALUES', 'FEATURE', 'FEATURES', 'PLEASE', 'IT', 'ITS', 'THIS', 'THAT', 'THESE', 'BY', 'WITH', 'ALL', 'LE', 'LA', 'LES', 'DE', 'DES', 'DU', 'POUR', 'EST', 'SONT', 'QUEL', 'QUELLE', 'QUELS', 'QUELLES', 'VALEUR', 'VALEURS', 'DONNE', 'MOI', 'MONTRE', 'ET', 'OU', 'UN', 'UNE', 'AU', 'AUX'}

_ca

_ca()

_fr

_fr(question: str) -> bool

_entities

_entities(ca) -> list

_count

_count(question: str) -> int

_value_tokens

_value_tokens(question: str, exclude=()) -> list

Words of the question that could be entity values (the store decides).

_entity_in

_entity_in(ca, question: str, entities: list) -> Optional[str]

The entity the question names, exactly or in plain words (one only).

_lookup_target

_lookup_target(features: list, tokens: list) -> Optional[dict]

The entity of the named features whose stored values include tokens.

values_request

values_request(question: str) -> Optional[dict]

The kind of values question asked (see the module docstring), or None. Read from the store of the turn: names and values are never guessed.

complete_pending

complete_pending(pending: dict, reply: str) -> Optional[dict]

The choice a reply makes among the offered (domain, entity) pairs: a number, or words naming the entity / the domain. None when it names none.

skill_values

skill_values(question: str, object_name: Optional[str] = None, entity_name: Optional[str] = None, data_domain: Optional[str] = None, as_of=None, pending: Optional[dict] = None) -> dict

Answer a VALUES question (direct answer, written by code). pending is the question this skill asked last turn ("which one?"): the reply chooses.

_loosely_named

_loosely_named(question: str, entity: str) -> bool

The question speaks of the entity in plain words: every key column, without an id / key / code suffix and as a word stem ("customers" for CustomerID, "categories" for Category).

_feature_target

_feature_target(feature: str, question: str, entity_name, data_domain) -> dict

{"entity", "domain"} for the one stored feature the turn means, or {"choices": [rows]} when it stays ambiguous (never guessed).

_which

_which(feature: str, rows: list, fr: bool) -> str

_fmt

_fmt(v) -> str

_cell

_cell(v) -> str

_key_table

_key_table(rows: list, keys: list, value_label: Optional[str] = None) -> list

render_entity_sample

render_entity_sample(s: dict, fr: bool) -> str

extremes_lines

extremes_lines(e: dict, fr: bool, n: int = DEFAULT_N, heading: bool = True) -> list

The extremes of a feature as Markdown lines (also appended to a distribution chart).

render_extremes

render_extremes(e: dict, fr: bool, n: int = DEFAULT_N) -> str

_when

_when(r: dict, fr: bool) -> str

render_lookup

render_lookup(r: dict, fr: bool) -> str

Values of named features for given entity values: one table.

render_profile

render_profile(p: dict, fr: bool) -> str

Every feature of given entity values: one table per value.