forked from GrammaticalFramework/gf-wordnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.hs
43 lines (41 loc) · 1.69 KB
/
check.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Data.Maybe
import Data.List
import Data.Char
import qualified Data.Map as Map
import PGF2
import System.IO
import System.Environment
import System.Directory
import System.FilePath
import Control.Monad(forM_)
main = do
args <- getArgs
checked <- case args of
[] -> do es <- fmap (catMaybes . map (readExpr . drop 5) . filter (\l -> take 4 l == "abs:") . lines) $ readFile "examples.txt"
let ids = nub (concatMap lemmas es)
return [("ParseSwe",ids),("ParseBul",ids)]
["-"] -> do ls <- fmap lines $ getContents
let res = [(lang,[(id,Just (unwords ws))]) | l <- ls, let (id:lang:ws) = words l]
return ((Map.toList . Map.fromListWith (++)) res)
forM_ checked $ \(lang,ids) ->
if null ids
then return ()
else do let fname = "WordNet"++drop 5 lang++".gf"
ls <- fmap lines $ readFile fname
(tmp_fname,hTmp) <- openTempFile "." fname
mapM_ (hPutStrLn hTmp . annotate ids) ls
hClose hTmp
renameFile tmp_fname fname
where
lemmas e =
case unApp e of
Just (f,[]) -> [(f,Nothing)]
Just (f,es) -> concatMap lemmas es
_ -> []
annotate checked l =
case words l of
("lin":id:"=":_) -> case lookup id checked of
Just Nothing -> (reverse . dropWhile (/=';') . reverse) l
Just (Just def) -> "lin "++id++" = "++def++" ;"
Nothing -> l
_ -> l