From afe31be8f6fd28c8af56beeb5de1e587ae62f093 Mon Sep 17 00:00:00 2001 From: OleksandrZhabenko Date: Mon, 28 Dec 2020 13:24:25 +0200 Subject: [PATCH] Update on Hackage --- ChangeLog.md | 9 +++ LICENSE | 20 ++++++ Setup.hs | 2 + String/UniquenessPeriodsG.hs | 115 +++++++++++++++++++++++++++++++ uniqueness-periods-general.cabal | 25 +++++++ 5 files changed, 171 insertions(+) create mode 100644 ChangeLog.md create mode 100644 LICENSE create mode 100644 Setup.hs create mode 100644 String/UniquenessPeriodsG.hs create mode 100644 uniqueness-periods-general.cabal diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..769649a --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,9 @@ +# Revision history for uniqueness-periods-general + +## 0.1.0.0 -- 2020-08-16 + +* First version. Released on an unsuspecting world. + +## 0.2.0.0 -- 2020-08-18 + +* Second version. Some documentation improvements. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2eaab6b --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2020 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. diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/String/UniquenessPeriodsG.hs b/String/UniquenessPeriodsG.hs new file mode 100644 index 0000000..6775314 --- /dev/null +++ b/String/UniquenessPeriodsG.hs @@ -0,0 +1,115 @@ +-- | +-- Module : String.UniquenessPeriodsG +-- Copyright : (c) OleksandrZhabenko 2020 +-- License : MIT +-- Stability : Experimental +-- Maintainer : olexandr543@yahoo.com +-- +-- Can be used to produce the similar to 'String.Ukrainian.UniquenessPeriods' from +-- @uniqueness-periods@ package functions. Provides the generalization of them. +-- For all the used conversion functions of the type @g :: String -> Vector String@ +-- it is important that they are stable for the repeated application (their result after +-- the first application cannot be changed by the rules in the function into new variants). +-- Otherwise, the recursive scheme of the functions in the module will lead to wrong results. +-- So the conversion function should work the following way (@xs@ denotes a word in the language) in GHCi: +-- +-- > let v = g xs +-- > let ys = concat . toList $ v +-- > let v2 = g ys +-- > v == v2 +-- > True +-- +-- Or in the other words, for the single word, @g . concat . toList . g = g@; +-- + +module String.UniquenessPeriodsG ( + -- * Auxiliary functions + show7s''' + , show7s5 + , show7s6 + , show7sn4' + , show7snc + -- ** Inner predicate (auxiliary) + , eqSnds + -- ** Inner backward conversion function + , listToString + -- * uniquenessPeriods function + , uniquenessPeriods +) where + +import Data.Char (isSpace) +import qualified Data.Vector as V +import Data.List ((\\),nubBy) + +-- | Function 'listToString' converts the list of Strings being the sequential sounds representations into the text with whitespaces +-- (whitespaces are substituted instead of punctuation symbols, too) and some phonetic conversions. The first argument must be a list of 'String', +-- each of which is a representation for the white space (or more generally, non-sound symbol representation). +listToString :: [String] -> [String] -> String +listToString whspss = concatMap (\ts -> if ts `elem` whspss then " " else ts) + +-- | Function 'eqSnds' compares two non-silent Strings representations for sounds by equality. If one of them is a representation for silence (e. g. pause), +-- then the predicate is @False@. The first argument must be a list of 'String', +-- each of which is a representation for the white space (or more generally, non-sound symbol representation). +eqSnds :: [String] -> String -> String -> Bool +eqSnds whspss xs ys + | xs `elem` whspss || ys `elem` whspss = False + | otherwise = xs == ys + +-- | The same as @show7s''@ from MMSyn7s module (@mmsyn7s@ package), but the second element in the resulting tuple is again the text with +-- whitespaces (whitespaces are substituted +-- instead of punctuation symbols, too) and some phonetic conversions. The first argument must be a list of 'String', +-- each of which is a representation for the white space (or more generally, non-sound symbol representation). +show7s''' :: [String] -> [String] -> ([String],String) +show7s''' whspss zss = + let (xss, yss) = splitAt 200 zss + uss = xss \\ nubBy (eqSnds whspss) xss + (wss,vss) = if null uss then (xss,[]) else (takeWhile (/= head uss) xss ++ head uss:(takeWhile (/= head uss) . tail . dropWhile (/= head uss) $ xss), + dropWhile (/= head uss) . tail . dropWhile (/= head uss) $ xss) in + (filter (\x -> x `notElem` whspss) $ wss, listToString whspss $ vss ++ yss) + +-- | Function 'show7s5' takes a text being a @String@ and returns a tuple, the first element of which is a list of Strings that correspond to the +-- sounds representations that (except pauses) are unique and are not repeated starting from the beginning of the given text (this list is filtered from +-- the representations for the silence), and the second one is a @String@ obtained from the remainder +-- list of Strings starting from the first duplicated non-silent sound representation with whitespaces (whitespaces are substituted +-- instead of punctiuation symbols, too) and some phonetic conversions. The first argument must be a list of 'String', +-- each of which is a representation for the white space (or more generally, non-sound symbol representation). The second argument is a function that +-- converts a 'String' of the text into the 'V.Vector' of sound representations for that language. +show7s5 :: [String] -> (String -> V.Vector String) -> String -> ([String], String) +show7s5 whspss g = show7s''' whspss . V.toList . g + +-- | Function 'show7s6' takes a text being a @String@ and returns a list of lists of Strings, each latter one of which is obtained for the unique parts of +-- the text from the sounds representations point of view. It can show how many and what sound representations are needed to be created to completely cover +-- the given text providing all the needed sound parameters. The first argument must be a list of 'String', +-- each of which is a representation for the white space (or more generally, non-sound symbol representation). The second argument is a function that +-- converts a 'String' of the text into the 'V.Vector' of sound representations for that language. +show7s6 :: [String] -> (String -> V.Vector String) -> String -> [[String]] +show7s6 whspss g t@(_:_) = (fst . show7s5 whspss g $ t):(show7s6 whspss g . snd . show7s5 whspss g $ t) +show7s6 _ _ _ = [] + +-- | Function 'uniquenessPeriods' takes a text being a @String@ and returns a list of Ints. Each Int value is a number of +-- the sounds representations (non-silent ones) being unique and not duplicated alongside the given text starting from the beginning to the end. +-- This function provides some important information about the phonetic and in some cases semantic structures of the text. +-- The first argument must be a list of 'String', +-- each of which is a representation for the white space (or more generally, non-sound symbol representation). The second argument is a function that +-- converts a 'String' of the text into the 'V.Vector' of sound representations for that language. +uniquenessPeriods :: [String] -> (String -> V.Vector String) -> String -> [Int] +uniquenessPeriods whspss g xs + | any (not . isSpace) xs = fmap length . show7s6 whspss g $ xs + | otherwise = [0::Int] + +-- | Converts a list of 'String' each one being a non-silent sound representation into a list of 'Int' using recursively @show7sn4'@. +-- The first argument must be a list of 'String', +-- each of which is a representation for the white space (or more generally, non-sound symbol representation). +show7snc :: [String] -> [String] -> [Int] +show7snc whspss xss = let (tss,vss) = show7sn4' whspss xss in if null vss then [length tss] else length tss:show7snc whspss vss + +-- | The same as @show7sn'''@ from the MMSyn7s module from the @mmsyn7s@ package, but does not concatenate the list of 'String' as the second tuple's element. +-- The first argument must be a list of 'String', +-- each of which is a representation for the white space (or more generally, non-sound symbol representation). +show7sn4' :: [String] -> [String] -> ([String],[String]) +show7sn4' whspss zss = + let (xss, yss) = splitAt 200 zss + uss = xss \\ nubBy (eqSnds whspss) xss + (wss,vss) = if null uss then (xss,[]) else (takeWhile (/= head uss) xss ++ head uss:(takeWhile (/= head uss) . tail . dropWhile (/= head uss) $ xss), + dropWhile (/= head uss) . tail . dropWhile (/= head uss) $ xss) in + (filter (\x -> x `notElem` whspss) $ wss, vss ++ yss) diff --git a/uniqueness-periods-general.cabal b/uniqueness-periods-general.cabal new file mode 100644 index 0000000..c8f6e0d --- /dev/null +++ b/uniqueness-periods-general.cabal @@ -0,0 +1,25 @@ +-- Initial uniqueness-periods-general.cabal generated by cabal init. For +-- further documentation, see http://haskell.org/cabal/users-guide/ + +name: uniqueness-periods-general +version: 0.2.0.0 +synopsis: Can be used to produce the similar to 'String.Ukrainian.UniquenessPeriods' functions. +description: Can be used to produce the similar to 'String.Ukrainian.UniquenessPeriods' from uniqueness-periods package functions. Provides the generalization of them. +homepage: https://hackage.haskell.org/package/uniqueness-periods-general +license: MIT +license-file: LICENSE +author: OleksandrZhabenko +maintainer: olexandr543@yahoo.com +copyright: Oleksandr Zhabenko +category: Language +build-type: Simple +extra-source-files: ChangeLog.md +cabal-version: >=1.10 + +library + exposed-modules: String.UniquenessPeriodsG + -- other-modules: + -- other-extensions: + build-depends: base >=4.7 && <4.15, vector >=0.11 && <0.15 + -- hs-source-dirs: + default-language: Haskell2010