pronounce-1.1.0.1: A Haskell library for interfacing with the CMU Pronouncing Dictionary

Copyright(c) Noah Goodman 2018
LicenseBSD3
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Text.Pronounce

Contents

Description

This is a library for interpresting the parsed Carnegie Mellon University Pronouncing Dictionary. It is modelled after Allison Parrish's python library, pronouncing.

Synopsis

Datatypes

type CMUdict = Map Text [Text] Source #

A Map from Entries to lists of possible pronunciations, serving as our representation of the CMU Pronouncing Dictionary

type UsesBin = Bool Source #

A type used to represent the option of decoding the dictionary from a binary file or parsing it from text

type DictComp = Reader CMUdict Source #

We are using the Reader monad to perform computations in the context of the CMU dictionary without having to pass it in or worry about initializing every time

type EntryWord = Text Source #

Convenient type aliases for transcription and entry

Using Text.Pronounce

initDict :: Maybe FilePath -> UsesBin -> IO CMUdict Source #

Initializes the cmu pronunctiation dictionary into our program, given an optional file name of the dictionary

stdDict :: IO CMUdict Source #

Default settings for initDict

runPronounce :: DictComp a -> CMUdict -> a Source #

Get the value from a series of Dictionary Computations by supplying the dictionary to the computation. This is just runReader.

Basic Functions

phonesForEntry :: EntryWord -> DictComp [Phones] Source #

Look up the pronunciation (list of possible phones) of a word in the dictionary

stressesForEntry :: EntryWord -> DictComp [Stress] Source #

Gives the stress pattern for a given word in the dictionary

stresses :: Phones -> Stress Source #

Isolates the stress pattern from a sequence of phones

syllableCount :: Phones -> Int Source #

Gives the syllable count of a given pronunciation

Searching the Dictionary

searchDictBy :: (Phones -> Bool) -> DictComp CMUdict Source #

Initializes a dictionary computation based on a selector function that operates on an individual phones. It returns a DictComp containing a CMUdict of all the entries that have at least one value satisfying the predicate.

search :: Phones -> DictComp [EntryWord] Source #

Given a sequence of phones, find all words that contain that sequence of phones

searchStresses :: Stress -> DictComp [EntryWord] Source #

Given a stress pattern, find all words that satisfy that pattern

Rhyming

rhymingPart :: Phones -> Phones Source #

Finds the rhyming part of the given phones.

rhymes :: EntryWord -> DictComp [EntryWord] Source #

Given a word, finds all other words that rhyme with it

Some Helper Functions

dictAppend :: (Applicative f, Monoid a) => DictComp (f a) -> DictComp (f a) -> DictComp (f a) Source #

Useful for nondeterministically combining several dictionary computations. Generally, one would call foldr1 (<||>) to get all the possible results of mapping a DictComp over a line of text (multiple words).

(<||>) :: (Applicative f, Monoid a) => DictComp (f a) -> DictComp (f a) -> DictComp (f a) infixl 3 Source #

Useful for nondeterministically combining several dictionary computations. Generally, one would call foldr1 (<||>) to get all the possible results of mapping a DictComp over a line of text (multiple words).

liftD :: Functor f => (a -> b) -> DictComp (f a) -> DictComp (f b) Source #

Lift functions to act on elements within a functor in a dictionary computation, such as a list of possible phones or stresses