foley.index.taxonomy.text#

The UCS term index: every row’s terms, with the vocabulary’s inflections.

Matching runs over a closed vocabulary: the words of the table’s subcategories, category names and synonyms. Instead of stemming the query (which mangles words: golden -> gold, news -> new), the index lists the regular inflections of every vocabulary word (inflections(): -s/-es/-ies, -ing, -ed, with the final e dropped and a final consonant doubled where English does), so a query word is only lowercased and looked up: "rattling" meets the rattle synonym, "screens" the screen one, and "chicken" never meets chick. Vocabulary words that are inflections of each other (door and doors, the DOORS category) share one lemma, so either spelling meets both.

Module Attributes

MIN_INFLECTED_LENGTH

Shorter vocabulary words are not inflected (be + d is bed).

NOT_INFLECTIONS

Vocabulary words that look like a regular inflection of another but are not (news is not the plural of new, thing not the + -ing, a winding road not the WIND): never linked to that other word.

Functions

build_term_index(rows, *[, inflect, ...])

Index the subcategory, synonyms and category name of each UcsRow in rows.

category_rows(rows)

category -> CatID of the row a category name alone lands on: its first generic (GENERAL/MISC) row, else its first row.

inflections(word)

The regular inflections of word (word itself excluded).

Classes

Term(catid, words, lemmas, kind)

One matchable term of a UCS row: its words, their lemmas, and where it came from.

TermIndex(by_lemma, lexicon, row_count)

A table's terms keyed by lemma, the surface-form lexicon, and term sharing.

foley.index.taxonomy.text.MIN_INFLECTED_LENGTH = 3#

Shorter vocabulary words are not inflected (be + d is bed).

foley.index.taxonomy.text.NOT_INFLECTIONS: frozenset = frozenset({'bearing', 'casing', 'copses', 'earing', 'lemming', 'news', 'rugged', 'seed', 'singed', 'thing', 'tired', 'weed', 'wicked', 'winding'})#

Vocabulary words that look like a regular inflection of another but are not (news is not the plural of new, thing not the + -ing, a winding road not the WIND): never linked to that other word.

class foley.index.taxonomy.text.Term(catid, words, lemmas, kind)[source]#

Bases: object

One matchable term of a UCS row: its words, their lemmas, and where it came from.

kind is "subcategory", "synonym" or "category".

property text: str#

The term as written (lowercased, single-spaced).

class foley.index.taxonomy.text.TermIndex(by_lemma, lexicon, row_count)[source]#

Bases: object

A table’s terms keyed by lemma, the surface-form lexicon, and term sharing.

by_lemma#

lemma -> every term with that lemma among its words.

Type:

Mapping[str, tuple[Term, ...]]

lexicon#

surface word (a vocabulary word or an inflection of one) -> its lemmas.

Type:

Mapping[str, frozenset[str]]

row_count#

a term’s lemmas -> in how many rows it appears, whatever its kind.

Type:

Mapping[tuple[str, ...], int]

lemmas(word)[source]#

The lemmas a query word can be (empty if no vocabulary word has that form).

Return type:

frozenset[str]

foley.index.taxonomy.text.build_term_index(rows, *, inflect=<function inflections>, not_inflections=frozenset({'bearing', 'casing', 'copses', 'earing', 'lemming', 'news', 'rugged', 'seed', 'singed', 'thing', 'tired', 'weed', 'wicked', 'winding'}))[source]#

Index the subcategory, synonyms and category name of each UcsRow in rows.

A row lists a term once per kind, so a word that is both its category name and one of its synonyms counts as both. A category name is one term, on the category’s representative row (category_rows()); a matcher lends it to the category’s other rows. inflect gives a word’s inflections (default inflections()); not_inflections are words never read as an inflection (default NOT_INFLECTIONS).

Return type:

TermIndex

foley.index.taxonomy.text.category_rows(rows)[source]#

category -> CatID of the row a category name alone lands on: its first generic (GENERAL/MISC) row, else its first row.

Return type:

dict[str, str]

foley.index.taxonomy.text.inflections(word)[source]#

The regular inflections of word (word itself excluded).

>>> sorted(inflections("rattle"))
['rattled', 'rattles', 'rattling']
>>> sorted(inflections("drip")), sorted(inflections("buzz"))
(['dripped', 'dripping', 'drips'], ['buzzed', 'buzzes', 'buzzing'])
>>> sorted(inflections("cry")), sorted(inflections("open"))
(['cried', 'cries', 'crying'], ['opened', 'opening', 'opens'])
>>> inflections("up")
frozenset()
Return type:

frozenset[str]