1
0
forked from GitHub/gf-core

export the morphology API from PGF

This commit is contained in:
krasimir
2009-09-28 12:06:20 +00:00
parent 97d25fa6c8
commit bb0be1e964
5 changed files with 34 additions and 25 deletions

View File

@@ -1,4 +1,6 @@
module PGF.Morphology where
module PGF.Morphology(Lemma,Analysis,Morpho,
buildMorpho,
lookupMorpho,fullFormLexicon) where
import PGF.ShowLinearize (collectWords)
import PGF.Data
@@ -9,24 +11,16 @@ import Data.List (intersperse)
-- these 4 definitions depend on the datastructure used
type Morpho = Map.Map String [(Lemma,Analysis)]
lookupMorpho :: Morpho -> String -> [(Lemma,Analysis)]
lookupMorpho mo s = maybe noAnalysis id $ Map.lookup s mo
buildMorpho :: PGF -> CId -> Morpho
buildMorpho pgf = Map.fromListWith (++) . collectWords pgf
prFullFormLexicon :: Morpho -> String
prFullFormLexicon mo =
unlines [w ++ " : " ++ prMorphoAnalysis ts | (w,ts) <- Map.assocs mo]
prMorphoAnalysis :: [(Lemma,Analysis)] -> String
prMorphoAnalysis lps = unlines [l ++ " " ++ p | (l,p) <- lps]
type Lemma = String
type Lemma = CId
type Analysis = String
noAnalysis :: [(Lemma,Analysis)]
noAnalysis = []
newtype Morpho = Morpho (Map.Map String [(Lemma,Analysis)])
buildMorpho :: PGF -> Language -> Morpho
buildMorpho pgf lang = Morpho (Map.fromListWith (++) (collectWords pgf lang))
lookupMorpho :: Morpho -> String -> [(Lemma,Analysis)]
lookupMorpho (Morpho mo) s = maybe [] id $ Map.lookup s mo
fullFormLexicon :: Morpho -> [(String,[(Lemma,Analysis)])]
fullFormLexicon (Morpho mo) = Map.toList mo