summaryrefslogtreecommitdiff
path: root/src/runtime/haskell/PGF/Morphology.hs
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2010-01-17 17:05:21 +0000
committerkrasimir <krasimir@chalmers.se>2010-01-17 17:05:21 +0000
commitaf13bae2dfb9adaa7c4aa273961fc09cc7ba1b7a (patch)
tree74ba570e4d202dff02f330b50e11a0fa09b068a6 /src/runtime/haskell/PGF/Morphology.hs
parent9e3d4c74dc807cb26bb36303d2157c70c0668a8e (diff)
now the linearization is completely based on PMCFG
Diffstat (limited to 'src/runtime/haskell/PGF/Morphology.hs')
-rw-r--r--src/runtime/haskell/PGF/Morphology.hs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/runtime/haskell/PGF/Morphology.hs b/src/runtime/haskell/PGF/Morphology.hs
index 9eee71a97..be786ebbb 100644
--- a/src/runtime/haskell/PGF/Morphology.hs
+++ b/src/runtime/haskell/PGF/Morphology.hs
@@ -2,11 +2,13 @@ module PGF.Morphology(Lemma,Analysis,Morpho,
buildMorpho,
lookupMorpho,fullFormLexicon) where
-import PGF.ShowLinearize (collectWords)
-import PGF.Data
import PGF.CId
+import PGF.Data
import qualified Data.Map as Map
+import qualified Data.Set as Set
+import qualified Data.IntMap as IntMap
+import Data.Array.IArray
import Data.List (intersperse)
-- these 4 definitions depend on the datastructure used
@@ -17,7 +19,23 @@ type Analysis = String
newtype Morpho = Morpho (Map.Map String [(Lemma,Analysis)])
buildMorpho :: PGF -> Language -> Morpho
-buildMorpho pgf lang = Morpho (Map.fromListWith (++) (collectWords pgf lang))
+buildMorpho pgf lang = Morpho $
+ case Map.lookup lang (concretes pgf) >>= parser of
+ Just pinfo -> collectWords pinfo
+ Nothing -> Map.empty
+
+collectWords pinfo = Map.fromListWith (++)
+ [(t, [(fun,lbls ! l)]) | (s,e,lbls) <- Map.elems (startCats pinfo)
+ , fid <- [s..e]
+ , FApply funid _ <- maybe [] Set.toList (IntMap.lookup fid (pproductions pinfo))
+ , let FFun fun lins = functions pinfo ! funid
+ , (l,seqid) <- assocs lins
+ , sym <- elems (sequences pinfo ! seqid)
+ , t <- sym2tokns sym]
+ where
+ sym2tokns (FSymKS ts) = ts
+ sym2tokns (FSymKP ts alts) = ts ++ [t | Alt ts ps <- alts, t <- ts]
+ sym2tokns _ = []
lookupMorpho :: Morpho -> String -> [(Lemma,Analysis)]
lookupMorpho (Morpho mo) s = maybe [] id $ Map.lookup s mo