summaryrefslogtreecommitdiff
path: root/src/PGF
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2009-09-28 12:06:20 +0000
committerkrasimir <krasimir@chalmers.se>2009-09-28 12:06:20 +0000
commit288ef038f21a043aacd292b3e958aad06ac6beca (patch)
tree61e5616658f847889b71955af3dea25fd025d7cd /src/PGF
parent726d160c8d79f148b5dc14e5616ec4302fe084a9 (diff)
export the morphology API from PGF
Diffstat (limited to 'src/PGF')
-rw-r--r--src/PGF/Morphology.hs30
-rw-r--r--src/PGF/ShowLinearize.hs4
2 files changed, 14 insertions, 20 deletions
diff --git a/src/PGF/Morphology.hs b/src/PGF/Morphology.hs
index 2eb793d73..9eee71a97 100644
--- a/src/PGF/Morphology.hs
+++ b/src/PGF/Morphology.hs
@@ -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]
+type Lemma = CId
+type Analysis = String
-prMorphoAnalysis :: [(Lemma,Analysis)] -> String
-prMorphoAnalysis lps = unlines [l ++ " " ++ p | (l,p) <- lps]
+newtype Morpho = Morpho (Map.Map String [(Lemma,Analysis)])
-type Lemma = String
-type Analysis = String
+buildMorpho :: PGF -> Language -> Morpho
+buildMorpho pgf lang = Morpho (Map.fromListWith (++) (collectWords pgf lang))
-noAnalysis :: [(Lemma,Analysis)]
-noAnalysis = []
+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
diff --git a/src/PGF/ShowLinearize.hs b/src/PGF/ShowLinearize.hs
index d739d38f5..dd3b997a6 100644
--- a/src/PGF/ShowLinearize.hs
+++ b/src/PGF/ShowLinearize.hs
@@ -97,7 +97,7 @@ markLinearize pgf lang = concat . take 1 . linearizesMark pgf lang
-- for Morphology: word, lemma, tags
-collectWords :: PGF -> CId -> [(String, [(String,String)])]
+collectWords :: PGF -> Language -> [(String, [(CId,String)])]
collectWords pgf lang =
concatMap collOne
[(f,c,0) | (f,(DTyp [] c _,_,_)) <- Map.toList $ funs $ abstract pgf]
@@ -108,6 +108,6 @@ collectWords pgf lang =
RR rs -> concat [fromRec f v t | (_,t) <- rs]
RT rs -> concat [fromRec f (p:v) t | (p,t) <- rs]
RFV rs -> concatMap (fromRec f v) rs
- RS s -> [(s,[(showCId f,unwords (reverse v))])]
+ RS s -> [(s,[(f,unwords (reverse v))])]
RCon c -> [] ---- inherent