brute force parsing method in RunGFCC

This commit is contained in:
aarne
2006-09-20 15:19:44 +00:00
parent d15dc3908c
commit bee08345cb
2 changed files with 13 additions and 0 deletions

View File

@@ -61,3 +61,12 @@ generateRandom gen gfcc cat = genTrees (randomRs (0.0, 1.0) gen) cat where
let fs = maybe [] id $ M.lookup cat $ cats $ abstract gfcc
in [(f,cs) | f <- fs,
Just (Typ cs _) <- [M.lookup f $ funs $ abstract gfcc]]
-- 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
parse :: GFCC -> CId -> [String] -> [Exp]
parse gfcc cat ws = [t | t <- gen, s <- lins t, words s == ws] where
gen = take 1024 $ generate gfcc cat
lins t = [linearize gfcc lang t | lang <- cncnames gfcc]

View File

@@ -33,6 +33,10 @@ treat grammar s = case words s of
"gr":cat:n:_ -> do
gen <- newStdGen
mapM_ prlins $ take (read n) $ generateRandom gen grammar (CId cat)
"p":cat:ws -> do
case parse grammar (CId cat) ws of
t:_ -> prlins t
_ -> putStrLn "no parse found"
_ -> lins $ readExp s
where
lins t = mapM_ (lin t) $ cncnames grammar