How add_lex() works

Correcting transcriptions in Fonology 1.5.0

A word comes out wrong. You correct it once, and from then on every transcription uses your version — without losing the corrections that ship with the package.

Two ways to correct a word

Both are the same function. Which one you want depends on whether the pipeline is almost right or plainly wrong.

Give the word back with a stress or quality diacritic. It still runs through the normal rules — you are telling them what to assume. Available for Portuguese, Spanish and Italian.

add_lex_pt("bórdas")

ipa("bordas", lg = "pt")
#> [1] "ˈbɔr.das"      # was ˈbor.das*

Hand over the finished IPA. The rules are skipped entirely — for loanwords and names no rule will ever get right. Available for all five languages.

add_lex_pt("shampoo", ipa = "ʃam.ˈpu")

ipa("shampoo", lg = "pt")
#> [1] "ʃam.ˈpu"       # was ʃam.ˈpo.o*
WarningThe two modes are not interchangeable

The ipa argument stores its value verbatim and skips transcription, so passing a diacritized spelling there returns that spelling as the “transcription”. Since version 1.5.0, add_lex_*() warns when an override looks like orthography rather than IPA.

Where your entry sits

Every word runs the same gauntlet. The first store that recognises it wins, and the search stops there.

ipa("shampoo", lg = "pt") 1 Your IPA override exact transcription you supplied match ʃam.ˈpu returned verbatim, rules skipped no match 2 Your diacritized entry bórdas, chièdere, término match ˈbɔr.das your form runs through the rules no match 3 The corpus lexicon PSL · Lexique · CMU · Wiktionary match ˈfɛ.ra dictionary form, returned as is not in the lexicon 4 The rules grapheme-to-phoneme fallback blo.ˈri.ko* starred: nobody vouched for this Steps 1 and 2 are yours. Step 3 is the dictionary. Step 4 is a guess — and the star is the invitation to correct it with step 1 or 2.
The lookup order inside ipa(). An asterisk marks a form produced by rules alone, so starred output in a corpus is a ready-made list of words worth checking.

Your corrections and ours, side by side

Steps 1 and 2 each read from two places: the corrections shipped with the package, and the ones you added on this machine. They are merged every time you transcribe, and yours win.

Yours on this machine shampoo ʃã.ˈpu fôlego removed Shipped with the package shampoo ʃam.ˈpu fôlego ˈfo.le.go yours wins hides it In effect what ipa() actually uses shampoo ʃã.ˈpu your override sits on top of the shipped one fôlego hidden for you still ships; other people keep it everything else as shipped updates reach you in the next release
Because the two are merged rather than swapped, clearing your own entries never deletes a shipped correction --- and a correction added in a later release reaches you even though you keep a lexicon of your own.
NoteRemoving works on two levels

Call remove_lex_pt("shampoo") once and your override is gone, so the shipped transcription comes back. Call it again and the shipped one is hidden too. Nothing you do here affects anyone else’s copy.

From your machine into the package

Your entries live in your own data directory, not in the installed package and not in your script. For the maintainer, promote_lex() is the step that turns a local fix into one everybody gets.

add_lex_pt() you spot a bad word Your machine R_user_dir() promote_lex() maintainer only Release next version Everyone gets the fix local entries cleared — the fix now ships, so nothing is lost Everyone else stops at step two: entries stay on their machine, and that is enough.
The maintainer's loop. If you are not maintaining the package, report a mistranscribed common word as an issue instead --- then the fix ships for everyone rather than living on one laptop.

The whole interface

Every function in the user-lexicon interface
Call What it does
add_lex_pt("bórdas") Fix stress or vowel quality; the word still goes through the rules. Portuguese, Spanish and Italian.
add_lex_pt(w, ipa = "…") Store an exact transcription, skipping the rules. All five languages.
remove_lex_pt("bordas") Drop your entry. Again on the same word hides the shipped one.
export_lex("pt", file) Write your entries to a file, to share or to re-import.
promote_lex() Maintainer. Move your entries into the package’s own lexicon, then empty yours.
ImportantWorking on something you will publish?

Your entries live on your machine, so a colleague running your script will not have them. Declare the add_lex_*() calls at the top of the script — re-running them is safe — or ship the file from export_lex() alongside it.

Copyright © Guilherme Duarte Garcia