summaryrefslogtreecommitdiff
path: root/src/PGF
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2008-10-20 08:42:39 +0000
committerkrasimir <krasimir@chalmers.se>2008-10-20 08:42:39 +0000
commiteb0fefec28cf9c089c55f1ef5de9c772faa61786 (patch)
tree8d9a8c88ea3bd7c6e5191c79a7722a0fdf76c1b6 /src/PGF
parent96bea5a0bbdf749ea6fc50b97e4740e44a56e814 (diff)
preparation for dep. types. The -cat option can take any type instead of just a category. The PGF API is generalized as well.
Diffstat (limited to 'src/PGF')
-rw-r--r--src/PGF/Generate.hs8
-rw-r--r--src/PGF/Parsing/FCFG.hs10
-rw-r--r--src/PGF/Parsing/FCFG/Active.hs4
-rw-r--r--src/PGF/Parsing/FCFG/Incremental.hs12
4 files changed, 17 insertions, 17 deletions
diff --git a/src/PGF/Generate.hs b/src/PGF/Generate.hs
index 518c2c71b..94be66245 100644
--- a/src/PGF/Generate.hs
+++ b/src/PGF/Generate.hs
@@ -8,8 +8,8 @@ import qualified Data.Map as M
import System.Random
-- generate an infinite list of trees exhaustively
-generate :: PGF -> CId -> Maybe Int -> [Tree]
-generate pgf cat dp = concatMap (\i -> gener i cat) depths
+generate :: PGF -> Type -> Maybe Int -> [Tree]
+generate pgf (DTyp _ cat _) dp = concatMap (\i -> gener i cat) depths
where
gener 0 c = [Fun f [] | (f, ([],_)) <- fns c]
gener i c = [
@@ -24,8 +24,8 @@ generate pgf cat dp = concatMap (\i -> gener i cat) depths
depths = maybe [0 ..] (\d -> [0..d]) dp
-- generate an infinite list of trees randomly
-genRandom :: StdGen -> PGF -> CId -> [Tree]
-genRandom gen pgf cat = genTrees (randomRs (0.0, 1.0 :: Double) gen) cat where
+genRandom :: StdGen -> PGF -> Type -> [Tree]
+genRandom gen pgf (DTyp _ cat _) = genTrees (randomRs (0.0, 1.0 :: Double) gen) cat where
timeout = 47 -- give up
diff --git a/src/PGF/Parsing/FCFG.hs b/src/PGF/Parsing/FCFG.hs
index fe56f8712..088c9f480 100644
--- a/src/PGF/Parsing/FCFG.hs
+++ b/src/PGF/Parsing/FCFG.hs
@@ -30,10 +30,10 @@ import qualified Data.Map as Map
parseFCFG :: String -- ^ parsing strategy
-> ParserInfo -- ^ compiled grammar (fcfg)
- -> CId -- ^ starting category
+ -> Type -- ^ start type
-> [String] -- ^ input tokens
-> Err [Tree] -- ^ resulting GF terms
-parseFCFG "bottomup" pinfo start toks = return $ Active.parse "b" pinfo start toks
-parseFCFG "topdown" pinfo start toks = return $ Active.parse "t" pinfo start toks
-parseFCFG "incremental" pinfo start toks = return $ Incremental.parse pinfo start toks
-parseFCFG strat pinfo start toks = fail $ "FCFG parsing strategy not defined: " ++ strat
+parseFCFG "bottomup" pinfo typ toks = return $ Active.parse "b" pinfo typ toks
+parseFCFG "topdown" pinfo typ toks = return $ Active.parse "t" pinfo typ toks
+parseFCFG "incremental" pinfo typ toks = return $ Incremental.parse pinfo typ toks
+parseFCFG strat pinfo typ toks = fail $ "FCFG parsing strategy not defined: " ++ strat
diff --git a/src/PGF/Parsing/FCFG/Active.hs b/src/PGF/Parsing/FCFG/Active.hs
index 0927a719b..ad1db7220 100644
--- a/src/PGF/Parsing/FCFG/Active.hs
+++ b/src/PGF/Parsing/FCFG/Active.hs
@@ -37,8 +37,8 @@ makeFinalEdge cat 0 0 = (cat, [EmptyRange])
makeFinalEdge cat i j = (cat, [makeRange i j])
-- | the list of categories = possible starting categories
-parse :: String -> ParserInfo -> CId -> [FToken] -> [Tree]
-parse strategy pinfo start toks = nubsort $ filteredForests >>= forest2trees
+parse :: String -> ParserInfo -> Type -> [FToken] -> [Tree]
+parse strategy pinfo (DTyp _ start _) toks = nubsort $ filteredForests >>= forest2trees
where
inTokens = input toks
starts = Map.findWithDefault [] start (startCats pinfo)
diff --git a/src/PGF/Parsing/FCFG/Incremental.hs b/src/PGF/Parsing/FCFG/Incremental.hs
index e5f64365f..38c2e6c95 100644
--- a/src/PGF/Parsing/FCFG/Incremental.hs
+++ b/src/PGF/Parsing/FCFG/Incremental.hs
@@ -22,11 +22,11 @@ import PGF.CId
import PGF.Data
import Debug.Trace
-parse :: ParserInfo -> CId -> [String] -> [Tree]
-parse pinfo start toks = maybe [] (\ps -> extractExps ps start) (foldM nextState (initState pinfo start) toks)
+parse :: ParserInfo -> Type -> [String] -> [Tree]
+parse pinfo typ toks = maybe [] (\ps -> extractExps ps typ) (foldM nextState (initState pinfo typ) toks)
-initState :: ParserInfo -> CId -> ParseState
-initState pinfo start =
+initState :: ParserInfo -> Type -> ParseState
+initState pinfo (DTyp _ start _) =
let items = do
cat <- fromMaybe [] (Map.lookup start (startCats pinfo))
(funid,args) <- foldForest (\funid args -> (:) (funid,args)) (\_ _ args -> args)
@@ -97,8 +97,8 @@ getCompletions (State pinfo chart items) w =
| isPrefixOf w tok = Map.insertWith Set.union tok (Set.singleton item) map
| otherwise = map
-extractExps :: ParseState -> CId -> [Tree]
-extractExps (State pinfo chart items) start = exps
+extractExps :: ParseState -> Type -> [Tree]
+extractExps (State pinfo chart items) (DTyp _ start _) = exps
where
(_,st) = process (\_ _ -> id) (sequences pinfo) (functions pinfo) (Set.toList items) () chart