library(devtools)
install_github("guilhermegarcia/fonology")
Fonology package
Phonological Analysis in R
The
Fonology
package (Garcia, 2023) provides different functions that are relevant to phonology research and/or teaching. If you have any suggestions or feedback, please visit the GitHub page of the project. To install the package, you will need to function install_github()
from the devtools
package (see below). Here’s a slide presentation with a demo of the package (English, français, português).
Probabilistic grammars are now part of the package (see below). French is now part of the ipa()
function to transcribe words. You can know extract the stressed syllable of a string using getStress(..., syl = TRUE)
. You can also change parsing direction when extracting syllables using getSyl(..., from_right = FALSE)
(by default, the function always starts from the right). See documentation for each function (?name_of_function
) for more information.
How to install
Main functions and data
getFeat()
andgetPhon()
to work with distinctive featuresipa()
phonemically transcribes words (real or not) in Portuguese, French or Spanishmaxent()
builds a MaxEnt Grammar (see alsonhg()
)syllable()
extracts syllabic constituentssonDisp()
calculates the sonority dispersion of a given demisyllable or the average dispersion for a set of words—see alsomeanSonDisp()
for the average dispersion of a given wordwug_pt()
generates hypothetical words in PortuguesebiGram_pt()
calculates bigram probabilities for a given wordplotVowels()
generates vowel trapezoidsplotSon()
plots the sonority profile of a given wordipa2tipa()
translates IPA sequences intotipa
sequencesmonthsAge()
andmeanAge()
psl
contains the Portuguese Stress Lexiconpt_lex
contains a simplified version ofpsl
stopwords_pt
,stopwords_fr
andstopwords_sp
contain stopwords in Portuguese, French and Spanish
Distinctive features
The function getFeat()
requires a set of phonemes ph
and a language lg
. It outputs the minimal matrix of distinctive features for ph
given the phonemic inventory of lg
. Five languages are supported: English, French, Italian, Portuguese, and Spanish. You can also use a custom phonemic inventory. See examples below.
The function getPhon()
requires a feature matrix ft
(a simple vector in R) and a language lg
. It outputs the set of phonemes represented by ft
given the phonemic inventory of lg
. The languages supported are the same as those supported by getFeat()
, and you can again provide your own phonemic inventory.
library(Fonology)
getFeat(ph = c("i", "u"), lg = "English")
#> [1] "+hi" "+tense"
getFeat(ph = c("i", "u"), lg = "French")
#> [1] "Not a natural class in this language."
getFeat(ph = c("i", "y", "u"), lg = "French")
#> [1] "+syl" "+hi"
getFeat(ph = c("p", "b"), lg = "Portuguese")
#> [1] "-son" "-cont" "+lab"
getFeat(ph = c("k", "g"), lg = "Italian")
#> [1] "+cons" "+back"
library(Fonology)
getPhon(ft = c("+syl", "+hi"), lg = "French")
#> [1] "u" "i" "y"
getPhon(ft = c("-DR", "-cont", "-son"), lg = "English")
#> [1] "t" "d" "b" "k" "g" "p"
getPhon(ft = c("-son", "+vce"), lg = "Spanish")
#> [1] "z" "d" "b" "ʝ" "g" "v"
library(Fonology)
getFeat(ph = c("p", "f", "w"),
lg = c("a", "i", "u", "y", "p",
"t", "k", "s", "w", "f"))
#> [1] "-syl" "+lab"
getPhon(ft = c("-son", "+cont"),
lg = c("a", "i", "u", "s", "z",
"f", "v", "p", "t", "m"))
#> [1] "s" "z" "f" "v"
IPA transcription
The function ipa()
takes a word
(or a vector with multiple words, real or not) in Portuguese, French or Spanish in its orthographic form and returns its phonemic (i.e., broad) transcription, including syllabification and stress. The accuracy of grapheme-to-phoneme conversion is at least 80% for all three languages. Narrow transcription is available for Portuguese (based on Brazilian Portuguese), which includes secondary stress—this can be generated by adding narrow = T
to the function. Run ipa_pt_test()
and ipa_sp_test()
for sample words in both languages. By default, ipa()
assumes that lg = "Portuguese"
(or lg = "pt"
) and narrow = F
.
ipa("atlético")
#> [1] "a.ˈtlɛ.ti.ko"
ipa("cantalo", narrow = T)
#> [1] "kãn.ˈta.lʊ"
ipa("antidepressivo", narrow = T)
#> [1] "ˌãn.t͡ʃi.ˌde.pɾe.ˈsi.vʊ"
ipa("feris")
#> [1] "fe.ˈɾis"
ipa("mejorado", lg = "sp")
#> [1] "me.xo.ˈɾa.do"
ipa("nuevos", lg = "sp")
#> [1] "nu.ˈe.bos"
ipa("informatique", lg = "fr")
#> [1] "ɛ̃.fɔʁ.ma.tik"
ipa("acheter", lg = "fr")
#> [1] "a.ʃə.te"
A more detailed function, ipa_pt()
, is available for Portuguese only. In it, stress is assigned based on two scenarios. First, real words (non-verbs) have their stress assignment derived from the Portuguese Stress Lexicon (Garcia, 2014)—if the word is listed there. Second, nonce words follow the general patterns of Portuguese stress as well as probabilistic tendencies shown in my work (Garcia, 2017a, 2017b, 2019). As a result, a nonce word may have antepenultimate stress under the right conditions based on lexical statistics in the language. Likewise, words with other so-called exceptional stress patterns are also generated probabilistically (e.g., LH]
words with penultimate stress). Stress and weight are also used to apply both spondaic and dactylic lowering to narrow transcriptions, following work such as Wetzels (2007). Secondary stress is provided when narrow = T
. For ipa()
, stress is not probabilistic (and therefore not variable): it merely follows the orthography as well as the typical stress rules in Portuguese (and Spanish).
There are several assumptions about surface-forms when narrow = T
(i.e., for Portuguese). Most of these assumptions can be adjusted. Diphthongization, for example, is sensitive to phonotactics. A word such as CV.ˈV.CV
will be narrowly transcribed as ˈCGV.CV
(except when the initial consonant is an affricate (allophonic), which seems to lower the probability of diphthongization based on my judgement). Diphthongization is not applied if the onset is complex. Needless to say, these assumptions are based on a particular dialect of Brazilian Portuguese, and I do not expect all of them to seamlessly apply to other dialects (although some assumptions are more easily generalizable than others).
Narrow transcription also includes (final) vowel reduction, voicing assimilation, l-vocalization, vowel devoicing, palatalization, and epenthesis in sC
clusters and other consonant sequences that are expected to be repaired on surface forms (e.g., kt, gn). Examples can be generated with the function ipa_pt_test()
. Finally, it’s important to note that the goal of the ipa()
function is phonemic transcription, not narrow phonetic transcription. Furthermore, there are certain limitations imposed by ASCII
when it comes to specific phonetic diacritics (e.g., super- and subscript symbols, which affects secondary articulation).
Use ipa_pt()
if you have nonce words as well as real words in Portuguese and you’d like to generate stress probabilistically based on the lexical statistics in the language. Note that ipa_pt()
is not vectorized. Use ipa()
if you just want to transcribe a large number of words (real or not) in Portuguese or Spanish and you don’t care about probabilistic stress assignment (i.e., you’re fine with categorical stress assignment). 99% of the time, you will use ipa()
.
Helper functions
If you plan to tokenize texts and create a table with individual columns for stress and syllables, you can use some simple additional helper functions. For example, getWeight()
will take a syllabified word and return its weight profile (e.g., getWeight("kon.to")
will return HL
). The function getStress()
1 will return the stress position of a given word (up to preantepenultimate stress)—the word must already be stressed, but the symbol used can be specified in the function (argument stress
). The function can instead extract the stressed syllable with the argument syl = TRUE
. Finally, countSyl()
will return the number of syllables in a given string, and getSyl()
will extract a particular syllable from a string. For example, getSyl(word = "kom-pu-ta-doɾ", pos = 3, syl = "-")
will take the antepenultimate syllable of the string in question (you can set the direction of the parsing with the argument dir
). The default symbol for syllabification is the period.
Here’s a simple example of how you could tokenize a text and create a table with coded variables using the functions discussed thus far (and without using packages such as tm
or tidytext
)—note also the function cleanText()
.
library(tidyverse)
= "Por exemplo, em quase todas as variedades do português..."
text
= tibble(word = text |>
d cleanText())
= d |>
d mutate(IPA = ipa(word),
stress = getStress(IPA),
weight = getWeight(IPA),
syl3 = getSyl(IPA, 3),
syl2 = getSyl(IPA, 2),
syl1 = getSyl(IPA, 1),
syl_st = getStress(IPA, syl = TRUE)) |> # get stressed syllable
filter(!word %in% stopwords_pt) # remove stopwords
word | IPA | stress | weight | syl3 | syl2 | syl1 | syl_st |
---|---|---|---|---|---|---|---|
exemplo | e.ˈzem.plo | penult | LHL | e | zem | plo | zem |
quase | ˈkwa.ze | penult | LL | NA | kwa | ze | kwa |
todas | ˈto.das | penult | LH | NA | to | das | to |
variedades | va.ɾi.e.ˈda.des | penult | LLH | e | da | des | da |
português | poɾ.tu.ˈges | final | HLH | poɾ | tu | ges | ges |
We often need to extract onsets, nuclei, codas and rhymes from syllables. That’s what syllable()
does: given a syllable (phonemically transcribed), the function returns a constituent of interest. Let’s add columns to d
where we extract all constituents of the final syllable (syl1
column).
= d |>
d select(-c(syl3, syl2, stress)) |>
mutate(on1 = syllable(syl = syl1, const = "onset"),
nu1 = syllable(syl = syl1, const = "nucleus"),
co1 = syllable(syl = syl1, const = "coda"),
rh1 = syllable(syl = syl1, const = "rhyme"))