Repository navigation
Separate wildcard (*) single word lexicon entries into a new autotag data type #36
Description
Summary
Some single word lexicon entries are patterns, not literal words. Two kinds of pattern syntax are used:
*as a wildcard, e.g.*-year-oldmatches10-year-old,25-year-old, etc.[...]character classes, e.g.[0-9]matches any single digit, and[0-9]*matches zero or more digits, so[0-9]*ishmatches9ishand10ish. These appear in the upstream USAS lexicons but are not in this repository yet.
Pattern entries are currently mixed with ordinary entries in which the same characters are literal, e.g. f***. Tools such as PyMUSAS therefore can't tell which entries to read as patterns and which to match exactly.
This issue proposes moving every single word lexicon entry whose lemma or pos is a pattern into its own file, with a new data type value of autotag.
Proposal
-
New data type
autotaginlanguage_resources.json. The file format is exactly the same as thesingledata type (same headers and rules, see Single word lexicon file format). The only difference is how thelemmaandposfields are read. In anautotagfile they are patterns:[...]is a regex character class matching exactly one character, e.g.[0-9]matches one digit and[a-z]one lowercase ASCII letter.*straight after a character class means "zero or more characters from that class" (as in regex), e.g.[0-9]*ishmatches9ishand10ish(see the warning below).*anywhere else means "zero or more of any character" (regex.*), e.g.*-year-oldmatches10-year-old.- Every other character is literal, e.g.
.,+,?,(. When an entry is converted to a regex, these characters must be escaped. -
- The
posfield cannot be just*. Everyautotagentry must give a POS pattern, so that patterns don't match tokens of every POS. Apospattern can still contain*alongside other characters, e.g.N*.
- The
PyMUSAS support is tracked in UCREL/pymusas#28, which needs to cover
[...]and[...]*as well as*. -
File naming convention:
semantic_lexicon_LANG_autotag.tsv, saved in the language's folder.LANGis the same language suffix used by that language's single word lexicon file, e.g.English/semantic_lexicon_en.tsv→English/semantic_lexicon_en_autotag.tsv. -
In
singlefiles,*,[and]in thelemmafield are always literal. The existing Implicit POS rule, where aposvalue of exactly*means any POS, stays as it is.
Warning
[...]* also matches zero characters, so the rest of the pattern on its own is a valid match. For example, [0-9]*ish matches 9ish and 10ish, but also the word ish. When writing an entry, check that the zero-character match is intended. If at least one character from the class is required, add a non-optional copy of the class before it, e.g. [0-9][0-9]*ish matches 9ish and 10ish but not ish.
Affected lexicons
At the moment, Danish and English are the only single word lexicons that contain pattern entries. All of these use *, and no entries in the repository use [...] yet. Both lexicons also contain at least one entry where * is literal.
| Lexicon | Pattern entries to move to autotag |
Entries that stay in single (literal *) |
|---|---|---|
| Danish/semantic_lexicon_dk.tsv | lines 31–61, e.g. *-hektar, *kph, *MB |
line 15983: f*** VERB S3.2/B1 and line 30: * X Z5 |
| English/semantic_lexicon_en.tsv | lines 32–67, e.g. *-year-old, *acre, *kph |
line 26029: f*** VERB S3.2/B1 and line 31: * X Z5 |
Entries from the upstream USAS lexicons that use [...] (e.g. [0-9]*ish) should go into the matching autotag file when they are added to this repository.
Note
A lemma of just * is a valid wildcard pattern. For example, * PUNCT PUNCT would give the USAS tag PUNCT to any token with the POS tag PUNCT that doesn't match a non-pattern single word lexicon entry, as in the example in UCREL/pymusas#28.
Out of scope: Portuguese/semantic_lexicon_pt.tsv contains * in many lemmas, but how to handle them is undecided (see #5). It is unchanged until #5 is resolved.
Tasks
- Create
Danish/semantic_lexicon_dk_autotag.tsvandEnglish/semantic_lexicon_en_autotag.tsv, following the naming convention above, with the same headers as theirsinglecounterparts (lemma pos semantic_tags), and remove the moved entries from the original files. - no
autotagentry has a pos value of exactly* - Add both files to
language_resources.jsonwith"data type": "autotag". - Document the
autotagdata type in the README (USAS Lexicon Meta Data and Lexicon File Format sections). Cover the pattern syntax ([...]character classes,*after a class meaning zero or more of that class,*elsewhere meaning zero or more of any character; every other character is literal), including that[...]*can match zero characters and how to require at least one. State that*,[and]insinglefiles are literal, and give theautotagfile naming convention. - Update CONTRIBUTING.md so that contributors:
- know
autotaglexicon files exist, follow the single word lexicon file format, and support*,[...]and[...]*patterns, - know that
[...]*also matches zero characters (e.g.[0-9]*ishmatchesish), so they may need to add a non-optional class, e.g.[0-9][0-9]*ish, - put pattern entries in a
semantic_lexicon_LANG_autotag.tsvfile rather than in the single word lexicon file, - add the file to the meta data file with
"data type": "autotag". - know that every
autotagentry needs a POS pattern, and that aposvalue of just*is not allowed,
- know
- Accept
autotageverywheresingleis accepted and validate it the same way, plus a check that every[in anautotaglemma/posstarts a well-formed, closed character class (e.g. by compiling the converted regex):txt_to_tsv.pytest_collection.pytest_all_collections.pylexicon_statistics.py(reportautotagas its own type)create_pos_tagsets.py
- Regenerate
lexicon_statistics.mdand thegenerated_pos_tagset.tsvfiles (the generated POS tagset files should be identical, but would be good as a check to ensure thatcreate_pos_tagsets.pyis refactored correctly).
Activity