packages feed

phonetic-languages-phonetics-basics 0.4.0.0 → 0.5.0.0

raw patch · 5 files changed

+140/−9 lines, 5 filesdep ~foldable-ixdep ~mmsyn2-arraynew-component:exe:pldPL

Dependency ranges changed: foldable-ix, mmsyn2-array

Files

ChangeLog.md view
@@ -47,3 +47,8 @@ * Fourth version. Added a new module Numeric.Wrapper.R.GLPK.Phonetic.Languages.Durations to find out the approximations of the phonetic languages representation element durations. For this added two new lightweight dependencies of lists-flines and foldable-ix. ++## 0.5.0.0 -- 2021-04-29++* Fifth version. Added two new modules Data.Phonetic.Languages.SpecificationsRead and Main. Added an executable pldPL (anologue+of the pldUkr from r-glpk-phonetic-languages-ukrainian-durations package). 
+ Data/Phonetic/Languages/SpecificationsRead.hs view
@@ -0,0 +1,34 @@+-- |+-- Module      :  Data.Phonetic.Languages.SpecificationsRead+-- Copyright   :  (c) OleksandrZhabenko 2021+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+{-| Provides functions to read data specifications for other modules from textual files.+-}++module Data.Phonetic.Languages.SpecificationsRead where++import Data.Char (isAlpha)+import Numeric.Wrapper.R.GLPK.Phonetic.Languages.Durations+import System.Environment (getArgs)+import GHC.Arr+import Text.Read+import Data.List+import Data.Maybe (fromMaybe,fromJust)+import GHC.Int+import Data.Phonetic.Languages.Base++charLine :: Char -> String -> Bool+charLine c = (== [c]) . take 1++groupBetweenChars :: Char -> [String] -> [[String]]+groupBetweenChars c [] = []+groupBetweenChars c xs = css : groupBetweenChars c (dropWhile (charLine c) dss)+  where (css,dss) = span (charLine c) xs++getGWritingSystem :: Char -> String -> GWritingSystemPRPLX+getGWritingSystem c xs = map ((\(t1,t2) -> (map (\kt -> fromJust (readPEMaybe kt::Maybe PhoneticsRepresentationPLX)) t2,+         read (concat t1)::Int8)) . splitAt 1) . groupBetweenChars c . lines $ xs+
+ Main.hs view
@@ -0,0 +1,82 @@+-- |+-- Module      :  Main+-- Copyright   :  (c) OleksandrZhabenko 2020-2021+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+{-| Can be used to calculate the durations of the approximations of the phonemes+using some prepared text with its correct (at least mostly) pronunciation.+The prepared text is located in the same directory and contains lines -the+phonetic language word and its duration in seconds separated with whitespace.+The library is intended to use the functionality of the :++1) R programming language https://www.r-project.org/++2) Rglpk library https://cran.r-project.org/web/packages/Rglpk/index.html++3) GNU GLPK library https://www.gnu.org/software/glpk/glpk.html++For more information, please, see the documentation for them.++For the model correctness the js here refers to sorted list of the 'Char' representations of the phonetic language phenomenae.++The length of the 'String' js is refered to as 'lng'::'Int'. The number of 'pairs'' function elements in the lists is refered to+as 'nn'::'Int'. The number of constraints is refered here as 'nc'::'Int'. @nc == nn `quot` 2@.++Is generalized from the Numeric.Wrapper.R.GLPK.Phonetics.Ukrainian.Durations module from+the @r-glpk-phonetic-languages-ukrainian-durations@ package.+-}++module Main where++import Data.Char (isAlpha)+import Numeric.Wrapper.R.GLPK.Phonetic.Languages.Durations+import System.Environment (getArgs)+import GHC.Arr+import Text.Read+import Data.List+import GHC.Int +import Data.Maybe (fromMaybe,fromJust)+import Data.Phonetic.Languages.Base+import Data.Phonetic.Languages.SpecificationsRead++main :: IO ()+main = do+ args <- getArgs+ let min1 = - abs (fromMaybe (-0.003) (readMaybe (concat . take 1 $ args)::Maybe Double))+     max1 = abs (fromMaybe 0.003 (readMaybe (concat . drop 1. take 2 $ args)::Maybe Double))+     min2 = - abs (fromMaybe (-0.0012) (readMaybe (concat . drop 2 . take 3 $ args)::Maybe Double))+     max2 = abs (fromMaybe 0.0012 (readMaybe (concat . drop 3 . take 4 $ args)::Maybe Double))+     arGs = dropWhile (all (not . isAlpha)) args+ processMentG arGs min1 max1 min2 max2++processMentG :: [String] -> Double -> Double -> Double -> Double -> IO ()+processMentG ts min1 max1 min2 max2 = do+  let file = concat . take 1 $ ts+      controlFile = concat . drop 1 . take 2 $ ts+      gwritingsysFile = concat . drop 2 . take 3 $ ts+  contents <- readFile file+  controlConts <- readFile controlFile+  gwrsCnts <- readFile gwritingsysFile+  let [pwHeader, objCfs, xs1sps1s] = groupBetweenChars '~' . lines $ controlConts+      gwrs = getGWritingSystem '~' gwrsCnts+      nn = fromMaybe 1 (readMaybe (concat . take 1 $ pwHeader)::Maybe Int)+      pw = LL (map (\zzs -> read zzs::PairwisePL) . drop 1 $ pwHeader) nn+      gs = fromMaybe [] (readMaybe (concat objCfs)::Maybe [(Int,Int)])+      xs1 = fromMaybe [] (readMaybe (concat . take 1 $ xs1sps1s)::Maybe [Int])+      sps1 = fromMaybe [] (readMaybe (concat . drop 1 . take 2 $ xs1sps1s)::Maybe [Int])+      [mx,mn1,mnSpecial,mnG] = map (\s -> fromJust (readMaybe s::Maybe Double)) . drop 3 . take 7 $ ts+      coeff = fromMaybe (sqrt 2.0) ((readMaybe (concat . drop 7 . take 8 $ ts))::Maybe Double)+      lst0 = createCoeffsObj lng (drop 7 ts)+      ll = length lst0 - 1+      lstCfs = listArray (0,ll) lst0+      xss = map words . lines $ contents+      words2 = map head xss+      lengths0 = map ((\rs -> read rs::Double) . last) xss+      bss = map (sort . map char . stringToXG gwrs) words2+      js = tail . nub . sort . unwords $ bss+      lng = length js+  putStrLn . answer2 lng nn pw mx gs min1 max1 min2 max2 mn1 mnSpecial mnG xs1 sps1 {- <---  new coeffs-} lstCfs bss (map (*coeff) lengths0) (map (* (1.0 / coeff)) lengths0) $ js+              +-- Example of usage: 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
Numeric/Wrapper/R/GLPK/Phonetic/Languages/Durations.hs view
@@ -77,7 +77,7 @@ pairwiseComparings :: Char -> PairwiseC -> [Int] -> [Int] pairwiseComparings x y zs = zs `mappend` pairs' y x -{-| A way to encode the pairs of the phonetic language representations that give some additional associations, connetctions+{-| A way to encode the pairs of the phonetic language representations that give some additional associations, connections between elements, usually being caused by some similarity or commonality of the pronunciation act for the phenomenae corresponding to these elements.  All ['Int'] must be equal in 'length' throughout the same namespace and this length is given as 'Int' argument in@@ -257,13 +257,13 @@   -> Double -- ^ Maximum duration of the phonetic language element representation in seconds.   -> [(Int, Int)] -- ^ List of pairs of indices that shows how the input data is related to the representation   -- (which coefficients relates to which representation elements).-  -> Double -- ^ A minimum  (usually, a negative one) possible random deviation from the computed value to be additionally applied to emulate+  -> Double -- ^ A maximum in absolute value (being, usually, a negative one) possible random deviation from the computed value to be additionally applied to emulate   -- 'more natural' behaviour and to get every time while running new sets of values. -  -> Double -- ^ A minimum (usually, a positive one) possible random deviation from the computed value to be additionally applied to emulate+  -> Double -- ^ A maximum in absolute value (being, usually, a positive one) possible random deviation from the computed value to be additionally applied to emulate   -- 'more natural' behaviour and to get every time while running new sets of values. -  -> Double -- ^ A maximum in absolute value (usually, a negative one) possible random deviation from the computed value to be+  -> Double -- ^ A minimum in absolute value (being, usually, a negative one) possible random deviation from the computed value to be   -- additionally applied to emulate 'more natural' behaviour and to get every time while running new sets of values. -  -> Double -- ^ A maximum in absolute value (usually, a positive one) possible random deviation from the computed value to be+  -> Double -- ^ A minimum in absolute value (being, usually, a positive one) possible random deviation from the computed value to be   -- additionally applied to emulate 'more natural' behaviour and to get every time while running new sets of values.    -> Double -- ^ A minimum positive duration value for some group of phonetic language representation (usually, some sorts of   -- phonemes, e. g. vowels) to set some peculiar behaviour for the set of resulting values.@@ -288,3 +288,5 @@    "if (k$status == 0){k$solution / mean(k$solution)} else {c()}", newLineEnding, "\")}"]  -- read ("SylS {charS=\'k\', phoneType=P 6")::PRS++-- pldUkr 0.01 0.01 0.1 0.2 words.txt 1.8 -1 0.01 0.01 2.5 2.5 2.5 2.5 2.5 2.5
phonetic-languages-phonetics-basics.cabal view
@@ -3,9 +3,9 @@ -- http://haskell.org/cabal/users-guide/  name:                phonetic-languages-phonetics-basics-version:             0.4.0.0+version:             0.5.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. +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  some dependencies of the mentioned one. homepage:            https://hackage.haskell.org/package/phonetic-languages-phonetics-basics license:             MIT license-file:        LICENSE@@ -18,10 +18,18 @@ cabal-version:       >=1.10  library-  exposed-modules:     Data.Phonetic.Languages.Undefined, Data.Phonetic.Languages.Base, Data.Phonetic.Languages.Syllables, Numeric.Wrapper.R.GLPK.Phonetic.Languages.Durations-  -- other-modules:+  exposed-modules:     Data.Phonetic.Languages.Undefined, Data.Phonetic.Languages.Base, Data.Phonetic.Languages.Syllables, Numeric.Wrapper.R.GLPK.Phonetic.Languages.Durations, Data.Phonetic.Languages.SpecificationsRead+  other-modules:       Main   other-extensions:    CPP, BangPatterns, UnboxedTuples, MagicHash, MultiParamTypeClasses, FlexibleInstances   ghc-options:         -funbox-strict-fields -fobject-code   build-depends:       base >=4.8 && <4.15, mmsyn2-array >=0.1.3 && <1, mmsyn5 >=0.5 && <1, lists-flines >=0.1.1 && <1, foldable-ix >=0.2 && <1+  -- hs-source-dirs:+  default-language:    Haskell2010++executable pldPL+  main-is:             Main.hs+  other-modules:       Data.Phonetic.Languages.Undefined, Data.Phonetic.Languages.Base, Data.Phonetic.Languages.Syllables, Numeric.Wrapper.R.GLPK.Phonetic.Languages.Durations, Data.Phonetic.Languages.SpecificationsRead+  -- other-extensions:+  build-depends:       base >=4.8 && <4.15, mmsyn2-array >=0.1.1 && <1, mmsyn5 >=0.5 && <1, lists-flines >=0.1.1 && <1, foldable-ix >=0.1 && <1   -- hs-source-dirs:   default-language:    Haskell2010