packages feed

toktok-0.5: tools/ExtractLexicon.hs

module Main where

import System (getArgs, getProgName)
import IO
import PGF (readPGF, readLanguage, getLexicon)
import Data.ByteString.Lazy.Char8 (pack, unpack)
import Codec.Text.IConv (convert)
--import System.Console.GetOpt

-- this is the main module to extract lexicon from a GF grammar.
-- the arguments are : grammar file, concrete syntax name.

main :: IO ()
main = do
       args <- getArgs
       case args of 
        [gram, lang] -> do
                        g <- readPGF gram
                        let Just l = readLanguage lang
                        putStrLn $ unlines $ map toUTF8 $ getLexicon g l
                        
        _ -> usage

usage :: IO ()
usage = do
        name <- getProgName
        hPutStrLn stderr $ "usage: " ++ name ++ " grammar.pgf LangName"

toUTF8 :: String -> String
toUTF8 = unpack . convert "LATIN1" "UTF-8" . pack