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 default UCS table is the shipped v8.2.1 master (753
CatIDs, with their synonyms) plus the in-code seed’s curated phrases; a house
extension and the EnvSound-UCS AudioSet mapping drop in as JSON under data/
with no logic change.
Functions
|
Build the UCS lookup: the v8.2.1 master, the seed's phrases, then a JSON drop. |
The UCS v8.2.1 master as shipped (753 rows, 82 categories): no seed, no drop. |
|
The process-wide default UCS table (master + seed phrases + any drop), built once. |
|
|
Parse a UCS-conformant filename to |
|
Every block of a UCS filename as a |
|
The UCS filename of |
|
Return 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. |
|
Every field of a UCS filename ( |
|
A loaded UCS lookup by CatID: exact, case-insensitive, or a legacy CatID. |
|
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. |
|
How the keyword stage matches, ranks and bands (one strategy object). |
- class foley.index.taxonomy.AudioSetUcsMap(by_name=dict(), by_mid=dict())[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=list())[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, policy=MatchPolicy(stop_words=frozenset({'your', 'me', 'into', 'those', 'on', 'very', 'just', 'then', 'am', 'been', 'more', 'without', 'nor', 'has', 'why', 'that', 'how', 'own', 'at', 'in', 'is', 'were', 'under', 'any', 'will', 'most', 'should', 'such', 'their', 'a', 'us', 'not', 'can', 'if', 'these', 'had', 'where', 'may', 'each', 'its', 'could', 'he', 'of', 'my', 'our', 'the', 'who', 'does', 'as', 'must', 'it', 'what', 'this', 'she', 'might', 'other', 'also', 'they', 'some', 'all', 'him', 'same', 'from', 'with', 'to', 'so', 'for', 'there', 'his', 'we', 'no', 'and', 'here', 'being', 'which', 'about', 'are', 'i', 'have', 'an', 'you', 'onto', 'be', 'or', 'too', 'them', 'but', 'was', 'when', 'her', 'only', 'did', 'than', 'by', 'do', 'would', 'every', 'few'}), ambiguous_words=frozenset({'over', 'small', 'down', 'tone', 'release', 'part', 'thing', 'break', 'sound', 'night', 'off', 'work', 'up', 'meeting', 'long', 'little', 'bang', 'light', 'large', 'misc', 'shot', 'hold', 'day', 'person', 'heavy', 'general', 'hit', 'set', 'out', 'way', 'beat', 'quiet', 'drop', 'blue', 'time', 'fall', 'run', 'handle', 'big', 'place', 'side', 'arc', 'piece', 'open', 'catch'}), skip_categories=frozenset({'ARCHIVED'}), kind_weights=mappingproxy({'subcategory': 3.0, 'category': 3.0, 'synonym': 2.0}), phrase_bonus=1.0, synonym_weight=<function inverse_sqrt_share>, strong_confidence=0.8, single_confidence=0.6, weak_confidence=0.4, audioset_confidence=0.5))[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.MatchPolicy(stop_words=frozenset({'a', 'about', 'all', 'also', 'am', 'an', 'and', 'any', 'are', 'as', 'at', 'be', 'been', 'being', 'but', 'by', 'can', 'could', 'did', 'do', 'does', 'each', 'every', 'few', 'for', 'from', 'had', 'has', 'have', 'he', 'her', 'here', 'him', 'his', 'how', 'i', 'if', 'in', 'into', 'is', 'it', 'its', 'just', 'may', 'me', 'might', 'more', 'most', 'must', 'my', 'no', 'nor', 'not', 'of', 'on', 'only', 'onto', 'or', 'other', 'our', 'own', 'same', 'she', 'should', 'so', 'some', 'such', 'than', 'that', 'the', 'their', 'them', 'then', 'there', 'these', 'they', 'this', 'those', 'to', 'too', 'under', 'us', 'very', 'was', 'we', 'were', 'what', 'when', 'where', 'which', 'who', 'why', 'will', 'with', 'without', 'would', 'you', 'your'}), ambiguous_words=frozenset({'arc', 'bang', 'beat', 'big', 'blue', 'break', 'catch', 'day', 'down', 'drop', 'fall', 'general', 'handle', 'heavy', 'hit', 'hold', 'large', 'light', 'little', 'long', 'meeting', 'misc', 'night', 'off', 'open', 'out', 'over', 'part', 'person', 'piece', 'place', 'quiet', 'release', 'run', 'set', 'shot', 'side', 'small', 'sound', 'thing', 'time', 'tone', 'up', 'way', 'work'}), skip_categories=frozenset({'ARCHIVED'}), kind_weights=mappingproxy({'subcategory': 3.0, 'category': 3.0, 'synonym': 2.0}), phrase_bonus=1.0, synonym_weight=<function inverse_sqrt_share>, strong_confidence=0.8, single_confidence=0.6, weak_confidence=0.4, audioset_confidence=0.5)[source]#
Bases:
objectHow the keyword stage matches, ranks and bands (one strategy object).
- skip_categories#
UCS categories the keyword stage never picks (a filename or declared CatID still may).
- Type:
- kind_weights#
Base weight of a hit by term kind (
subcategory,category,synonym).
- synonym_weight#
(rows listing the synonym, rows in the table) -> factoron a synonym hit’s weight:inverse_sqrt_share()(default) oridf_share()(foley#290).
- strong_confidence#
Band of strong evidence: a subcategory hit, a multi-word phrase, or two distinct content words on the row (a category name plus another word counts).
- Type:
- weak_confidence#
Band of a brush: a category name alone, or a synonym many rows share. A
confident=Falserow drops one band (floored here).- Type:
- class foley.index.taxonomy.TaxonomyResolver(*args, **kwargs)[source]#
Bases:
ProtocolResolve a
SoundRecordto a UCS CatID.
- class foley.index.taxonomy.UcsName(catid, category, subcategory, fx_name=None, creator_id=None, source_id=None, user_category=None, vendor_category=None, user_data=None)[source]#
Bases:
objectEvery field of a UCS filename (
foley.index.taxonomy.ucs.parse_ucs_name).CatID[-UserCategory]_[VendorCategory-]FXName_CreatorID_SourceID[_UserData].ext: underscores separate the blocks; a hyphen attaches the optional UserCategory to the CatID and the optional VendorCategory to the FXName.categoryandsubcategorycome from the table row ofcatid; a block the name does not have isNone.
- class foley.index.taxonomy.UcsRow(catid, category, subcategory, synonyms=(), confident=False, explanation='')[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 unverified row (a house drop’s); the keyword resolver bands its matches one notch lower.
- class foley.index.taxonomy.UcsTable(by_catid=dict(), order=list(), _ci_index=dict(), legacy=dict())[source]#
Bases:
objectA loaded UCS lookup by CatID: exact, case-insensitive, or a legacy CatID.
Plain data, compared by identity (a matcher caches its index per table).
- legacy#
lower(old CatID) -> CatIDfor CatIDs foley once stamped that are not UCS (weathrain->RAIN), so a stored record still finds its row.
- 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 (master + seed phrases + any drop), built once.
- Return type:
- foley.index.taxonomy.format_ucs_name(name=None, /, *, ext=None, table=None, is_vendor_tag=<function looks_like_vendor_tag>, max_bytes=255, **blocks)[source]#
The UCS filename of
name(aUcsNameor a mapping of its blocks), withblocks(UCS_NAME_BLOCKS) overriding it: the inverse ofparse_ucs_name().Each block is sanitised so the name parses back to the same blocks: unsafe characters and underscores inside a block become spaces, whitespace is collapsed, a VendorCategory is upper-cased, and a hyphen that would make an FXName’s head read as a VendorCategory becomes a space (
Sci-Fi Doorstays as it is). A name overmax_byteshas its longest shortenable block (UCS_SHORTENABLE_BLOCKS) cut on a character boundary until it fits. Soformat_ucs_name(parse_ucs_name(f))isffor anyfthis function made. The CatID is looked up intable(default:default_ucs_table()) and written in its canonical spelling; an unknown one raises, since the name would not parse. An all-capitals CatID keeps every mandatory block, empty if need be (RAIN_Heavy__), so the name reads back as UCS.- Parameters:
name (
Union[UcsName,Mapping,None]) – The blocks to format (category/subcategoryare ignored).ext (
Optional[str]) – The extension to append ('wav'or'.wav'), orNonefor a stem.table (
Optional[UcsTable]) – The UCS table the CatID must be in.is_vendor_tag (
Callable[[str],bool]) – What reads as a VendorCategory (as inparse_ucs_name()).max_bytes (
int) – The longest name to make, in UTF-8 bytes, extension included.**blocks – Block values overriding
name’s.
- Raises:
TypeError – a keyword is not a UCS block.
ValueError – no CatID, or one not in
table; a badext; a VendorCategory that cannot be read back or has no FXName; a name that cannot be cut tomax_bytes.
- Return type:
>>> format_ucs_name(catid="doorwood", fx_name="Sci-Fi Door_slam", creator_id="JD", ... source_id="NYC", ext="wav") 'DOORWood_Sci-Fi Door slam_JD_NYC.wav' >>> n = parse_ucs_name("DOORWood-Gate_SCIFI-Creak Open_JD_NYC_take_2.wav") >>> format_ucs_name(n, ext="wav") 'DOORWood-Gate_SCIFI-Creak Open_JD_NYC_take_2.wav' >>> format_ucs_name(catid="DOORWood", fx_name="BOOM-Creak") # not a vendor tag 'DOORWood_BOOM Creak' >>> len(format_ucs_name(catid="DOORWood", fx_name="x" * 300, user_data="id1")) 255
- 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_master()[source]#
The UCS v8.2.1 master as shipped (753 rows, 82 categories): no seed, no drop.
Row fields are the master’s, verbatim (
SubCategoryin capitals:('DOORS', 'WOOD')), with its explanation and synonyms (lowercased). The default table (default_ucs_table()) is this plus the seed’s phrases.>>> t = load_ucs_master() >>> len(t), t.get("doorwood").subcategory, "WOODHndl" in t (753, 'WOOD', True)
- Return type:
- foley.index.taxonomy.load_ucs_table(*, data_dir=None, master=PosixPath('/home/runner/work/foley/foley/foley/index/taxonomy/data/ucs_master.json'), include_seed=True, legacy_catids={'AMBNature': 'AMBForst', 'AMBUrban': 'AMBUrbn', 'ANMLBird': 'BIRDSong', 'CLOTHMove': 'CLOTHMvmt', 'COMMPhone': 'COMTelph', 'DESTGeneral': 'DESTRCrsh', 'DOORKnob': 'DOORHdwr', 'DOORMetal': 'DOORMetl', 'EXPLGeneral': 'EXPLReal', 'FIREGeneral': 'FIREBurn', 'FIREWhoosh': 'FIREWhsh', 'FOOTConc': 'FEETHmn', 'FOOTGravel': 'FEETHmn', 'FOOTWood': 'FEETHmn', 'GLASBreak': 'GLASBrk', 'GUIBeep': 'UIBeep', 'GUIWhoosh': 'UIMvmt', 'GUNHandgun': 'GUNPis', 'LIQDPour': 'WATRPour', 'MACHGeneral': 'MACHMisc', 'PAPRHandle': 'PAPRHndl', 'VEHCarExt': 'VEHCar', 'VEHCarInt': 'VEHInt', 'WATRRun': 'WATRFlow', 'WATRSplash': 'WATRSplsh', 'WEATHRain': 'RAIN', 'WEATHThunder': 'THUN', 'WEATHWind': 'WIND'})[source]#
Build the UCS lookup: the v8.2.1 master, the seed’s phrases, then a JSON drop.
- Parameters:
data_dir – Directory to look for
ucs_full.jsonin (defaults to the package’staxonomy/data/). Its rows override any row on CatID collision and add new ones (a house extension of UCS).master – The UCS master JSON (default: the shipped v8.2.1 table).
None, or a path that does not exist, falls back to the seed rows alone.include_seed (
bool) – Add the seed’s curated phrases to their master rows (defaultTrue); with no master, the seed rows are the table.legacy_catids (
Mapping[str,str]) – Old CatIDs a stored record may carry, mapped to real ones (defaultLEGACY_CATIDS); the table’sgetresolves them.
- Return type:
- Returns:
A ready
UcsTable.- Raises:
ValueError – no master and
include_seed=False: there would be no rows.
>>> t = load_ucs_table() >>> len(t), t.get("RAIN").category, "rain on window" in t.get("RAIN").synonyms (753, 'RAIN', True)
- foley.index.taxonomy.parse_catid_token(filename)[source]#
Return the CatID candidate of a UCS-style filename, else
None.Strips directory, extension and an attached
-UserCategory; requires at least one_(the field delimiter). Does not validate the token against the table.>>> parse_catid_token("DOORWood-Gate_Creak_JD_NYC.wav") 'DOORWood'
- 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.parse_ucs_name(filename, *, table=None, is_vendor_tag=<function looks_like_vendor_tag>)[source]#
Every block of a UCS filename as a
UcsName, elseNone.Fail-quiet like
parse_ucs_filename():Nonewhen the name has no_, its CatID is not in the table, or its CatID is all capitals (RAW,MIX) and it lacks a mandatory block (UCS_MANDATORY_BLOCKS). Blocks past SourceID are the UserData (rejoined with_); a block the name lacks isNone. The FXName block’s head before a hyphen is the VendorCategory only whenis_vendor_tagaccepts it (looks_like_vendor_tag()), soSci-Fi Doorstays whole.>>> n = parse_ucs_name("DOORWood-Gate_SCIFI-Creak Open_JD_NYC_take 2.wav") >>> (n.catid, n.category, n.subcategory, n.user_category) ('DOORWood', 'DOORS', 'WOOD', 'Gate') >>> (n.vendor_category, n.fx_name, n.creator_id, n.source_id, n.user_data) ('SCIFI', 'Creak Open', 'JD', 'NYC', 'take 2') >>> m = parse_ucs_name("DOORWood_Sci-Fi Slam 5.1_JD_NYC") >>> (m.vendor_category, m.fx_name, m.creator_id, m.source_id, m.user_data) (None, 'Sci-Fi Slam 5.1', 'JD', 'NYC', None) >>> parse_ucs_name("DOORWood_Slam.wav").creator_id is None True >>> parse_ucs_name("NOTACAT_x_y_z.wav") is None, parse_ucs_name("plain.wav") is None (True, True) >>> parse_ucs_name("MIX_final.wav") is None, parse_ucs_name("RAIN_Heavy_JD_NYC.wav").catid (True, 'RAIN')
- foley.index.taxonomy.resolve_catid(*, tags=(), caption=None, audioset_labels=(), filename=None, catid=None, table=None, audioset_map=None, policy=MatchPolicy(stop_words=frozenset({'your', 'me', 'into', 'those', 'on', 'very', 'just', 'then', 'am', 'been', 'more', 'without', 'nor', 'has', 'why', 'that', 'how', 'own', 'at', 'in', 'is', 'were', 'under', 'any', 'will', 'most', 'should', 'such', 'their', 'a', 'us', 'not', 'can', 'if', 'these', 'had', 'where', 'may', 'each', 'its', 'could', 'he', 'of', 'my', 'our', 'the', 'who', 'does', 'as', 'must', 'it', 'what', 'this', 'she', 'might', 'other', 'also', 'they', 'some', 'all', 'him', 'same', 'from', 'with', 'to', 'so', 'for', 'there', 'his', 'we', 'no', 'and', 'here', 'being', 'which', 'about', 'are', 'i', 'have', 'an', 'you', 'onto', 'be', 'or', 'too', 'them', 'but', 'was', 'when', 'her', 'only', 'did', 'than', 'by', 'do', 'would', 'every', 'few'}), ambiguous_words=frozenset({'over', 'small', 'down', 'tone', 'release', 'part', 'thing', 'break', 'sound', 'night', 'off', 'work', 'up', 'meeting', 'long', 'little', 'bang', 'light', 'large', 'misc', 'shot', 'hold', 'day', 'person', 'heavy', 'general', 'hit', 'set', 'out', 'way', 'beat', 'quiet', 'drop', 'blue', 'time', 'fall', 'run', 'handle', 'big', 'place', 'side', 'arc', 'piece', 'open', 'catch'}), skip_categories=frozenset({'ARCHIVED'}), kind_weights=mappingproxy({'subcategory': 3.0, 'category': 3.0, 'synonym': 2.0}), phrase_bonus=1.0, synonym_weight=<function inverse_sqrt_share>, strong_confidence=0.8, single_confidence=0.6, weak_confidence=0.4, audioset_confidence=0.5))[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).catid (
Optional[str]) – Optional CatID the sound declares (e.g. its iXMLCATID); wins over keywords when the table knows it, else it is ignored.table (
Optional[UcsTable]) – UCS table (defaults todefault_ucs_table()).audioset_map (
Optional[AudioSetUcsMap]) – AudioSet->UCS map (defaults todefault_audioset_ucs_map()).policy (
MatchPolicy) – How keywords match and band (defaultDEFAULT_MATCH_POLICY; vary it withdataclasses.replace).
- 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: curated phrases on real UCS rows, and the AudioSet overlap map. |
|
The UCS term index: every row's terms, with the vocabulary's inflections. |
|
UCS table loading + the UCS-filename CatID parse (report 04 §5.2, §6.4). |