diff options
| author | bringert <unknown> | 2005-06-17 11:46:04 +0000 |
|---|---|---|
| committer | bringert <unknown> | 2005-06-17 11:46:04 +0000 |
| commit | 05b5ffe5bf03a870f6fe0728ace6c0d8de69b89e (patch) | |
| tree | 18298275e8397f200013b6aec8ee38bbd93e32b1 /src/GF/Speech/PrSLF.hs | |
| parent | 30e3a8fd991c7bad3d21b03749d6a8a0e7a7f8e5 (diff) | |
Added beginnings of ATK SLF generation.
Diffstat (limited to 'src/GF/Speech/PrSLF.hs')
| -rw-r--r-- | src/GF/Speech/PrSLF.hs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/GF/Speech/PrSLF.hs b/src/GF/Speech/PrSLF.hs new file mode 100644 index 000000000..044a94ed0 --- /dev/null +++ b/src/GF/Speech/PrSLF.hs @@ -0,0 +1,69 @@ +---------------------------------------------------------------------- +-- | +-- Module : PrSLF +-- Maintainer : BB +-- Stability : (stable) +-- Portability : (portable) +-- +-- > CVS $Date: 2005/06/17 12:46:05 $ +-- > CVS $Author: bringert $ +-- > CVS $Revision: 1.1 $ +-- +-- This module converts a CFG to an SLF finite-state network +-- for use with the ATK recognizer. The SLF format is described +-- in the HTK manual, and an example for use in ATK is shown +-- in the ATK manual. +-- +-- FIXME: remove \/ warn \/ fail if there are int \/ string literal +-- categories in the grammar +----------------------------------------------------------------------------- + +module GF.Speech.PrSLF (slfPrinter) where + +import GF.Speech.SRG +import GF.Speech.TransformCFG +import GF.Infra.Ident + +import GF.Formalism.CFG +import GF.Formalism.Utilities (Symbol(..)) +import GF.Conversion.Types +import GF.Infra.Print +import GF.Infra.Option + +import Data.Char (toUpper,toLower) + +data SLF = SLF [SLFNode] [SLFEdge] + +data SLFNode = SLFNode Int SLFWord + +type SLFWord = Maybe String + +data SLFEdge = SLFEdge Int Int Int + + +slfPrinter :: Ident -- ^ Grammar name + -> Options -> CGrammar -> String +slfPrinter name opts cfg = prSLF slf "" + where gr = makeNice cfg + gr' = makeRegular gr + srg = makeSRG name opts gr' + slf = srg2slf srg + +srg2slf :: SRG -> SLF +srg2slf = undefined + +prSLF :: SLF -> ShowS +prSLF (SLF ns es) = header . unlinesS (map prNode ns) . unlinesS (map prEdge es) + where + header = showString "VERSION=1.0" . nl + . prFields [("N",show (length ns)),("L", show (length es))] . nl + prNode (SLFNode i w) = prFields [("I",show i),("W",showWord w)] + prEdge (SLFEdge i s e) = prFields [("J",show i),("S",show s),("E",show e)] + + +showWord :: SLFWord -> String +showWord Nothing = "!NULL" +showWord (Just w) = w -- FIXME: convert words to upper case + +prFields :: [(String,String)] -> ShowS +prFields fs = unwordsS [ showString l . showChar '=' . showString v | (l,v) <- fs ] |
