<<echo=FALSE, results=hide>>=
## Vowels and their quality
vowels <- rbind(
  c("i", "close", "front", "unrounded"),
  c("e", "close-mid", "front", "unrounded"),
  c("ɛ", "open-mid", "front", "unrounded"),
  c("a", "open", "front", "unrounded"),
  c("ɑ", "open", "back", "unrounded"),
  c("ɔ", "open-mid", "back", "rounded"),
  c("o", "close-mid", "back", "rounded"),
  c("u", "close", "back", "rounded"),
  c("y", "close", "front", "rounded"),
  c("ø", "close-mid", "front", "rounded"),
  c("œ", "open-mid", "front", "rounded"),
  c("ɶ", "open", "front", "rounded"),
  c("ɒ", "open", "back", "rounded"),
  c("ʌ", "open-mid", "back", "unrounded"),
  c("ɤ", "close-mid", "back", "unrounded"),
  c("ɯ", "close", "back", "unrounded"),
  c("ɨ", "close", "central", "unrounded"),
  c("ʉ", "close", "central", "rounded")
)
vowels <- cbind(vowels, "", "", "")

## Vowel quality parameters
height <- c("close", "near-close", "close-mid", "mid", "open-mid", "near-open", "open")
front_back <- c("front", "front centralized", "central", "back centralized", "back")
lips <- c("unrounded", "rounded")

## Binary coding of features
match_mchoice <- function(true, options) {
  x <- match(true, options)
  sapply(x, function(i) paste(append(rep(0, length(options) - 1), 1, after = i - 1), collapse = ""))
}
vowels[, 5] <- match_mchoice(vowels[,2], height)
vowels[, 6] <- match_mchoice(vowels[,3], front_back)
vowels[, 7] <- match_mchoice(vowels[,4], lips)

## Casually selecting two vowels
vowels <- vowels[sample(1:nrow(vowels), 2), ]

## Possible answers and correct solution
ans <- rep(c(height, front_back, lips), 2)
sol <- paste(t(vowels[, 5:7]), collapse = "|")
@

\begin{question}
Describe the following Cardinal vowels according to the three parameters
vowel height, frontness-backness, and lip rounding:

\begin{enumerate}
  \item \Sexpr{vowels[1,1]} is the ##ANSWER1## ##ANSWER2## ##ANSWER3## vowel.
  \item \Sexpr{vowels[2,1]} is the ##ANSWER4## ##ANSWER5## ##ANSWER6## vowel.
\end{enumerate}

<<echo=FALSE, results=tex>>=
answerlist(ans, markup = "latex")
@
\end{question}

\begin{solution}
For an overview of the 18 Cardinal vowels see \url{https://en.wikipedia.org/wiki/Cardinal_vowels}.

\begin{enumerate}
  \item \Sexpr{vowels[1,1]} is the \Sexpr{vowels[1,2]} \Sexpr{vowels[1,3]} \Sexpr{vowels[1,4]} vowel.
  \item \Sexpr{vowels[2,1]} is the \Sexpr{vowels[2,2]} \Sexpr{vowels[2,3]} \Sexpr{vowels[2,4]} vowel.
\end{enumerate}
\end{solution}

\exname{Cardinal vowels}
\extype{cloze}
\exclozetype{schoice|schoice|schoice|schoice|schoice|schoice}
\exsolution{\Sexpr{sol}}

