Hi
ich hab mal schnell nen Untertitel Korrektur Programm geschrieben.
Ich hatte meist Fehler bei der Unterscheidung vom kleinen "L" und
großen "i". Dies wäre insofern man die Standartschriftart Arial nutzt
kein Problem, aber wenn man auf andere umschwenkt, speziell jene
die Handschriften nachahmen, dann werden die Fehler ersichtlich.
Da wir gerade Haskell lernten und diese recht fix ist - für Problem-
lösungen habe ich mal eben das geschrieben. Das ist mehr vielleicht
der Interesse halber, als wirklich nützlich.
Bin für jede Verbesserung offen.
Code
{- stubtitle changer - version 1.0
much faster then the first version - due to the fact
having less - correction tuples in changeseng and changesengfront
-}
module Subtitlechange where
type Change = ([Char],[Char])
type Changes = [Change]
{- array of mistakes and their corrections
when parsing dvd bitmap subtitle with
subrip to a srt textfile
-}
changeseng :: Changes
changeseng = [(' l', ' I'),
('<i>l', '<i>I'),
('''l', '''I')]
{- array of chars, which can deliver
after an l
-}
vowelsy :: [Char]
vowelsy = ['a','e','i','o','u','y']
{- have to distinguish the the difference
of the l and I at the beginning or in the string
-}
changesengfront :: Changes
changesengfront = [('l', 'I'),
('-l', '-I')]
main :: IO ()
main = do
putStr "Input-File: "
ifile <- getLine
putStr "Output-File: "
ofile <- getLine
x <- readFile ifile
writeFile ofile (concat [correctfront (correct str changeseng) changesengfront | str <-
(getNewLine x [])])
putStr "Done!!"
newline :: Char
newline = '\n'
{- seperate the input, which is taken as a
whole string into the lines which show up usually
at the shell or in an editor
-}
getNewLine :: String -> String -> [String]
getNewLine [] _ = []
getNewLine (x:xs) culi
| x == newline = (culi ++ [x]) : (getNewLine xs [])
| otherwise = getNewLine xs (culi ++ [x])
-- correcting mistakes in a string
correct :: String -> Changes -> String
correct [] _ = []
correct str [] = str
correct inputstr ((w,r):xs) = correct (correctone inputstr (w,r)) xs
correctone :: String -> Change -> String
correctone [] (w,r) = []
correctone inputstr (w,r)
| (length inputstr) < (wlength) = inputstr
| (take wlength inputstr) == w
&& not(elem (inputstr !! wlength) vowelsy) = r ++ correctone (drop wlength inputstr) (w,r)
| otherwise = (head inputstr):(correctone (tail inputstr) (w,r))
where
wlength = length w
-- correction of mistakes at the start of a string
correctfront :: String -> Changes -> String
correctfront [] _ = []
correctfront str [] = str
correctfront str ((w,r):xs)
| w == (take wlength str) && not(elem (str !! wlength) vowelsy) = r ++ drop wlength str
| otherwise = correctfront str xs
where
wlength = length w
Alles anzeigen
Kompilieren mit dem GHC (glasgow haskell compiler) hat nicht funktioniert.
Der Haskell Interpreter https://localhost/www.haskell.org hat auf jeden Fall funktioniert.
cu phate