foley.index.taxonomy#
UCS + AudioSet taxonomy: the tags -> UCS CatID resolver for foley.
Two complementary controlled vocabularies (report 04 §5): UCS (the industry
browse tree and normalization target) and the AudioSet ontology (the machine
label layer taggers emit). This package resolves a sound’s free tags, caption,
AudioSet labels, and/or UCS-style filename onto a UCS CatID, filling
ucs_category/ucs_subcategory on ingest and
ucs_catid on the query side.
Progressive disclosure — the one-call path is:
from foley.index.taxonomy import resolve_catid
resolve_catid(caption="a heavy wooden door creaks open") # -> CatIdResolution
Everything else (the UCS table, the AudioSet map, a custom resolver) is optional
keyword injection. The seed tables live in code; the full UCS master and the
EnvSound-UCS mapping drop in later as JSON under data/ with no logic change.
Functions
|
Build the UCS lookup: the seed rows, overridden/extended by a JSON drop. |
The process-wide default UCS table (seed + any JSON drop), built once. |
|
|
Parse a UCS-conformant filename to |
|
Return token 0 (the CatID candidate) of a UCS-style filename, else |
|
Build the AudioSet(name|MID) -> UCS-CatID map. |
The process-wide default AudioSet->UCS map (seed + any JSON drop). |
|
|
Resolve inputs to a best UCS CatID by the staged precedence. |
Classes
|
One Universal Category System entry. |
|
A loaded UCS lookup: by CatID (exact + case-insensitive) and by synonym. |
|
AudioSet-label -> UCS-CatID overlap map (report 04 §5.3). |
|
The result of resolving free tags/caption/labels to a UCS CatID. |
|
Resolve a |
|
The default stdlib resolver — staged keyword/synonym/AudioSet resolution. |
- class foley.index.taxonomy.AudioSetUcsMap(by_name=<factory>, by_mid=<factory>)[source]#
Bases:
objectAudioSet-label -> UCS-CatID overlap map (report 04 §5.3).
Keyed primarily by lowercased label name (robust);
by_midcarries the best-effort/m/...machine ids as a secondary key. Every target CatID is validated against the UCS table at load time (fail-fast on a broken map).
- class foley.index.taxonomy.CatIdResolution(catid=None, category=None, subcategory=None, source=None, confidence=0.0, matched_terms=<factory>)[source]#
Bases:
objectThe result of resolving free tags/caption/labels to a UCS CatID.
catidfeedsucs_categoryandsubcategoryfeedsucs_subcategoryon ingest, anducs_catidon the query side.
- class foley.index.taxonomy.KeywordResolver(*, table=None, audioset_map=None)[source]#
Bases:
objectThe default stdlib resolver — staged keyword/synonym/AudioSet resolution.
Zero heavy dependencies. Bind a different
TaxonomyResolver(e.g. a future CLAP zero-shot resolver) by keyword injection to upgrade quality.- resolve(record)[source]#
Resolve a
SoundRecord’s tags/caption/labels/uri.- Return type:
- class foley.index.taxonomy.TaxonomyResolver(*args, **kwargs)[source]#
Bases:
ProtocolResolve a
SoundRecordto a UCS CatID.
- class foley.index.taxonomy.UcsRow(catid, category, subcategory, synonyms=(), confident=False)[source]#
Bases:
objectOne Universal Category System entry.
A
catid(e.g.'DOORWood') is an OPAQUE key — the category prefix is variable-length and not reliably splittable — socatid -> (category, subcategory)is always a table lookup, never a string split (report 04 §5.2).confident=Falsemarks an APPROXIMATE CatID reconstructed for the seed table; verify it against the UCS master before treating it as authoritative.
- class foley.index.taxonomy.UcsTable(by_catid=<factory>, order=<factory>, _ci_index=<factory>)[source]#
Bases:
objectA loaded UCS lookup: by CatID (exact + case-insensitive) and by synonym.
- by_catid#
CatID -> UcsRow(case-sensitive primary key).
- order#
The CatIDs in stable insertion order (deterministic tie-breaking).
- foley.index.taxonomy.default_audioset_ucs_map()[source]#
The process-wide default AudioSet->UCS map (seed + any JSON drop).
- Return type:
- foley.index.taxonomy.default_ucs_table()[source]#
The process-wide default UCS table (seed + any JSON drop), built once.
- Return type:
- foley.index.taxonomy.load_audioset_ucs_map(*, data_dir=None, table=None, include_seed=True)[source]#
Build the AudioSet(name|MID) -> UCS-CatID map.
- Parameters:
data_dir – Directory to look for
audioset_ucs.jsonin (defaults to the package’staxonomy/data/); merged over the seed when present.table (
Optional[UcsTable]) – The UCS table every target CatID must exist in (defaults todefault_ucs_table()).include_seed (
bool) – Start from the in-code seed map (defaultTrue).
- Return type:
- Returns:
A ready
AudioSetUcsMap.- Raises:
ValueError – If any entry targets a CatID absent from
table.
- foley.index.taxonomy.load_ucs_table(*, data_dir=None, include_seed=True)[source]#
Build the UCS lookup: the seed rows, overridden/extended by a JSON drop.
- Parameters:
data_dir – Directory to look for
ucs_full.jsonin (defaults to the package’staxonomy/data/). When present, its rows override the seed on CatID collision and add the rest of the ~750-row master.include_seed (
bool) – Start from the in-code seed table (defaultTrue).
- Return type:
- Returns:
A ready
UcsTable.
- foley.index.taxonomy.parse_catid_token(filename)[source]#
Return token 0 (the CatID candidate) of a UCS-style filename, else
None.Strips directory and extension; requires at least one
_(the field delimiter). Does not validate the token against the table.
- foley.index.taxonomy.parse_ucs_filename(filename, *, table=None)[source]#
Parse a UCS-conformant filename to
(ucs_category, ucs_subcategory).Fail-quiet: returns
(None, None)when the name is not UCS-conformant or its CatID token is unknown (so a wrong subcategory is never emitted).
- foley.index.taxonomy.resolve_catid(*, tags=(), caption=None, audioset_labels=(), filename=None, table=None, audioset_map=None)[source]#
Resolve inputs to a best UCS CatID by the staged precedence.
- Parameters:
audioset_labels (
Sequence[str]) – AudioSet MIDs or names (e.g. from PANNs).filename (
Optional[str]) – Optional UCS-style filename/path (its token-0 CatID wins if recognized).table (
Optional[UcsTable]) – UCS table (defaults todefault_ucs_table()).audioset_map (
Optional[AudioSetUcsMap]) – AudioSet->UCS map (defaults todefault_audioset_ucs_map()).
- Return type:
- Returns:
A
CatIdResolution(falsy when nothing resolved).
Modules
AudioSet-label -> UCS-CatID overlap map (report 04 §5.3, [11 §3.1]). |
|
Data structures for the UCS/AudioSet taxonomy resolver (stdlib-only). |
|
Resolve free tags/caption/labels to a UCS CatID (the EnvSound-UCS pipeline). |
|
Seed taxonomy data — a representative in-code UCS subset + AudioSet overlap map. |
|
UCS table loading + the UCS-filename CatID parse (report 04 §5.2, §6.4). |