packages feed

string-interpreter 0.5.5.0 → 0.6.0.0

raw patch · 4 files changed

+78/−6 lines, 4 files

Files

ChangeLog.md view
@@ -45,3 +45,9 @@ ## 0.5.5.0 -- 2022-03-24  * Fifth version revised F. Updated the dependency boundaries to support the latest GHC and Cabal versions.++## 0.6.0.0 -- 2022-04-25++* Sixth version. Fixed issue with splitting for negative position argument. Added the possibility to+concat just two words in any position. Added a variant of the function convStringInterpreterIO with the possibility+to correct the long splitting after revision.
Interpreter/StringConversion.hs view
@@ -1,9 +1,10 @@ {-# OPTIONS_HADDOCK show-extensions #-} {-# LANGUAGE ScopedTypeVariables #-} + -- | -- Module      :  Interpreter.StringConversion--- Copyright   :  (c) OleksandrZhabenko 2021+-- Copyright   :  (c) OleksandrZhabenko 2021-2022 -- License     :  MIT -- Stability   :  Experimental -- Maintainer  :  olexandr543@yahoo.com@@ -25,7 +26,7 @@  | null contrs = xs  | null . words $ xs = xs  | case filter (\y -> isDigit y || y == '/' || y == '-') contrs of { a:'/':bs -> a /= '/' && a /= '0' ; ~rrr -> False } =-     let ys = filter (\y -> isDigit y || y == '/') contrs in+     let ys = filter (\y -> isDigit y || y == '/' || y == '-') contrs in        case ys of          ~a:'/':bs -> let wordsN = words xs                           wordN = min (fromMaybe 1 (readMaybe [a]::Maybe Int)) (length wordsN)@@ -39,7 +40,10 @@                             if null wss then twoWords `mappend` (' ':unwords kss)                             else unwords wss `mappend` (' ':twoWords) `mappend` (' ':unwords kss)  | length (filter (\t -> if (length . words $ xs) >= 10 then t >= '1' && t <= '9' else t >= '1' && [t] <= show (length . words $ xs)) $ contrs) < 2 = xs- | otherwise = let cntrs = filter (\t -> if (length . words $ xs) >= 10 then t >= '1' && t <= '9' else t >= '1' && [t] <= show (length . words $ xs)) $ contrs+ -- The following case is changed since the version 0.6.0.0 to support concatenations of the arbitrary two words, not needed to be consequent ones.+ | otherwise = let cntrs = (if take 1 (filter isDigit contrs) == "0" then "0" else []) `mappend`+                     (filter (\t -> if (length . words $ xs) >= 10 then t >= '1' && t <= '9'+                                    else t >= '1' && [t] <= show (length . words $ xs)) $ contrs)                    tss = words xs in                      case length cntrs of                       2 -> let pos = fromJust (readMaybe (take 1 cntrs)::Maybe Int)@@ -49,10 +53,72 @@                                  if length tss < pos + number - 1 then xs                                  else if null zss then concat kss `mappend` " " `mappend` unwords lss                                       else unwords zss `mappend` " " `mappend` concat kss `mappend` " " `mappend` unwords lss-                      _ -> let idxs = map (\x -> fromJust (readMaybe [x]::Maybe Int)) $ cntrs+                      _ -> let idxs = map (\x -> fromJust (readMaybe [x]::Maybe Int)) $ (if take 1 cntrs == "0" then drop 1 cntrs else cntrs)                                wordsN = map (\i -> tss !! (i - 1)) idxs                                restWords = tss \\ wordsN                                  in unwords restWords `mappend` " " `mappend` concat wordsN++{-| Variant of the 'convStringInterpreter' with the additional possibility to correct splitting after revision. -}+convStringInterpreterIO :: String -> String -> IO String+convStringInterpreterIO contrs xs+ | null contrs = return xs+ | null . words $ xs = return xs+ | case filter (\y -> isDigit y || y == '/' || y == '-') contrs of { a:'/':bs -> a /= '/' && a /= '0' ; ~rrr -> False } =+     let ys = filter (\y -> isDigit y || y == '/' || y == '-') contrs in+       case ys of+         ~a:'/':bs -> do+                        let wordsN = words xs+                            wordN = min (fromMaybe 1 (readMaybe [a]::Maybe Int)) (length wordsN)+                            pos = fromMaybe 0 (readMaybe bs::Maybe Int)+                            wrdP = wordsN !! (wordN - 1)+                        if abs pos >= 8 then do+                          corr pos wrdP >>= \pos2 -> correctionF pos2 wrdP wordN wordsN+                        else correctionF pos wrdP wordN wordsN+ | length (filter (\t -> if (length . words $ xs) >= 10 then t >= '1' && t <= '9' else t >= '1' && [t] <= show (length . words $ xs)) $ contrs) < 2 = return xs+ | otherwise = let cntrs = (if take 1 (filter isDigit contrs) == "0" then "0" else []) `mappend`+                     (filter (\t -> if (length . words $ xs) >= 10 then t >= '1' && t <= '9'+                                    else t >= '1' && [t] <= show (length . words $ xs)) $ contrs)+                   tss = words xs in+                     case length cntrs of+                      2 -> let pos = fromJust (readMaybe (take 1 cntrs)::Maybe Int)+                               number = fromJust (readMaybe (drop 1 cntrs)::Maybe Int)+                               (zss,yss) = splitAt (pos - 1) tss+                               (kss,lss) = splitAt number yss in+                                 if length tss < pos + number - 1 then return xs+                                 else if null zss then return (concat kss `mappend` " " `mappend` unwords lss)+                                      else return (unwords zss `mappend` " " `mappend` concat kss `mappend` " " `mappend` unwords lss)+                      _ -> let idxs = map (\x -> fromJust (readMaybe [x]::Maybe Int)) $ (if take 1 cntrs == "0" then drop 1 cntrs else cntrs)+                               wordsN = map (\i -> tss !! (i - 1)) idxs+                               restWords = tss \\ wordsN+                                 in return (unwords restWords `mappend` " " `mappend` concat wordsN)++corr :: Int -> String -> IO Int+corr pos wrdP = do+  let (ts, us) | pos >= 0 = splitAt pos wrdP+               | otherwise = splitAt (length wrdP + pos) wrdP+      twoWords = ts `mappend` (' ':us)+  putStrLn $ "?:       " `mappend` twoWords+  llls <- getLine+  if null llls then return pos+  else do+    let tss = words llls+        wrd0 = fromMaybe 1 (readMaybe (concat . take 1 $ tss)::Maybe Int)+        posN = fromMaybe 0 (readMaybe (concat . drop 1 . take 2 $ tss)::Maybe Int)+    case wrd0 of+      1 -> corr (pos - posN) wrdP+      2 -> corr (pos + posN) wrdP+      _ -> corr pos wrdP++correctionF :: Monad m => Int -> String -> Int -> [String] -> m String+correctionF pos wrdP wordN wordsN = do+  let (ts,us) | pos >= 0 = splitAt pos wrdP+              | otherwise = splitAt (length wrdP + pos) wrdP+      twoWords = ts `mappend` (' ':us)+      (wss,tss) = splitAt (wordN - 1) wordsN+      kss = drop 1 tss+  if null wss then return (twoWords `mappend` (' ':unwords kss))+              else return (unwords wss `mappend` (' ':twoWords) `mappend` (' ':unwords kss))+  {-| Inspired by: 'https://hackage.haskell.org/package/base-4.15.0.0/docs/src/GHC-IO.html#catch' Reads a textual file given by its 'FilePath' and returns its contents lazily. If there is
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2021 OleksandrZhabenko+Copyright (c) 2021-2022 OleksandrZhabenko  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
string-interpreter.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                string-interpreter-version:             0.5.5.0+version:             0.6.0.0 synopsis:            Is used in the phonetic languages approach (e. g. in the recursive mode). description:         A library that has commonly used functions for the phonetic-languages implementations that deals with String data. homepage:            https://hackage.haskell.org/package/string-interpreter