Copyright | (c) Noah Goodman 2018 |
---|---|
License | BSD3 |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
This is a library for interpreting the parsed Carnegie Mellon University Pronouncing
Dictionary. It is modelled after Allison Parrish's python library, pronouncing
.
Synopsis
- type CMUdict = Map Entry [Phones]
- type Entry = Text
- type Phones = [Text]
- type Stress = [Int]
- type DictComp = ReaderT CMUdict []
- dictcomp :: (CMUdict -> [a]) -> DictComp a
- runPronounce :: DictComp a -> CMUdict -> [a]
- initDict :: Maybe FilePath -> DictSource -> IO CMUdict
- stdDict :: IO CMUdict
- data DictSource
- phonesForEntry :: Entry -> DictComp Phones
- stressesForEntry :: Entry -> DictComp Stress
- noStress :: Phones -> Phones
- stresses :: Phones -> Stress
- syllableCount :: Phones -> Int
- entries :: DictComp Entry
- phoneses :: DictComp [Phones]
- pairs :: DictComp (Entry, [Phones])
- class DictField a
- filterDict :: DictField a => (a -> Bool) -> CMUdict -> CMUdict
- filterComp :: DictField a => (a -> Bool) -> DictComp b -> DictComp b
- search :: Phones -> DictComp Entry
- searchStresses :: Stress -> DictComp Entry
- rhymingPart :: Phones -> Phones
- rhymesUsing :: (Phones -> Phones -> Bool) -> Entry -> DictComp Entry
- rhymes :: Entry -> DictComp Entry
Fundamentals
Basic Datatypes
type CMUdict = Map Entry [Phones] Source #
A Map from Entry
s to lists of possible pronunciations (Phones
), serving as our
representation of the CMU Pronouncing Dictionary
Represents an entry word in the cmu pronouncing dictionary (simply an alias
for Text
to improve type specificity and readability
Represents a string containing the phonetic breakdown of a word, in a
similar manner to the EntryWord
type
Type alias for a stress pattern, which is a list of integers 0-2 indicating stress.
- 0 -> unstressed
- 1 -> primary stress
- 2 -> secondary stress
The Dictionary Computation Monad
type DictComp = ReaderT CMUdict [] Source #
We are using the List monad inside the ReaderT monad to perform nondeterministic computations
(due to the possibility of multiple Phones
patterns per Entry
) in the context of the
CMU dictionary without having to pass it as an argument to every function.
dictcomp :: (CMUdict -> [a]) -> DictComp a Source #
Contruct a Dictionary Computation based on a selector function on the
CMUdict
that returns a list of possible results. This is just a synonym for
the ReaderT
constructor.
runPronounce :: DictComp a -> CMUdict -> [a] Source #
Get the possible values resulting from a series of Dictionary Computations by supplying the
dictionary to the computation. This is just runReaderT
.
Using Text.Pronounce
initDict :: Maybe FilePath -> DictSource -> IO CMUdict Source #
Initializes the cmu pronunctiation dictionary into our program, given an optional file name of the dictionary
data DictSource Source #
Options for the initial source of the CMUDict. Currently, we can either parse from plaintext file or load preprocessed binary
Basic Functions
phonesForEntry :: Entry -> DictComp Phones Source #
Look up the pronunciation (list of possible phones) of a word in the dictionary
stressesForEntry :: Entry -> DictComp Stress Source #
Gives the stress pattern for a given word in the dictionary
syllableCount :: Phones -> Int Source #
Gives the syllable count of a given pronunciation
Searching the Dictionary
Field Selectors
entries :: DictComp Entry Source #
A Dictionary Computation that returns a list of all the entry words in the
CMUdict
phoneses :: DictComp [Phones] Source #
A Dictionary Computation that returns a list of all the lists of phones in
the CMUdict
pairs :: DictComp (Entry, [Phones]) Source #
A Dictionary Computation that returns a list of all the (key,value) pairs
in the
CMUdict@
Filtering Searches
A class that provides a generalized function filterDict
for filtering the
CMUdict
based on a choice of different "fields"
filterComp :: DictField a => (a -> Bool) -> DictComp b -> DictComp b Source #
Filter a the results of a DictComp
, taking only those whose corresponing
entries conform to the selector function
Specific Searches
search :: Phones -> DictComp Entry Source #
Given a sequence of phones, find all words that contain that sequence of phones
searchStresses :: Stress -> DictComp Entry 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, where the rhyming part is defined as everything in a word after and including the last stressed or semistressed phone. Note that this is merely one interpretation of what constitutes a rhyme. There exist both stricter and looser definitions that may be suited to different purposes.