phonetic-languages-phonetics-basics 0.3.0.0 → 0.3.1.0
raw patch · 3 files changed
+92/−26 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Phonetic.Languages.Syllables: SP1 :: SegmentationInfo1 -> [SegmentationPredFunction] -> [([PRS] -> [PRS], [PRS] -> [PRS])] -> SegmentationRules1
- Data.Phonetic.Languages.Syllables: [pF] :: SegmentationRules1 -> [SegmentationPredFunction]
- Data.Phonetic.Languages.Syllables: [res] :: SegmentationRules1 -> [([PRS] -> [PRS], [PRS] -> [PRS])]
- Data.Phonetic.Languages.Syllables: isVwl :: Char -> Bool
- Data.Phonetic.Languages.Syllables: type SegmentPredicates = [SegmentationRules1]
+ Data.Phonetic.Languages.Syllables: LFS :: SegmentationPredFunction -> DListFunctionResult -> SegmentationLineFunction
+ Data.Phonetic.Languages.Syllables: SR1 :: SegmentationInfo1 -> [SegmentationLineFunction] -> SegmentationRules1
+ Data.Phonetic.Languages.Syllables: [lineFs] :: SegmentationRules1 -> [SegmentationLineFunction]
+ Data.Phonetic.Languages.Syllables: [predF] :: SegmentationLineFunction -> SegmentationPredFunction
+ Data.Phonetic.Languages.Syllables: [resF] :: SegmentationLineFunction -> DListFunctionResult
+ Data.Phonetic.Languages.Syllables: data SegmentationLineFunction
+ Data.Phonetic.Languages.Syllables: findC :: Char -> Array Int PRS -> Maybe PRS
+ Data.Phonetic.Languages.Syllables: gBF4 :: Ix i => (# Int#, PRS #) -> (# Int#, PRS #) -> Char -> Array i PRS -> Maybe PRS
+ Data.Phonetic.Languages.Syllables: type DListFunctionResult = ([PRS] -> [PRS], [PRS] -> [PRS])
+ Data.Phonetic.Languages.Syllables: type SegmentRulesG = [SegmentationRules1]
- Data.Phonetic.Languages.Syllables: createSyllablesPL :: GWritingSystemPRPLX -> [(Char, Char)] -> CharPhoneticClassification -> SegmentPredicates -> String -> String -> String -> [[[PRS]]]
+ Data.Phonetic.Languages.Syllables: createSyllablesPL :: GWritingSystemPRPLX -> [(Char, Char)] -> CharPhoneticClassification -> SegmentRulesG -> String -> String -> String -> [[[PRS]]]
- Data.Phonetic.Languages.Syllables: divCnsnts :: [(Char, Char)] -> SegmentPredicates -> [PRS] -> ([PRS] -> [PRS], [PRS] -> [PRS])
+ Data.Phonetic.Languages.Syllables: divCnsnts :: [(Char, Char)] -> SegmentRulesG -> [PRS] -> DListFunctionResult
- Data.Phonetic.Languages.Syllables: reSyllableCntnts :: [(Char, Char)] -> SegmentPredicates -> [[PRS]] -> [[PRS]]
+ Data.Phonetic.Languages.Syllables: reSyllableCntnts :: [(Char, Char)] -> SegmentRulesG -> [[PRS]] -> [[PRS]]
- Data.Phonetic.Languages.Syllables: type CharPhoneticClassification = [PRS]
+ Data.Phonetic.Languages.Syllables: type CharPhoneticClassification = Array Int PRS
Files
- ChangeLog.md +5/−0
- Data/Phonetic/Languages/Syllables.hs +85/−24
- phonetic-languages-phonetics-basics.cabal +2/−2
ChangeLog.md view
@@ -21,3 +21,8 @@ * Third version. Added a new module Data.Phonetic.Languages.Syllables for the general syllable segmentation. Added new lightweight dependencies of mmsyn5 and mmsyn2-array.++## 0.3.1.0 -- 2021-04-21++* Third version revised A. Changed some data types and type synonyms in the module Data.Phonetic.Languages.Syllables.+Some code optimizations in it. Some documentation improvements. Added new auxiliary functions to the module.
Data/Phonetic/Languages/Syllables.hs view
@@ -1,10 +1,12 @@ {-# OPTIONS_HADDOCK show-extensions #-}-{-# OPTIONS_GHC -funbox-strict-fields #-}+{-# OPTIONS_GHC -funbox-strict-fields -fobject-code #-} {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE UnboxedTuples #-}+{-# LANGUAGE MagicHash #-} -- | -- Module : Data.Phonetic.Languages.Syllables--- Copyright : (c) OleksandrZhabenko 2020-2021+-- Copyright : (c) OleksandrZhabenko 2021 -- License : MIT -- Stability : Experimental -- Maintainer : olexandr543@yahoo.com@@ -13,14 +15,44 @@ -- 'Languages.Phonetic.Ukrainian.Syllable.Arr' from @ukrainian-phonetics-basic-array@ package. -- -module Data.Phonetic.Languages.Syllables where+module Data.Phonetic.Languages.Syllables (+ -- * Data types and type synonyms+ PRS(..)+ , PhoneticType(..)+ , CharPhoneticClassification+ , StringRepresentation+ , SegmentationInfo1(..)+ , SegmentationPredFunction(..)+ , DListFunctionResult+ , SegmentationLineFunction(..)+ , SegmentationRules1(..)+ , SegmentRulesG+ -- * Basic functions+ , str2PRSs+ , sndGroups+ , groupSnds+ , divCnsnts+ , reSyllableCntnts+ , divVwls+ , createSyllablesPL+ -- * Auxiliary functions+ , gBF4+ , findC+ , isVowel1+ , isSonorous1+ , isVoicedC1+ , isVoicelessC1+ , isNotVowel2+ , notEqC+) where import Prelude hiding (mappend) import Data.Monoid-import Data.Typeable-import qualified Data.List as L (groupBy,find,findIndex)+import qualified Data.List as L (groupBy,find) import Data.Phonetic.Languages.Base import CaseBi.Arr+import GHC.Arr+import GHC.Exts import Data.List.InnToOut.Basic (mapI) import Data.Maybe (mapMaybe,fromJust) import GHC.Int@@ -32,7 +64,7 @@ data PRS = SylS { charS :: !Char, -- ^ Phonetic languages phenomenon representation. Usually, a phoneme, but it can be otherwise something different. phoneType :: !PhoneticType -- ^ Some encoded type.-} deriving ( Eq, Typeable )+} deriving ( Eq ) instance Ord PRS where compare (SylS x1 y1) (SylS x2 y2) =@@ -42,28 +74,52 @@ data PhoneticType = P !Int8 deriving (Eq, Ord) -{-| The list must be sorted in the ascending order to be used in the module correctly.+{-| The 'Array' 'Int' must be sorted in the ascending order to be used in the module correctly. -}-type CharPhoneticClassification = [PRS]+type CharPhoneticClassification = Array Int PRS {-| The 'String' of converted phonetic language representation 'Char' data is converted to this type to apply syllable segmentation or other transformations. -} type StringRepresentation = [PRS] +-- | Is somewhat rewritten from the 'CaseBi.Arr.gBF3' function (not exported) from the @mmsyn2-array@ package.+gBF4+ :: (Ix i) => (# Int#, PRS #)+ -> (# Int#, PRS #)+ -> Char+ -> Array i PRS+ -> Maybe PRS+gBF4 (# !i#, k #) (# !j#, m #) c arr+ | isTrue# ((j# -# i#) ># 1# ) = + case compare c (charS p) of+ GT -> gBF4 (# n#, p #) (# j#, m #) c arr+ LT -> gBF4 (# i#, k #) (# n#, p #) c arr+ _ -> Just p+ | c == charS m = Just m+ | c == charS k = Just k+ | otherwise = Nothing+ where !n# = (i# +# j#) `quotInt#` 2#+ !p = unsafeAt arr (I# n#)+{-# INLINABLE gBF4 #-}++findC+ :: Char+ -> Array Int PRS+ -> Maybe PRS+findC c arr = gBF4 (# i#, k #) (# j#, m #) c arr + where !(I# i#,I# j#) = bounds arr+ !k = unsafeAt arr (I# i#)+ !m = unsafeAt arr (I# i#)+ str2PRSs :: CharPhoneticClassification -> String -> StringRepresentation-str2PRSs zs = map (\c -> fromJust . L.find ((== c) . charS) $ zs)+str2PRSs arr = map (\c -> fromJust . findC c $ arr) -- | Function-predicate 'isVowel1' checks whether its argument is a vowel representation in the 'PRS' format. isVowel1 :: PRS -> Bool isVowel1 = (== P 0) . phoneType {-# INLINE isVowel1 #-} --- | Function-predicate 'isVwl' checks whether its argument is a vowel representation in the 'Char' format.-isVwl :: Char -> Bool-isVwl = getBFstLSorted' False [('a',True),('e',True),('i',True),('o',True),('u',True),('y',True)]-{-# INLINE isVwl #-}- -- | Function-predicate 'isSonorous1' checks whether its argument is a sonorous consonant representation in the 'PRS' format. isSonorous1 :: PRS -> Bool isSonorous1 = (`elem` [P 1,P 2]) . phoneType@@ -114,31 +170,36 @@ data SegmentationPredFunction = PF (SegmentationInfo1 -> [PRS] -> Bool) -data SegmentationRules1 = SP1 {+type DListFunctionResult = ([PRS] -> [PRS],[PRS] -> [PRS])++data SegmentationLineFunction = LFS {+ predF :: SegmentationPredFunction, -- ^ The predicate to check the needed rule for segmentation.+ resF :: DListFunctionResult -- ^ The result if the 'predF' returns 'True' for its arguments.+}++data SegmentationRules1 = SR1 { infoS :: SegmentationInfo1, - pF :: [SegmentationPredFunction], -- ^ The list must be sorted in the appropriate order of the guards usage for the predicates.+ lineFs :: [SegmentationLineFunction] -- ^ The list must be sorted in the appropriate order of the guards usage for the predicates. -- The length of the list must be equal to the ('fromEnum' . 'predicateN' . 'infoS') value.- res :: [([PRS] -> [PRS],[PRS] -> [PRS])] -- ^ The corresponding list of rules for segmentation. } {-| List of the 'SegmentationRules1' sorted in the descending order by the 'fieldN' 'SegmentationInfo1' data and where the length of all the 'SegmentationPredFunction' lists of 'PRS' are equal to the 'fieldN' 'SegmentationInfo1' data by definition. -}-type SegmentPredicates = [SegmentationRules1]+type SegmentRulesG = [SegmentationRules1] -- | Function 'divCnsnts' is used to divide groups of consonants into two-elements lists that later are made belonging to -- different neighbour syllables if the group is between two vowels in a word. The group must be not empty, but this is not checked. -- The example phonetical information for the proper performance in Ukrainian can be found from the: -- https://msn.khnu.km.ua/pluginfile.php/302375/mod_resource/content/1/%D0%9B.3.%D0%86%D0%86.%20%D0%A1%D0%BA%D0%BB%D0%B0%D0%B4.%D0%9D%D0%B0%D0%B3%D0%BE%D0%BB%D0%BE%D1%81.pdf -- The example of the 'divCnsnts' can be found at: https://hackage.haskell.org/package/ukrainian-phonetics-basic-array-0.1.2.0/docs/src/Languages.Phonetic.Ukrainian.Syllable.Arr.html#divCnsnts-divCnsnts :: [(Char,Char)] -> SegmentPredicates -> [PRS] -> ([PRS] -> [PRS],[PRS] -> [PRS])-divCnsnts ks gs xs@(_:_) = res js !! ix+divCnsnts :: [(Char,Char)] -> SegmentRulesG -> [PRS] -> DListFunctionResult+divCnsnts ks gs xs@(_:_) = resF . fromJust . L.find ((\(PF f) -> f (infoS js) xs) . predF). lineFs $ js where !l = length xs !js = fromJust . L.find ((== l) . fromEnum . fieldN . infoS) $ gs -- js :: SegmentationRules1- !ix = fromJust . L.findIndex (\(PF f) -> f (infoS js) xs) . pF $ js divCnsnts _ _ [] = (id,id) -reSyllableCntnts :: [(Char,Char)] -> SegmentPredicates -> [[PRS]] -> [[PRS]]+reSyllableCntnts :: [(Char,Char)] -> SegmentRulesG -> [[PRS]] -> [[PRS]] reSyllableCntnts ks gs (xs:ys:zs:xss) | (/= P 0) . phoneType . last $ ys = fst (divCnsnts ks gs ys) xs:reSyllableCntnts ks gs (snd (divCnsnts ks gs ys) zs:xss) | otherwise = reSyllableCntnts ks gs ((xs `mappend` ys):zs:xss)@@ -154,12 +215,12 @@ :: GWritingSystemPRPLX -> [(Char,Char)] -> CharPhoneticClassification- -> SegmentPredicates+ -> SegmentRulesG -> String -- ^ Corresponds to the \'0\' symbol delimiter in the @ukrainian-phonetics-basic-array@ package. -> String -- ^ Corresponds to the \'1\' and \'-\' symbol delimiters in the @ukrainian-phonetics-basic-array@ package. -> String -- ^ Actually the converted 'String'. -> [[[PRS]]]-createSyllablesPL wrs ks cs gs us vs = map (divVwls . reSyllableCntnts ks gs . groupSnds . str2PRSs cs) . words1 . mapMaybe g . convertToProperPL . map (\x -> if x == '-' then ' ' else x)+createSyllablesPL wrs ks arr gs us vs = map (divVwls . reSyllableCntnts ks gs . groupSnds . str2PRSs arr) . words1 . mapMaybe g . convertToProperPL . map (\x -> if x == '-' then ' ' else x) where g x | x `elem` us = Nothing | x `notElem` vs = Just x
phonetic-languages-phonetics-basics.cabal view
@@ -3,7 +3,7 @@ -- http://haskell.org/cabal/users-guide/ name: phonetic-languages-phonetics-basics-version: 0.3.0.0+version: 0.3.1.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. homepage: https://hackage.haskell.org/package/phonetic-languages-phonetics-basics@@ -21,7 +21,7 @@ exposed-modules: Data.Phonetic.Languages.Undefined, Data.Phonetic.Languages.Base, Data.Phonetic.Languages.Syllables -- other-modules: other-extensions: CPP, BangPatterns, UnboxedTuples, MagicHash- ghc-options: -funbox-strict-fields+ ghc-options: -funbox-strict-fields -fobject-code build-depends: base >=4.8 && <4.15, mmsyn2-array >= 0.1.3 && <1, mmsyn5 >= 0.5 && <1 -- hs-source-dirs: default-language: Haskell2010