From 25e14b253d24a9409ec70758126d8a64f24a691d Mon Sep 17 00:00:00 2001 From: krasimir Date: Wed, 19 Apr 2017 13:00:46 +0000 Subject: now the database with glosses is compiled on the PC by running glosses.hs. On the phone we just extract the database --- src/ui/android/glosses.hs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/ui/android/glosses.hs') diff --git a/src/ui/android/glosses.hs b/src/ui/android/glosses.hs index 3776d569b..966ec90aa 100644 --- a/src/ui/android/glosses.hs +++ b/src/ui/android/glosses.hs @@ -1,10 +1,21 @@ import SG +import PGF2 import Data.Char import Data.List main = do - ls <- fmap lines $ readFile "../../../lib/src/translator/Dictionary.gf" - writeFile "assets/glosses.txt" (unlines [x | Just (fn,gloss) <- map gloss ls, x <- glossTriples fn gloss]) + 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 @@ -14,9 +25,12 @@ gloss l = _ -> Nothing glossTriples fn s = - (if null gs then [] else ["<"++fn++",gloss,"++show (merge gs)++">"])++ - (if null es then [] else ["<"++fn++",example,"++show (merge (map (init . tail) es))++">"]) + (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 = -- cgit v1.2.3