blob: 966ec90aa587505ed9d5050d3c728cd1def14db5 (
plain)
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
44
45
46
|
import SG
import PGF2
import Data.Char
import Data.List
main = do
db <- openSG "assets/semantics.db"
inTransaction db $ do
ls <- fmap lines $ readFile "../../../lib/src/translator/Dictionary.gf"
let glosses = [x | Just (fn,gloss) <- map gloss ls, x <- glossTriples fn gloss]
topics <- fmap (map toTriple . lines) $ readFile "topics.txt"
sequence_ [insertTriple db s p o | (s,p,o) <- glosses++topics]
closeSG db
toTriple l =
case readTriple l of
Just t -> t
Nothing -> error ("topics.txt: "++l)
gloss l =
case words l of
("fun":fn:_) -> case dropWhile (/='\t') l of
'\t':l -> Just (fn,l)
_ -> Nothing
_ -> Nothing
glossTriples fn s =
(if null gs then [] else [(fn_e,gloss,mkStr (merge gs))])++
(if null es then [] else [(fn_e,example,mkStr (merge (map (init . tail) es)))])
where
fn_e = mkApp fn []
gloss = mkApp "gloss" []
example = mkApp "example" []
(es,gs) = partition isExample (splitGloss s)
splitGloss s =
let (xs,s') = break (==';') s
in trim xs : case s' of
';':s -> splitGloss s
_ -> []
where
trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace
merge = intercalate "; "
isExample s = not (null s) && head s == '"' && last s == '"'
|