phonetic-languages-phonetics-basics 0.8.4.0 → 0.9.0.0
raw patch · 5 files changed
+86/−62 lines, 5 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.Phonetic.Languages.PrepareText: complexNWords :: [[String]] -> [String] -> [String]
- Data.Phonetic.Languages.PrepareText: complexWords :: Concatenations -> Concatenations -> [String] -> [String]
- Data.Phonetic.Languages.PrepareText: prepareConcats :: [[String]] -> [Concatenations]
- Data.Phonetic.Languages.PrepareText: toSequentialApp :: Concatenations -> [Concatenations]
+ Data.Phonetic.Languages.PrepareText: concatWordsFromLeftToRight :: ConcatenationsArr -> String -> [String]
- Data.Phonetic.Languages.PrepareText: prepareGrowTextMN :: Int -> Int -> [[String]] -> String -> String -> [String]
+ Data.Phonetic.Languages.PrepareText: prepareGrowTextMN :: Int -> Int -> [[String]] -> [[String]] -> String -> String -> [String]
- Data.Phonetic.Languages.PrepareText: prepareText :: [[String]] -> String -> String -> [String]
+ Data.Phonetic.Languages.PrepareText: prepareText :: [[String]] -> [[String]] -> String -> String -> [String]
- Data.Phonetic.Languages.PrepareText: prepareTextN :: Int -> [[String]] -> String -> String -> [String]
+ Data.Phonetic.Languages.PrepareText: prepareTextN :: Int -> [[String]] -> [[String]] -> String -> String -> [String]
- Data.Phonetic.Languages.PrepareText: prepareTuneTextMN :: Int -> Int -> [[String]] -> String -> String -> [String]
+ Data.Phonetic.Languages.PrepareText: prepareTuneTextMN :: Int -> Int -> [[String]] -> [[String]] -> String -> String -> [String]
Files
- ChangeLog.md +7/−0
- Data/Phonetic/Languages/PrepareText.hs +60/−48
- LICENSE +1/−1
- README.md +14/−9
- phonetic-languages-phonetics-basics.cabal +4/−4
ChangeLog.md view
@@ -112,3 +112,10 @@ ## 0.8.4.0 -- 2021-09-04 * Eigth version revised D. Added new 'tuned' functions to the Data.Phonetic.Languages.PrepareText module.++## 0.9.0.0 -- 2022-02-09++* Ninth version. Fixed the long existing issues with not working prepending needed concatenations for the text in the+module Data.Phonetic.Languages.PrepareText. Added also the possibility to not only prepend needed words, but also append.+This introduces breaking changes, so please, wait for update for all the dependent packages before starting the upgrade, also+check the code that uses library functions afterwards.
Data/Phonetic/Languages/PrepareText.hs view
@@ -1,6 +1,10 @@+{-# OPTIONS_HADDOCK show-extensions #-}++{-# LANGUAGE MultiWayIf #-}+ -- | -- Module : Data.Phonetic.Languages.PrepareText--- Copyright : (c) OleksandrZhabenko 2020-2021+-- Copyright : (c) OleksandrZhabenko 2020-2022 -- License : MIT -- Stability : Experimental -- Maintainer : olexandr543@yahoo.com@@ -27,14 +31,11 @@ module Data.Phonetic.Languages.PrepareText ( Concatenations -- * Basic functions- , complexWords+ , concatWordsFromLeftToRight , splitLines , splitLinesN , isSpC , sort2Concat- , toSequentialApp- , prepareConcats- , complexNWords -- * The end-user functions , prepareText , prepareTextN@@ -46,7 +47,7 @@ , isPLL ) where -import CaseBi.Arr (getBFstL')+import CaseBi.Arr (getBFstL',getBFst') import Data.List.InnToOut.Basic (mapI) import Data.Char (isAlpha,toLower) import GHC.Arr@@ -54,12 +55,19 @@ -- | The lists in the list are sorted in the descending order by the word counts in the inner 'String's. All the 'String's -- in each inner list have the same number of words, and if there is no 'String' with some intermediate number of words (e. g. there--- are not empty 'String's for 4 and 2 words, but there is no one for 3 words 'String's) then such corresponding list is empty, but--- it is, nevertheless, present. Probably the maximum number of words can be no more than 4, and the minimum number can be--- probably no less than 1, but it depends (especially for the maximum). The 'String's in the inner lists must be (unlike the inner+-- are 'String's for 4 and 2 words, but there is no one for 3 words 'String's) then such corresponding list is absent (since+-- the 0.9.0.0 version). Probably the maximum number of words can be not more than 4, and the minimum number is+-- not less than 1, but it depends. The 'String's in the inner lists must be (unlike the inner -- lists themselves) sorted in the ascending order for the data type to work correctly in the functions of the module. type Concatenations = [[String]] +type ConcatenationsArr = [Array Int (String,Bool)]++defaultConversion :: Concatenations -> ConcatenationsArr+defaultConversion ysss = map (f . filter (not . null)) . filter (not . null) $ ysss+ where f :: [String] -> Array Int (String,Bool)+ f yss = let l = length yss in listArray (0,l-1) . zip yss . cycle $ [True]+ -- | Is used to convert a phonetic language text into list of 'String' each of which is ready to be -- used by the functions from the other modules in the package. -- It applies minimal grammar links and connections between the most commonly used phonetic language@@ -68,6 +76,7 @@ -- \"phonetic\" language on the phonetic language basis. prepareText :: [[String]] -- ^ Is intended to become a valid 'Concatenations'.+ -> [[String]] -- ^ Is intended to become a valid 'Concatenations'. -> String -- ^ A sorted 'String' of possible characters in the phonetic language representation. -> String -> [String]@@ -76,59 +85,60 @@ sort2Concat :: [[String]]- -> Concatenations -- ^ Data used to concatenate the basic grammar preserving words and word sequences to the next word to+ -> Concatenations -- ^ Data used to concatenate the basic grammar preserving words and word sequences to the next word or+ -- to the previous word to -- leave the most of the meaning (semantics) of the text available to easy understanding while reading and listening to. sort2Concat xsss | null xsss = [] | otherwise = map sort . reverse . sortOn (map (length . words)) $ xsss -toSequentialApp- :: Concatenations -- ^ Data used to concatenate the basic grammar preserving words and word sequences to the next word to- -- leave the most of the meaning (semantics) of the text available to easy understanding while reading and listening to.- -> [Concatenations]-toSequentialApp ysss@(xss:xsss)- | null xss = toSequentialApp xsss- | otherwise = [xss, replicate (n - 1) []] : toSequentialApp xsss- where n = length . words . head $ xss-toSequentialApp _ = []+----------------------------------------------------- -prepareConcats- :: [[String]]- -> [Concatenations]-prepareConcats = toSequentialApp . sort2Concat-{-# INLINABLE prepareConcats #-}+complexWords2 :: ConcatenationsArr -> String -> (String -> String,String)+complexWords2 ysss@(yss:zsss) zs@(r:rs)+ | getBFst' (False, yss) . unwords $ tss = ((uwxs `mappend`), unwords uss)+ | otherwise = complexWords2 zsss zs+ where y = length . words . fst . unsafeAt yss $ 0+ (tss,uss) = splitAt y . words $ zs+ uwxs = concat tss+complexWords2 _ zs = (id,zs) -{-| Applies the full complex words concatenations (opposite to the 'complexWords' that applies only partial concatenations).--}-complexNWords :: [[String]] -> [String] -> [String]-complexNWords xsss yss = complexNWords' tssss yss- where tssss = prepareConcats xsss- complexNWords' tssss@(ysss:zssss) uss = complexNWords' zssss . complexWords ysss ysss $ uss- complexNWords' _ uss = uss+pairCompl :: (String -> String,String) -> (String,String)+pairCompl (f,xs) = (f [],xs) --- | Concatenates complex words in phonetic language so that they are not separated further by possible words order rearrangements (because they are treated--- as a single word). This is needed to preserve basic grammar in phonetic languages.-complexWords :: Concatenations -> Concatenations -> [String] -> [String]-complexWords rsss ysss zss- = map (\(ts,_,_) -> ts) . foldr f v $ zss- where v = [([],rsss,ysss)]- f z rs@((t,rsss,(yss:tsss)):ks)- | null yss = f z ((t,rsss,tsss):ks)- | getBFstL' False (zip yss . replicate 10000 $ True) uwxs = (filter (/= ' ') uwxs `mappend` t,rsss,rsss):ks- | otherwise = f z ((t,rsss,tsss):ks)- where y = length . words . head $ yss- uwxs = unwords . take y . map (\(q,_,_) -> q) $ rs- f z rs@((t,rsss,[]):ks) = (z,rsss,rsss):rs+splitWords :: ConcatenationsArr -> [String] -> String -> (String,String)+splitWords ysss tss zs = let (ws,us) = pairCompl . complexWords2 ysss $ zs in if+ | null . words $ zs -> (mconcat tss,[])+ | null ws -> (\(xss,uss) -> (mconcat (tss `mappend` xss), unwords uss)) . splitAt 1 . words $ zs+ | otherwise -> splitWords ysss (tss `mappend` [ws]) us +concatWordsFromLeftToRight :: ConcatenationsArr -> String -> [String]+concatWordsFromLeftToRight ysss zs = let (ws,us) = splitWords ysss [] zs in+ if null us then [ws] else ws : concatWordsFromLeftToRight ysss us++-----------------------------------------------------++append2prependConv :: Concatenations -> Concatenations+append2prependConv = map (map (unwords . reverse . words))+{-# INLINE append2prependConv #-}++left2right :: [String] -> String+left2right = unwords . reverse . map reverse+{-# INLINE left2right #-}++-----------------------------------------------------+ -- | A generalized variant of the 'prepareText' with the arbitrary maximum number of the words in the lines given as the first argument. prepareTextN :: Int -- ^ A maximum number of the words or their concatenations in the resulting list of 'String's. -> [[String]] -- ^ Is intended to become a valid 'Concatenations'.+ -> [[String]] -- ^ Is intended to become a valid 'Concatenations'. -> String -- ^ A sorted 'String' of possible characters in the phonetic language representation. -> String -> [String]-prepareTextN n ysss xs = filter (any (isPLL xs)) . splitLinesN n . map (unwords . complexNWords ysss . words) .- filter (not . null) . lines+prepareTextN n ysss zsss xs = filter (any (isPLL xs)) . splitLinesN n . map (left2right .+ concatWordsFromLeftToRight (defaultConversion . sort2Concat . append2prependConv $ zsss) . left2right .+ concatWordsFromLeftToRight (defaultConversion . sort2Concat $ ysss)) . filter (not . null) . lines -- | A predicate to check whether the given character is one of the \"\' \\x2019\\x02BC-\". isSpC :: Char -> Bool@@ -176,10 +186,11 @@ :: Int -- ^ A maximum number of the words or their concatenations in the resulting list of 'String's. -> Int -- ^ A number of words in every 'String' that the function firstly forms. To have some sense of usage, must be less than the first argument. -> [[String]] -- ^ Is intended to become a valid 'Concatenations'.+ -> [[String]] -- ^ Is intended to become a valid 'Concatenations'. -> String -- ^ A sorted 'String' of possible characters in the phonetic language representation. -> String -> [String]-prepareGrowTextMN m n ysss xs = growLinesN m . prepareTextN n ysss xs+prepareGrowTextMN m n ysss zsss xs = growLinesN m . prepareTextN n ysss zsss xs {-# INLINE prepareGrowTextMN #-} -------------------------------------@@ -205,8 +216,9 @@ :: Int -- ^ A maximum number of the words or their concatenations in the resulting list of 'String's. -> Int -- ^ A number of words in every 'String' that the function firstly forms. To have some sense of usage, must be less than the first argument. -> [[String]] -- ^ Is intended to become a valid 'Concatenations'.+ -> [[String]] -- ^ Is intended to become a valid 'Concatenations'. -> String -- ^ A sorted 'String' of possible characters in the phonetic language representation. -> String -> [String]-prepareTuneTextMN m n ysss xs = tuneLinesN m . prepareTextN n ysss xs+prepareTuneTextMN m n ysss zsss xs = tuneLinesN m . prepareTextN n ysss zsss xs {-# INLINE prepareTuneTextMN #-}
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2021 Oleksandr Zhabenko+Copyright (c) 2021-2022 Oleksandr Zhabenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
README.md view
@@ -1,3 +1,8 @@+The version 0.9.0.0 fixed the long existing issues with not working prepending needed concatenations for the text in the+module Data.Phonetic.Languages.PrepareText. Added also the possibility to not only prepend needed words, but also append.+This introduces breaking changes, so please, wait for update for all the dependent packages before starting the upgrade, also+check the code that uses library functions afterwards.+ The version 0.7.0.0 introduces breaking changes, so the related code must be revised and probably rewritten. The changes are related with the introducing the possibilities to represent also appearance of the sounds in the written text being pronounced and the introduction more general concept of phonemes that creates@@ -15,7 +20,7 @@ * Some examples. -Let in the file words.txt you have the (phonetic language) words and their durations in seconds as pairs separated with whitespace +Let in the file words.txt you have the (phonetic language) words and their durations in seconds as pairs separated with whitespace at the lines. Also let in the file controlData.txt you have control specifications, an example of syntaxis for which is in the file@@ -24,26 +29,26 @@ Also let in the file gwrsys.txt you have GWritingSystemPRPLX specifications, an example of syntaxis for which is in the file gwrsysExample.txt. -Then the following commands can be variants of the usage of the pldPL executable. +Then the following commands can be variants of the usage of the pldPL executable. -1) pldPL 0.001 0.001 0.01 0.02 words.txt controlData.txt gwrsys.txt 0.3 0.2 0.02 0.06 1.8 -1 0.01 0.01 1.5 1.5 1.5 1.5 1.5 1.5 | R --quiet --no-save +1) pldPL 0.001 0.001 0.01 0.02 words.txt controlData.txt gwrsys.txt 0.3 0.2 0.02 0.06 1.8 -1 0.01 0.01 1.5 1.5 1.5 1.5 1.5 1.5 | R --quiet --no-save This variant tries to minimize the duration of the only one element belonging to the special phonetic language representation-elements (-1 as the second parameter after the file name), tries -to reduce the influence of the two other elements (the third and the fourth parameters as 0.01) and tries to somewhat +elements (-1 as the second parameter after the file name), tries+to reduce the influence of the two other elements (the third and the fourth parameters as 0.01) and tries to somewhat make longer the 6 vowels (all the consonants have by that the default coefficients equal to 1.0) (a simple example, though the program supports also the more complicated ones). -2) pldPL 0.001 0.001 0.01 0.02 words.txt controlData.txt gwrsys.txt 0.3 0.2 0.02 0.06 1.8 -1 0.01 0.01 2.5 2.5 2.5 2.5 2.5 2.5 | R --quiet --no-save +2) pldPL 0.001 0.001 0.01 0.02 words.txt controlData.txt gwrsys.txt 0.3 0.2 0.02 0.06 1.8 -1 0.01 0.01 2.5 2.5 2.5 2.5 2.5 2.5 | R --quiet --no-save The same as the 1), but with more prolongation of the vowels. -3) pldPL 0.001 0.001 0.01 0.02 words.txt controlData.txt gwrsys.txt 0.3 0.2 0.02 0.06 1.4 -1 0.01 0.01 2.5 2.5 2.5 2.5 2.5 2.5 | R --quiet --no-save +3) pldPL 0.001 0.001 0.01 0.02 words.txt controlData.txt gwrsys.txt 0.3 0.2 0.02 0.06 1.4 -1 0.01 0.01 2.5 2.5 2.5 2.5 2.5 2.5 | R --quiet --no-save If the 2) gives you the not NULL result, then it is recommended to minimize the first parameter after the next 4 parameters-after the gwrsys.txt. +after the gwrsys.txt. -4) pldPL 0.001 0.001 0.01 0.02 words.txt controlData.txt gwrsys.txt 0.3 0.2 0.02 0.06 1.6 -1 0.01 0.01 2.5 2.5 2.5 2.5 2.5 2.5 | R --quiet --no-save +4) pldPL 0.001 0.001 0.01 0.02 words.txt controlData.txt gwrsys.txt 0.3 0.2 0.02 0.06 1.6 -1 0.01 0.01 2.5 2.5 2.5 2.5 2.5 2.5 | R --quiet --no-save If the previous gives NULL result, then try to somewhat increase the first parameter after the next 4 parameters after the gwrsys.txt.
phonetic-languages-phonetics-basics.cabal view
@@ -3,7 +3,7 @@ -- http://haskell.org/cabal/users-guide/ name: phonetic-languages-phonetics-basics-version: 0.8.4.0+version: 0.9.0.0 synopsis: A library for working with generalized phonetic languages usage. description: There already exists a Ukrainian implementation for the phonetic languages approach published at: https://hackage.haskell.org/package/phonetic-languages-simplified-examples-array. It is optimized for the Ukrainian only and needs to be rewritten for every new language mostly from scratch using it as a template. To avoid this boilerplate, this one is provided. It can be used for different languages and even for music or other fields. Now it combines the functionality of the @r-glpk-phonetic-languages-ukrainian-durations@ and @phonetic-languages-ukrainian-array@ and some dependencies of the mentioned one. homepage: https://hackage.haskell.org/package/phonetic-languages-phonetics-basics@@ -20,9 +20,9 @@ library exposed-modules: Data.Phonetic.Languages.Base, Data.Phonetic.Languages.Syllables, Numeric.Wrapper.R.GLPK.Phonetic.Languages.Durations, Data.Phonetic.Languages.SpecificationsRead, Data.Phonetic.Languages.PrepareText other-modules: Main- other-extensions: CPP, BangPatterns, UnboxedTuples, MagicHash, MultiParamTypeClasses, FlexibleInstances+ other-extensions: CPP, BangPatterns, UnboxedTuples, MagicHash, MultiParamTypeClasses, FlexibleInstances, MultiWayIf ghc-options: -funbox-strict-fields -fobject-code- build-depends: base >=4.8 && <4.15, mmsyn2-array >=0.1.3 && <1, mmsyn3 >= 0.1.5 && <1, mmsyn5 >=0.5 && <1, lists-flines >=0.1.1 && <1, foldable-ix >=0.2 && <1+ build-depends: base >=4.8 && <5, mmsyn2-array >=0.1.3 && <1, mmsyn3 >= 0.1.5 && <1, mmsyn5 >=0.5 && <1, lists-flines >=0.1.1 && <1, foldable-ix >=0.2 && <1 -- hs-source-dirs: default-language: Haskell2010 @@ -30,6 +30,6 @@ main-is: Main.hs other-modules: Data.Phonetic.Languages.Base, Data.Phonetic.Languages.Syllables, Numeric.Wrapper.R.GLPK.Phonetic.Languages.Durations, Data.Phonetic.Languages.SpecificationsRead, Data.Phonetic.Languages.PrepareText -- other-extensions:- build-depends: base >=4.8 && <4.15, mmsyn2-array >=0.1.1 && <1, mmsyn3 >= 0.1.5 && <1, mmsyn5 >=0.5 && <1, lists-flines >=0.1.1 && <1, foldable-ix >=0.1 && <1+ build-depends: base >=4.8 && <5, mmsyn2-array >=0.1.1 && <1, mmsyn3 >= 0.1.5 && <1, mmsyn5 >=0.5 && <1, lists-flines >=0.1.1 && <1, foldable-ix >=0.1 && <1 -- hs-source-dirs: default-language: Haskell2010