Permalink
Browse files

Improve Translator.hs + use it in performance test

  • Loading branch information...
1 parent be431dc commit 684cdd66c16dec20447118165ea93dc5c29d8f1a @Kaljurand Kaljurand committed Jun 13, 2012
Showing with 50 additions and 14 deletions.
  1. +5 −0 Makefile
  2. +24 −9 Translator.hs
  3. +0 −5 make-parser.sh
  4. +3 −0 make-pgf.bash
  5. +18 −0 run-lin-test.sh
View
@@ -84,3 +84,8 @@ test_precision_range:
bash run-precision-test.bash 100 6
bash run-precision-test.bash 100 7
+Parser: Parser.hs
+ ghc --make -o Parser Parser.hs
+
+Translator: Translator.hs
+ ghc --make -o Translator Translator.hs
View
@@ -1,22 +1,37 @@
module Main where
+-- Translates from STDIN to STDOUT, from Lang1 to Lang2.
+-- The (obligatory) command-line arguments are:
+--
+-- * PGF file
+-- * start category
+-- * source language
+-- * target language
+--
+-- Usage:
+--
+-- cat tests/acewiki_aceowl/sentences.txt | ./Translator TestAttempto.pgf ACEText TestAttemptoAce TestAttemptoCat
+
import PGF
-import System (getArgs)
+import Data.Maybe
+import System.Environment (getArgs)
main :: IO ()
main = do
- file:_ <- getArgs
- gr <- readPGF file
- loop (translate gr)
+ file:cat:lang1:lang2:_ <- getArgs
+ pgf <- readPGF file
+ loop (translate pgf (fromJust (readType cat)) (fromJust (readLanguage lang1)) (fromJust (readLanguage lang2)))
loop :: (String -> String) -> IO ()
loop trans = do
s <- getLine
- putStr ("ACE: " ++ s)
+ putStr s
putStrLn $ trans s
loop trans
-translate :: PGF -> String -> String
-translate gr s = case parseAllLang gr (startCat gr) s of
- (lg,t:_):_ -> " (" ++ (unlines [linearize gr l t | l <- languages gr, l /= lg]) ++ ")"
- _ -> " (NO PARSE)"
+translate :: PGF -> Type -> Language -> Language -> String -> String
+translate pgf cat lang1 lang2 s =
+ case parse_ pgf lang1 cat (Just 4) s of
+ (ParseFailed num, _) -> "|FAIL " ++ unwords (take num (words s))
+ (ParseOk trees, _) -> "|OK (" ++ show (length trees) ++ ") " ++ (unlines [linearize pgf lang2 t | t <- trees])
+ _ -> "|FAIL"
View
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-parser="Parser"
-
-ghc --make -o $parser ${parser}.hs
View
@@ -53,7 +53,10 @@ echo "Building PGF from:"
eval echo ${words}
# TODO: for some reason the output-dir parameter has no influence,
# so we don't use it, and the PGF is dropped into the current directory.
+# TODO: optimize-pgf seems to give much better performance,
+# but doesn't always work with multiple languages (parsing fails).
gf +RTS -${stack_size} -RTS --preproc=mkPresent --make --optimize-pgf --mk-index --name $name --path $path `eval echo ${words}`
+#gf +RTS -${stack_size} -RTS --preproc=mkPresent --make --mk-index --name $name --path $path `eval echo ${words}`
# Commented out because always creates empty output.
# It would be cool though to find out some day if ACE can be converted into a
View
@@ -0,0 +1,18 @@
+# Measures the "parse ACE + linearize as X" time of the given PGF for every language X.
+tests="tests/acewiki_aceowl"
+languages="Cat Dut Eng Fin Fre Ger Ita Spa Swe Urd"
+
+name="ACE-0_0_2"
+
+# ACE-0_0_2.pgf is compiled with the AceWiki grammar and all the languages.
+bash make-pgf.bash grammars/acewiki_aceowl/ "words/acewiki_aceowl/TestAttempto{Ace,Cat,Dut,Eng,Fin,Fre,Ger,Ita,Spa,Swe,Urd}.gf"
+
+for lang in ${languages}; do
+ echo "Translating to ${lang}" ;
+ t1=`date +%s` ;
+ cat ${tests}/sentences.txt | \
+ ./Translator ${name}.pgf ACEText TestAttemptoAce TestAttempto${lang} > out_${lang}.txt ;
+ t2=`date +%s` ;
+ t=`echo "scale=3; ($t2-$t1)/60" | bc`;
+ echo "${lang}: $t minutes" ;
+done

0 comments on commit 684cdd6

Please sign in to comment.