diff options
| author | aarne <aarne@cs.chalmers.se> | 2007-10-05 07:33:33 +0000 |
|---|---|---|
| committer | aarne <aarne@cs.chalmers.se> | 2007-10-05 07:33:33 +0000 |
| commit | 07d2910df14842b1882512af0cb3717be6c303bc (patch) | |
| tree | 4fca75cadfd308ea8cedeea978e760d0159f844b /src/GF/GFCC/Generate.hs | |
| parent | a0f3aecc51c341be147049162861a0892523c835 (diff) | |
divided DataGFCC
Diffstat (limited to 'src/GF/GFCC/Generate.hs')
| -rw-r--r-- | src/GF/GFCC/Generate.hs | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/src/GF/GFCC/Generate.hs b/src/GF/GFCC/Generate.hs index 758e96d8c..09212976a 100644 --- a/src/GF/GFCC/Generate.hs +++ b/src/GF/GFCC/Generate.hs @@ -1,5 +1,6 @@ module GF.GFCC.Generate where +import GF.GFCC.Macros import GF.GFCC.DataGFCC import GF.GFCC.AbsGFCC @@ -10,27 +11,17 @@ import System.Random generate :: GFCC -> CId -> [Exp] generate gfcc cat = concatMap (\i -> gener i cat) [0..] where - gener 0 c = [Tr (AC f) [] | (f, Typ [] _) <- fns c] + gener 0 c = [tree (AC f) [] | (f, Typ [] _) <- fns c] gener i c = [ tr | (f, Typ cs _) <- fns c, let alts = map (gener (i-1)) cs, ts <- combinations alts, - let tr = Tr (AC f) ts, + let tr = tree (AC f) ts, depth tr >= i ] - fns cat = - let fs = lookMap [] cat $ catfuns $ abstract gfcc - in [(f,ty) | f <- fs, Just (ty,_) <- [M.lookup f $ funs $ abstract gfcc]] - depth tr = case tr of - Tr _ [] -> 1 - Tr _ ts -> maximum (map depth ts) + 1 + fns = functionsToCat gfcc ---- from Operations -combinations :: [[a]] -> [[a]] -combinations t = case t of - [] -> [[]] - aa:uu -> [a:u | a <- aa, u <- combinations uu] -- generate an infinite list of trees randomly genRandom :: StdGen -> GFCC -> CId -> [Exp] @@ -45,16 +36,16 @@ genRandom gen gfcc cat = genTrees (randomRs (0.0, 1.0) gen) cat where (genTrees ds2 cat) -- else (drop k ds) genTree rs = gett rs where - gett ds (CId "String") = (Tr (AS "foo") [], 1) - gett ds (CId "Int") = (Tr (AI 12345) [], 1) - gett [] _ = (Tr (AS "TIMEOUT") [], 1) ---- + gett ds (CId "String") = (tree (AS "foo") [], 1) + gett ds (CId "Int") = (tree (AI 12345) [], 1) + gett [] _ = (tree (AS "TIMEOUT") [], 1) ---- gett ds cat = case fns cat of - [] -> (Tr (AM 0) [],1) + [] -> (tree (AM 0) [],1) fs -> let d:ds2 = ds (f,args) = getf d fs (ts,k) = getts ds2 args - in (Tr (AC f) ts, k+1) + in (tree (AC f) ts, k+1) getf d fs = let lg = (length fs) in fs !! (floor (d * fromIntegral lg)) getts ds cats = case cats of @@ -64,11 +55,10 @@ genRandom gen gfcc cat = genTrees (randomRs (0.0, 1.0) gen) cat where in (t:ts, k + ks) _ -> ([],0) - fns cat = - let fs = maybe [] id $ M.lookup cat $ catfuns $ abstract gfcc - in [(f,cs) | f <- fs, - Just (Typ cs _,_) <- [M.lookup f $ funs $ abstract gfcc]] + fns cat = [(f,cs) | (f, Typ cs _) <- functionsToCat gfcc cat] + +{- -- brute-force parsing method; only returns the first result -- note: you cannot throw away rules with unknown words from the grammar -- because it is not known which field in each rule may match the input @@ -77,3 +67,4 @@ searchParse :: Int -> GFCC -> CId -> [String] -> [Exp] searchParse i gfcc cat ws = [t | t <- gen, s <- lins t, words s == ws] where gen = take i $ generate gfcc cat lins t = [linearize gfcc lang t | lang <- cncnames gfcc] +-} |
