packages feed

phonetic-languages-phonetics-basics 0.5.1.0 → 0.6.0.0

raw patch · 5 files changed

+119/−5 lines, 5 files

Files

ChangeLog.md view
@@ -57,3 +57,9 @@  * Fifth version revised A. Added two example files with data syntaxis, first of all useful for the pldPL executable. See README.md. Added also README.md file with a brief description of the possible scenario of the usage for pldPL. Some code improvements. ++## 0.6.0.0 -- 2021-05-03++* Sixth version. Added a module Data.Phonetic.Languages.PrepareText. Added a file EnglishConcatenated.txt that contains additional+list of the English words the corresponding translations of which are intended to be concatenated to the next phonetic language+words to preserve the basic grammar. Some code and documentation improvements. 
+ Data/Phonetic/Languages/PrepareText.hs view
@@ -0,0 +1,103 @@+-- |+-- Module      :  Data.Phonetic.Languages.PrepareText+-- Copyright   :  (c) OleksandrZhabenko 2020-2021+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- Helps to order the 7 or less phonetic language words (or their concatenations)+-- to obtain (to some extent) suitable for poetry or music text.+-- Earlier it has been a module DobutokO.Poetry.Ukrainian.PrepareText+-- from the @dobutokO-poetry@ package.+-- In particular, this module can be used to prepare the phonetic language text+-- by applying the most needed grammar to avoid misunderstanding+-- for the produced text. The attention is paid to the prepositions, pronouns, conjunctions+-- and particles that are most commonly connected (or not) in a significant way+-- with the next text.+-- Uses the information from:+-- https://uk.wikipedia.org/wiki/%D0%A1%D0%BF%D0%BE%D0%BB%D1%83%D1%87%D0%BD%D0%B8%D0%BA+-- and+-- https://uk.wikipedia.org/wiki/%D0%A7%D0%B0%D1%81%D1%82%D0%BA%D0%B0_(%D0%BC%D0%BE%D0%B2%D0%BE%D0%B7%D0%BD%D0%B0%D0%B2%D1%81%D1%82%D0%B2%D0%BE)+--+-- Uses arrays instead of vectors.+-- A list of basic (but, probably not complete and needed to be extended as needed) English words (the articles, pronouns,+-- particles, conjunctions etc.) the corresponding phonetic language translations of which are intended to be used as a+-- 'Concatenations' here is written to the file EnglishConcatenated.txt in the source tarball.++module Data.Phonetic.Languages.PrepareText (+  Concatenations+  -- * Basic functions+  , prepareText+  , prepareTextN+  , complexWords+  , splitLines+  , splitLinesN+  , isSpC+  -- * Used to transform after convertToProperphonetic language from mmsyn6ukr package+  , isPLL+) where++import CaseBi.Arr (getBFstL')+import Data.List.InnToOut.Basic (mapI)+import Data.Char (isAlpha,toLower)+import GHC.Arr++{-| 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+lists themselves) sorted in the ascending order for the data type to work correctly in the functions of the module.+-}+type Concatenations = [[String]]++-- | 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+-- words that \"should\" be paired and not dealt with separately+-- to avoid the misinterpretation and preserve maximum of the semantics for the+-- \"phonetic\" language on the phonetic language basis.+prepareText :: Concatenations -> String -> String -> [String]+prepareText ysss xs = filter (any (isPLL xs)) . splitLines . map (unwords . complexWords ysss ysss . words .+  filter (\t -> isAlpha t || isSpC t)) . filter (not . null) . lines++-- | 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@(yss:tsss) zss@(ts:xss)+ | null yss = complexWords rsss tsss zss+ | otherwise =+    let y = length . words . head $ yss+        uwxs = unwords . take y $ zss in getBFstL' (complexWords rsss tsss zss) (map (\ys ->+           (ys,complexWords rsss tsss ((filter (/= ' ') ys ++ ts):xss))) yss) uwxs+complexWords rsss [] zss@(xs:xss) = xs:complexWords rsss rsss xss+complexWords _ _ [] = []++-- | A generalized variant of the 'prepareText' with the arbitrary maximum number of the words in the lines given as the first argument.+prepareTextN :: Int -> Concatenations -> String -> String -> [String]+prepareTextN n ysss xs = filter (any (isPLL xs)) . splitLinesN n . map (unwords . complexWords ysss ysss . words .+  filter (\t -> isAlpha t || isSpC t)) . filter (not . null) . lines++isSpC :: Char -> Bool+isSpC x = x == '\'' || x == ' ' || x == '\x2019' || x == '\x02BC' || x == '-'+{-# INLINE isSpC #-}++-- | The first argument must be a 'String' of sorted 'Char's in the ascending order of all possible symbols that can be+-- used for the text in the phonetic language selected. Can be prepared beforehand, or read from the file. +isPLL :: String -> Char -> Bool+isPLL xs y = getBFstL' False (zip xs . replicate 10000 $ True) y++-- | The function is recursive and is applied so that all returned elements ('String') are no longer than 7 words in them.+splitLines :: [String] -> [String]+splitLines xss+ | null xss = []+ | otherwise = mapI (\xs -> compare (length . words $ xs) 7 == GT) (\xs -> let yss = words xs in+     splitLines . map unwords . (\(q,r) -> [q,r]) . splitAt (length yss `quot` 2) $ yss) $ xss++-- | A generalized variant of the 'splitLines' with the arbitrary maximum number of the words in the lines given as the first argument.+splitLinesN :: Int -> [String] -> [String]+splitLinesN n xss+ | null xss || n <= 0 = []+ | otherwise = mapI (\xs -> compare (length . words $ xs) n == GT) (\xs -> let yss = words xs in+     splitLines . map unwords . (\(q,r) -> [q,r]) . splitAt (length yss `quot` 2) $ yss) $ xss+
+ EnglishConcatenated.txt view
@@ -0,0 +1,1 @@+["A","About","Actually","After","After all","Against","Allegedly","Almost","Already","Among","Around","As","As far as","As if","As though","At","Barely","Before","Behind","Below","Beneath","Between","But","By","Even","Exactly","Except","Exclusively","For","From","However","I.e.","If","In","In addition","In order to","Just","Let","Likewise","Near","Of","On","Only","Or","Over","Round","Still","Than","That is","The","Therefore","Though","Through","To","Under","Unless","When","With","Without","a","about","after","against","allegedly","almost","already","among","around","as","as far as","as if","as the","as though","at","barely","because","because of","because of that","before","behind","below","beneath","between","but","by","despite that","even","even though","exactly","except","exclusively","for","from","however","i.e.","if","in","in order to","inhibit","instead of","just","let","like","moreover","near","of","on","only","or","over","round","since the","so","so as","so that","still","than","that is","the","therefore","though","through","to","under","unless","whatever","whereas","while as","with","without"]
README.md view
@@ -50,3 +50,7 @@ r-glpk-phonetic-languages-ukrainian-durations package. For more information, please, refer to: https://hackage.haskell.org/package/r-glpk-phonetic-languages-ukrainian-durations +----------------------------------------------------------++In the file EnglishConnected.txt in the source tarball there are English words the translations of which are intended to be+concatenated to the next word in the phonetic language before applying sound processing so that the basic grammar is preserved.
phonetic-languages-phonetics-basics.cabal view
@@ -3,9 +3,9 @@ -- http://haskell.org/cabal/users-guide/  name:                phonetic-languages-phonetics-basics-version:             0.5.1.0+version:             0.6.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  some dependencies of the mentioned one.+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 license:             MIT license-file:        LICENSE@@ -14,11 +14,11 @@ copyright:           Oleksandr Zhabenko category:            Language, Math, Game build-type:          Simple-extra-source-files:  ChangeLog.md, README.md, controlDataExample.txt, gwrsysExample.txt+extra-source-files:  ChangeLog.md, README.md, controlDataExample.txt, gwrsysExample.txt, EnglishConcatenated.txt 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, Data.Phonetic.Languages.SpecificationsRead+  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, Data.Phonetic.Languages.PrepareText   other-modules:       Main   other-extensions:    CPP, BangPatterns, UnboxedTuples, MagicHash, MultiParamTypeClasses, FlexibleInstances   ghc-options:         -funbox-strict-fields -fobject-code@@ -28,7 +28,7 @@  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-modules:       Data.Phonetic.Languages.Undefined, 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, mmsyn5 >=0.5 && <1, lists-flines >=0.1.1 && <1, foldable-ix >=0.1 && <1   -- hs-source-dirs: