brassica-1.0.0: Featureful sound change applier
CopyrightSee LICENSE file
LicenseBSD3
MaintainerBrad Neimann
Safe HaskellSafe-Inferred
LanguageHaskell2010

Brassica.SoundChange

Description

The modules below provide Brassica’s support for sound changes. For further details on their syntax and processing, refer to the reference guide, and the documentation of individual modules.

In brief, a sound changes file passes through the following phases:

  1. First it is parsed to a SoundChanges CategorySpec Directive
  2. Next it undergoes expansion to give a SoundChanges Expanded GraphemeList
  3. Finally it can be applied to a PWord using applyChanges or similar.

Words may also be extracted from a words file for application using tokeniseWords, and the file can be recreated using detokeniseWords or similar. (For an MDF file one can similarly use tokeniseMDF.)

For a simple example, the following sample applies a sound change file to a words file (without error-handling):

import Data.Maybe (mapMaybe)
import System.Environment (getArgs)
import Brassica.SoundChange

main :: IO ()
main = do
    [changesFile, wordsFile] <- getArgs
    changes <- readFile changesFile
    words <- readFile wordsFile

    let Right changesParsed = parseSoundChanges changes
        Right changesExpanded = expandSoundChanges changesParsed

        Right wordsTokenised =
            withFirstCategoriesDecl tokeniseWords changesExpanded words

        wordsOutput = fmap (mapMaybe getOutput . applyChanges changesExpanded) $ wordsTokenised

    putStrLn $ detokeniseWords $
        concatMap (splitMultipleResults "/") wordsOutput

If writing sound changes in Haskell, it is suggested to skip parsing and expansion and directly create a value of type SoundChanges Expanded (Bool, [Grapheme]). Expansion is of little use when Categorys and Autosegments can be assigned names in the code itself.

Documentation