mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
Merge pull request #59 from inariksit/gftest
(gftest) Fixes/additions when comparing against older version
This commit is contained in:
@@ -935,6 +935,7 @@ hasConcrString gr str =
|
|||||||
type Context = String
|
type Context = String
|
||||||
type LinTree = ((Lang,Context),(Lang,String),(Lang,String),(Lang,String))
|
type LinTree = ((Lang,Context),(Lang,String),(Lang,String),(Lang,String))
|
||||||
data Comparison = Comparison { funTree :: String, linTree :: [LinTree] }
|
data Comparison = Comparison { funTree :: String, linTree :: [LinTree] }
|
||||||
|
|
||||||
instance Show Comparison where
|
instance Show Comparison where
|
||||||
show c = unlines $ funTree c : map showLinTree (linTree c)
|
show c = unlines $ funTree c : map showLinTree (linTree c)
|
||||||
|
|
||||||
@@ -945,27 +946,28 @@ showLinTree :: LinTree -> String
|
|||||||
showLinTree ((an,hl),(l1,t1),(l2,t2),(_l,[])) = unlines ["", an++hl, l1++t1, l2++t2]
|
showLinTree ((an,hl),(l1,t1),(l2,t2),(_l,[])) = unlines ["", an++hl, l1++t1, l2++t2]
|
||||||
showLinTree ((an,hl),(l1,t1),(l2,t2),(l3,t3)) = unlines ["", an++hl, l1++t1, l2++t2, l3++t3]
|
showLinTree ((an,hl),(l1,t1),(l2,t2),(l3,t3)) = unlines ["", an++hl, l1++t1, l2++t2, l3++t3]
|
||||||
|
|
||||||
compareTree :: Grammar -> Grammar -> [Grammar] -> Tree -> Comparison
|
compareTree :: Grammar -> Grammar -> [Grammar] -> Cat -> Tree -> Comparison
|
||||||
compareTree gr oldgr transgr t = Comparison {
|
compareTree gr oldgr transgr startcat t = Comparison {
|
||||||
funTree = "* " ++ show t
|
funTree = "* " ++ show t
|
||||||
, linTree = [ ( ("** ",hl), (langName gr,newLin), (langName oldgr, oldLin), transLin )
|
, linTree = [ ( ("** ",hl), (langName gr,newLin), (langName oldgr, oldLin), transLin )
|
||||||
| ctx <- ctxs
|
| ctx <- ctxs
|
||||||
, let hl = show (ctx dummyHole)
|
, let hl = show (ctx dummyHole)
|
||||||
|
, let newLin = linearize gr (ctx t)
|
||||||
|
, let oldLin = linearize oldgr (ctx t)
|
||||||
, let transLin = case transgr of
|
, let transLin = case transgr of
|
||||||
[] -> ("","")
|
[] -> ("","")
|
||||||
g:_ -> (langName g, linearize g (ctx t))
|
g:_ -> (langName g, linearize g (ctx t))
|
||||||
, let newLin = linearize gr (ctx t)
|
, newLin /= oldLin
|
||||||
, let oldLin = linearize oldgr (ctx t)
|
] }
|
||||||
, newLin /= oldLin ] }
|
|
||||||
where
|
where
|
||||||
w = top t
|
w = top t
|
||||||
c = snd (ctyp w)
|
c = snd (ctyp w)
|
||||||
cs = [ coe
|
cs = c:[ coe
|
||||||
| (cat,coe) <- coercions gr
|
| (cat,coe) <- coercions gr
|
||||||
, c == cat ]
|
, c == cat ]
|
||||||
ctxs = concat
|
ctxs = concat
|
||||||
[ contextsFor gr sc cat
|
[ contextsFor gr sc cat
|
||||||
| sc <- ccats gr (startCat gr)
|
| sc <- ccats gr startcat
|
||||||
, cat <- cs ]
|
, cat <- cs ]
|
||||||
langName gr = concrLang gr ++ "> "
|
langName gr = concrLang gr ++ "> "
|
||||||
|
|
||||||
@@ -1081,7 +1083,7 @@ bestTrees fun gr cats =
|
|||||||
bestExamples fun gr $ take 200 -- change this to something else if too slow
|
bestExamples fun gr $ take 200 -- change this to something else if too slow
|
||||||
[ featIthVec gr cats size i
|
[ featIthVec gr cats size i
|
||||||
| all (`S.member` nonEmptyCats gr) cats
|
| all (`S.member` nonEmptyCats gr) cats
|
||||||
, size <- [0..10]
|
, size <- [0..20]
|
||||||
, let card = featCardVec gr cats size
|
, let card = featCardVec gr cats size
|
||||||
, i <- [0..card-1]
|
, i <- [0..card-1]
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -114,8 +114,12 @@ main = do
|
|||||||
where
|
where
|
||||||
s = top t
|
s = top t
|
||||||
c = snd (ctyp s)
|
c = snd (ctyp s)
|
||||||
ctxs = concat [ contextsFor gr sc c
|
cs = c:[ coe
|
||||||
| sc <- ccats gr startcat ]
|
| (cat,coe) <- coercions gr
|
||||||
|
, c == cat ]
|
||||||
|
ctxs = concat [ contextsFor gr sc cat
|
||||||
|
| sc <- ccats gr startcat
|
||||||
|
, cat <- cs ]
|
||||||
|
|
||||||
output = -- Print to stdout or write to a file
|
output = -- Print to stdout or write to a file
|
||||||
if write_to_file args
|
if write_to_file args
|
||||||
@@ -149,9 +153,9 @@ main = do
|
|||||||
-- Test a tree
|
-- Test a tree
|
||||||
let trees = case tree args of
|
let trees = case tree args of
|
||||||
[] -> []
|
[] -> []
|
||||||
ts -> lines ts
|
ts -> [ readTree gr t | t <- lines ts ]
|
||||||
output $
|
output $
|
||||||
unlines [ testTree' (readTree gr tree) 1 | tree <- trees ]
|
unlines [ testTree' tree 1 | tree <- trees ]
|
||||||
|
|
||||||
-- Test a function
|
-- Test a function
|
||||||
let substrs xs = filter (/="*") $ groupBy (\a b -> a/='*' && b/='*') xs
|
let substrs xs = filter (/="*") $ groupBy (\a b -> a/='*' && b/='*') xs
|
||||||
@@ -368,7 +372,7 @@ main = do
|
|||||||
| funName <- funs -- comes from command line arg -f
|
| funName <- funs -- comes from command line arg -f
|
||||||
, let fs@(s:_) = lookupSymbol gr funName
|
, let fs@(s:_) = lookupSymbol gr funName
|
||||||
, let cat = snd $ Grammar.typ s ]
|
, let cat = snd $ Grammar.typ s ]
|
||||||
fromTb = [ (cat,[tree]) | tree <- treebank'
|
fromTb = [ (cat,[tree]) | tree <- treebank'++trees
|
||||||
, let (CC (Just cat) _) = ccatOf tree ]
|
, let (CC (Just cat) _) = ccatOf tree ]
|
||||||
|
|
||||||
treesToTest =
|
treesToTest =
|
||||||
@@ -381,25 +385,18 @@ main = do
|
|||||||
writeFile file ""
|
writeFile file ""
|
||||||
putStrLn "Testing functions in… "
|
putStrLn "Testing functions in… "
|
||||||
diff <- concat `fmap`
|
diff <- concat `fmap`
|
||||||
sequence [ do let cs = [ compareTree grammar otherGrammar grTrans t
|
sequence [ do let cs = [ compareTree grammar otherGrammar grTrans startcat t
|
||||||
| t <- trees ]
|
| t <- ttrees ]
|
||||||
putStr $ cat ++ " \r"
|
putStr $ cat ++ " \r"
|
||||||
-- prevent lazy evaluation; make printout accurate
|
-- prevent lazy evaluation; make printout accurate
|
||||||
appendFile ("/tmp/"++file) (unwords $ map show cs)
|
appendFile ("/tmp/"++file) (unwords $ map show cs)
|
||||||
return cs
|
return [ c | c@(Comparison f (x:xs)) <- cs ]
|
||||||
| (cat,trees) <- treesToTest ]
|
| (cat,ttrees) <- treesToTest ]
|
||||||
let relevantDiff = go [] [] diff where
|
|
||||||
go res seen [] = res
|
let shorterTree c1 c2 = length (funTree c1) `compare` length (funTree c2)
|
||||||
go res seen (Comparison f ls:cs) =
|
|
||||||
if null uniqLs then go res seen cs
|
|
||||||
else go (Comparison f uniqLs:res) (uniqLs++seen) cs
|
|
||||||
where uniqLs = deleteFirstsBy ctxEq ls seen
|
|
||||||
ctxEq (a,_,_,_) (b,_,_,_) = a==b
|
|
||||||
shorterTree c1 c2 = length (funTree c1) `compare` length (funTree c2)
|
|
||||||
writeFile file $ unlines
|
writeFile file $ unlines
|
||||||
[ show comp
|
[ show comp
|
||||||
| comp <- sortBy shorterTree relevantDiff ]
|
| comp <- sortBy shorterTree diff ]
|
||||||
|
|
||||||
|
|
||||||
writeLinFile (langName ++ "-lin-diff.org") gr ogr
|
writeLinFile (langName ++ "-lin-diff.org") gr ogr
|
||||||
putStrLn $ "Created file " ++ (langName ++ "-lin-diff.org")
|
putStrLn $ "Created file " ++ (langName ++ "-lin-diff.org")
|
||||||
|
|||||||
Reference in New Issue
Block a user