Commits

Grzegorz Chrupała committed 13f4913

align.hs

  • Participants
  • Parent commits 11951a6

Comments (0)

Files changed (1)

+import Control.Applicative
+import Data.Char
+import System.Environment
 import Align
-import Data.Char
+import Codec.Binary.UTF8.String
+import Data.Word
+
 
 main :: IO ()
+main = do
+  [sf, tf] <- getArgs
+  srcs <- lines <$> readFile sf 
+  tgts <- lines <$> readFile tf 
+  putStr . unlines . map format $ zipWith alignment srcs tgts
+      
+    
+alignment :: String -> String -> [(Word8, Op Word8)]    
+alignment src tgt = zip src' (shiftUp $ align src' tgt') 
+  where src' = encode src
+        tgt' = encode tgt
+        
+format :: [(Word8, Op Word8)] -> String
+format ops = unlines [ unwords [show c, formatOp op] | (c,op) <- ops ]
 
+formatOp op | isEmpty op = "O"
+formatOp op = formatD (deletes op) ++ formatI (inserts op)
+
+formatI [] = ""
+formatI xs = "I"++show xs
+
+formatD Nothing = ""
+formatD (Just c) = "D"++show c ++ ";"
+