phonetic-languages-simplified-examples-common (empty) → 0.1.0.0
raw patch · 7 files changed
+210/−0 lines, 7 filesdep +basedep +heapsdep +mmsyn2-arraysetup-changed
Dependencies added: base, heaps, mmsyn2-array, phonetic-languages-constraints-array, phonetic-languages-simplified-common, phonetic-languages-simplified-properties-lists-double, phonetic-languages-ukrainian-array, subG, ukrainian-phonetics-basic-array
Files
- CHANGELOG.md +5/−0
- LICENSE +20/−0
- Phonetic/Languages/Common.hs +53/−0
- Phonetic/Languages/Simplified/DeEnCoding.hs +88/−0
- Phonetic/Languages/Simplified/SimpleConstraints.hs +17/−0
- Setup.hs +2/−0
- phonetic-languages-simplified-examples-common.cabal +25/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for phonetic-languages-simplified-examples-common++## 0.1.0.0 -- 2021-01-02++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2020-2021 OleksandrZhabenko++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Phonetic/Languages/Common.hs view
@@ -0,0 +1,53 @@+{-# OPTIONS_GHC -threaded -rtsopts #-}+{-# OPTIONS_HADDOCK show-extensions #-}+{-# LANGUAGE BangPatterns, FlexibleContexts #-}++-- |+-- Module : Phonetic.Languages.Common+-- Copyright : (c) OleksandrZhabenko 2020+-- License : MIT+-- Stability : Experimental+-- Maintainer : olexandr543@yahoo.com+--+--+--++module Phonetic.Languages.Common (+ fLines+ , fLinesIO+) where++import Data.SubG (subG)+import Melodics.ByteString.Ukrainian.Arr (isUkrainianL)+import Phonetic.Languages.Ukrainian.PrepareText+import Data.Char (isAlpha)+++fLines :: Int -> String -> [String]+fLines !toOneLine ys =+ let preText = filter (any (\x -> isUkrainianL x && isAlpha x)) . prepareText . (\z -> if toOneLine == 1 then unwords . words $ z else z) $ ys+ wss = map (length . subG " 01-") preText+ in helpG2 preText wss++helpG2 (t:ts) (r:rs)+ | r > 7 = filter (`notElem` "01-") t:helpG2 ts rs+ | otherwise = t:helpG2 ts rs+helpG2 _ _ = []++fLinesIO :: String -> IO ()+fLinesIO ys =+ let preText = filter (any (\x -> isUkrainianL x && isAlpha x)) . prepareText $ ys+ wss = map (length . subG " 01-") preText+ in mapM_ putStrLn . map (\(i,x) -> show (i + 1) ++ "\t" ++ x) . helpG3 . indexedL "" . helpG2 preText $ wss++-- | Is taken mostly from the Phonetic.Languages.Simplified.Lists.UniquenessPeriodsG module from the @phonetic-languages-simplified-common@ package.+indexedL :: Foldable t => b -> t b -> [(Int, b)]+indexedL y zs = foldr f v zs+ where !v = [(length zs,y)]+ f x ((j,z):ys) = (j-1,x):(j,z):ys+{-# INLINE indexedL #-}++helpG3 :: [a] -> [a]+helpG3 xs+ | null xs = []+ | otherwise = init xs
+ Phonetic/Languages/Simplified/DeEnCoding.hs view
@@ -0,0 +1,88 @@+{-# OPTIONS_GHC -threaded -rtsopts #-}+{-# OPTIONS_HADDOCK show-extensions #-}+{-# LANGUAGE BangPatterns #-}++-- |+-- Module : Phonetic.Languages.Simplified.DeEnCoding+-- Copyright : (c) OleksandrZhabenko 2020+-- License : MIT+-- Stability : Experimental+-- Maintainer : olexandr543@yahoo.com+--+-- Functions to encode and decode 'String' -> \['Int8'\] used in the Simple/Main.hs code.+-- Is taken from the @phonetic-languages-simplified-lists-examples@ package.++module Phonetic.Languages.Simplified.DeEnCoding where++import Data.Heap (Heap)+import qualified Data.Heap as Heap+import GHC.Int+import Data.Foldable (foldl')+import Data.List (sortBy,sort)+import System.IO++--default (Int, Double)++encodeToInt :: [String] -> Int+encodeToInt yss = foldl' (\x y -> x * 10 + y) 0 . map (\(j,_) -> fromEnum j) . sortBy (\x y -> compare (snd x) (snd y)) . trans2 $ yss+{-# INLINABLE encodeToInt #-}+++-- | Is taken mostly from the Phonetic.Languages.Simplified.Lists.UniquenessPeriodsG module from the @phonetic-languages-simplified-common@ package.+indexedL :: Foldable t => b -> t b -> [(Int8, b)]+indexedL y zs = foldr f v zs+ where !v = [(toEnum (length zs + 1),y)]+ f x ((j,z):ys) = (j-1,x):(j,z):ys+{-# INLINE indexedL #-}++trans2 :: [[a]] -> [(Int8, [a])]+trans2 = init . indexedL []+{-# INLINE trans2 #-}++trans232 :: [[a]] -> [(Int, [a])]+trans232 zs = init . foldr f v $ zs+ where !v = [(length zs + 1,[])]+ f x ((j,z):ys) = (j-1,x):(j,z):ys+{-# INLINE trans232 #-}++int2l :: Int -> [Int8]+int2l n+ | n < 10 = [toEnum n]+ | otherwise = int2l n1 `mappend` [l]+ where (!n1,!l0) = quotRem n 10+ !l = toEnum l0+{-# INLINABLE int2l #-}++-- | So:+-- > decodeToStr (int2l . encodeToInt . words $ xs) xs == unwords . words $ xs+--+decodeToStr :: [Int8] -> String -> String+decodeToStr ys = unwords . map snd . sortBy (\x y -> compare (fst x) (fst y)) . zip ys . sort . words+{-# INLINE decodeToStr #-}++-- | Every 'String' consists of words with whitespace symbols in between.+toHeap :: [String] -> Heap Int+toHeap yss@(xs:xss)+ | null xss = Heap.singleton . encodeToInt . words $ xs+ | otherwise = Heap.fromList . map (encodeToInt . words) $ yss+toHeap _ = Heap.empty+{-# INLINE toHeap #-}++fromHeap :: String -> Heap Int -> [String]+fromHeap ys heap+ | Heap.null heap = []+ | otherwise = map (flip decodeToStr ys . int2l) . Heap.toUnsortedList $ heap+{-# INLINE fromHeap #-}++intersectInterResults :: [String] -> [String] -> [String]+intersectInterResults zss+ | null zss = const []+ | otherwise = fromHeap (head zss) . Heap.intersect (toHeap zss) . toHeap+{-# INLINE intersectInterResults #-}++-- | Auxiliary printing function to define the line ending in some cases. Is taken from the+-- Languages.UniquenessPeriods.Vector.General.DebugG module from the @phonetic-languages-general@ package+newLineEnding :: String+newLineEnding+ | nativeNewline == LF = "\n"+ | otherwise = "\r\n"
+ Phonetic/Languages/Simplified/SimpleConstraints.hs view
@@ -0,0 +1,17 @@+-- |+-- Module : Phonetic.Languages.Simplified.SimpleConstraints+-- Copyright : (c) OleksandrZhabenko 2020+-- License : MIT+-- Stability : Experimental+-- Maintainer : olexandr543@yahoo.com+--+-- Some code shared for different Main modules.++module Phonetic.Languages.Simplified.SimpleConstraints where++import Data.Monoid++showB :: Int -> Bool -> String+showB n bool+ | n >= 2 && bool == True = 'B':show (n - 1) `mappend` concatMap show [0..n - 2]+ | otherwise = ""
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ phonetic-languages-simplified-examples-common.cabal view
@@ -0,0 +1,25 @@+-- Initial phonetic-languages-simplified-examples-common.cabal generated by cabal init. For+-- further documentation, see http://haskell.org/cabal/users-guide/++name: phonetic-languages-simplified-examples-common+version: 0.1.0.0+synopsis: Some commonly used by phonetic-languages-simplified* series functions.+description: Are intended to be used by the phonetic-languages-simplified-lists-examples and phonetic-languages-simplified-examples-array packages.+homepage: https://hackage.haskell.org/package/phonetic-languages-simplified-examples-common+license: MIT+license-file: LICENSE+author: OleksandrZhabenko+maintainer: olexandr543@yahoo.com+copyright: (c) 2020-2021 Oleksandr Zhabenko+category: Language, Math, Game+build-type: Simple+extra-source-files: CHANGELOG.md+cabal-version: >=1.10++library+ exposed-modules: Phonetic.Languages.Simplified.DeEnCoding, Phonetic.Languages.Simplified.SimpleConstraints, Phonetic.Languages.Common+ -- other-modules:+ other-extensions: BangPatterns+ build-depends: base >=4.8 && <4.15, phonetic-languages-simplified-common >=0.4 && <1, phonetic-languages-simplified-properties-lists-double >=0.1 && <1, mmsyn2-array >=0.1.1 && <1, phonetic-languages-constraints-array >=0.1 && <1, heaps >= 0.3.6.1 && <1, subG >=0.4.2 && <1, phonetic-languages-ukrainian-array >=0.1 && <1, ukrainian-phonetics-basic-array >=0.1.1 && <1+ -- hs-source-dirs:+ default-language: Haskell2010