mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-21 09:02:50 -06:00
brute force parsing method in RunGFCC
This commit is contained in:
@@ -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
|
let fs = maybe [] id $ M.lookup cat $ cats $ abstract gfcc
|
||||||
in [(f,cs) | f <- fs,
|
in [(f,cs) | f <- fs,
|
||||||
Just (Typ cs _) <- [M.lookup f $ funs $ abstract gfcc]]
|
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]
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ treat grammar s = case words s of
|
|||||||
"gr":cat:n:_ -> do
|
"gr":cat:n:_ -> do
|
||||||
gen <- newStdGen
|
gen <- newStdGen
|
||||||
mapM_ prlins $ take (read n) $ generateRandom gen grammar (CId cat)
|
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
|
_ -> lins $ readExp s
|
||||||
where
|
where
|
||||||
lins t = mapM_ (lin t) $ cncnames grammar
|
lins t = mapM_ (lin t) $ cncnames grammar
|
||||||
|
|||||||
Reference in New Issue
Block a user