phonetic-languages-phonetics-basics 0.3.3.0 → 0.3.4.0
raw patch · 3 files changed
+54/−6 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: C :: SegmentationPredFData a b -> SegmentationPredFData a b -> SegmentationPredFData a b
+ Data.Phonetic.Languages.Syllables: D :: SegmentationPredFData a b -> SegmentationPredFData a b -> SegmentationPredFData a b
+ Data.Phonetic.Languages.Syllables: L :: Int -> [Int] -> Array Int a -> SegmentationPredFData a b
+ Data.Phonetic.Languages.Syllables: NEC :: Int -> Int -> Array Int a -> [b] -> SegmentationPredFData a b
+ Data.Phonetic.Languages.Syllables: [infoSP] :: SegmentationLineFunction -> SegmentationInfo1
+ Data.Phonetic.Languages.Syllables: class Eval2Bool a
+ Data.Phonetic.Languages.Syllables: data SegmentationPredFData a b
+ Data.Phonetic.Languages.Syllables: eval2Bool :: Eval2Bool a => a -> Bool
+ Data.Phonetic.Languages.Syllables: fromPhoneticType :: PhoneticType -> Int
+ Data.Phonetic.Languages.Syllables: instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Data.Phonetic.Languages.Syllables.SegmentationPredFData a b)
+ Data.Phonetic.Languages.Syllables: instance (GHC.Read.Read a, GHC.Read.Read b) => GHC.Read.Read (Data.Phonetic.Languages.Syllables.SegmentationPredFData a b)
+ Data.Phonetic.Languages.Syllables: instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (Data.Phonetic.Languages.Syllables.SegmentationPredFData a b)
+ Data.Phonetic.Languages.Syllables: instance Data.Phonetic.Languages.Syllables.Eval2Bool (Data.Phonetic.Languages.Syllables.SegmentationPredFData Data.Phonetic.Languages.Syllables.PRS (GHC.Types.Char, GHC.Types.Char))
+ Data.Phonetic.Languages.Syllables: instance GHC.Read.Read Data.Phonetic.Languages.Syllables.PRS
+ Data.Phonetic.Languages.Syllables: instance GHC.Read.Read Data.Phonetic.Languages.Syllables.PhoneticType
+ Data.Phonetic.Languages.Syllables: type SegmentationFDP = SegmentationPredFData PRS (Char, Char)
- Data.Phonetic.Languages.Syllables: LFS :: SegmentationPredFunction -> Int8 -> SegmentationLineFunction
+ Data.Phonetic.Languages.Syllables: LFS :: SegmentationInfo1 -> SegmentationFDP -> Int8 -> SegmentationLineFunction
- Data.Phonetic.Languages.Syllables: [predF] :: SegmentationLineFunction -> SegmentationPredFunction
+ Data.Phonetic.Languages.Syllables: [predF] :: SegmentationLineFunction -> SegmentationFDP
Files
- ChangeLog.md +6/−0
- Data/Phonetic/Languages/Syllables.hs +46/−4
- phonetic-languages-phonetics-basics.cabal +2/−2
ChangeLog.md view
@@ -35,3 +35,9 @@ * Third version revised C. Some code improvements. Added classes and instances for classes. Some changes to imrove overall representation possibilities. ++## 0.3.4.0 -- 2021-04-26++* Third version revised D. Changed the data types representation in the Data.Phonetic.Languages.Syllables module. Used some+special function refactoring to the algebraic data type to represent a complex predicate of the special structure. Some code+improvements.
Data/Phonetic/Languages/Syllables.hs view
@@ -4,6 +4,7 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE MagicHash #-}+{-# LANGUAGE FlexibleInstances #-} -- | -- Module : Data.Phonetic.Languages.Syllables@@ -24,6 +25,9 @@ , StringRepresentation , SegmentationInfo1(..) , SegmentationPredFunction(..)+ , SegmentationPredFData(..)+ , SegmentationFDP+ , Eval2Bool(..) , DListFunctionResult , SegmentationLineFunction(..) , SegmentationRules1(..)@@ -46,6 +50,7 @@ , isVoicelessC1 , isNotVowel2 , notEqC+ , fromPhoneticType ) where import Prelude hiding (mappend)@@ -68,7 +73,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 )+} deriving ( Eq, Read ) instance Ord PRS where compare (SylS x1 y1) (SylS x2 y2) =@@ -79,11 +84,14 @@ instance Show PRS where show (SylS c (P x)) = "SylS \'" `mappend` (c:'\'':' ':show x) -data PhoneticType = P !Int8 deriving (Eq, Ord)+data PhoneticType = P !Int8 deriving (Eq, Ord, Read) instance Show PhoneticType where show (P x) = "P " `mappend` show x +fromPhoneticType :: PhoneticType -> Int+fromPhoneticType (P x) = fromEnum x+ {-| The 'Array' 'Int' must be sorted in the ascending order to be used in the module correctly. -} type CharPhoneticClassification = Array Int PRS@@ -194,8 +202,41 @@ _ -> Nothing _ -> Nothing +{-| We can think of 'SegmentationPredFunction' in terms of @f (SI fN pN) ks [x_{1},x_{2},...,x_{i},...,x_{fN}]@. Comparing with+'divCnsnts' from the @ukrainian-phonetics-basics-array@ we can postulate that it consists of the following logical terms of+the symbolic form:+1) 'phoneType' x_{i} `elem` (X{...} = map P ['Int8'])++2) 'notEqC' ks x_{i} x_{j} (j /= i)++combined with the standard logic Boolean operations of '(&&)', '(||)' and 'not'. Further, the 'not' can be transformed into the+positive (affirmative) form using the notion of the universal set for the task. This transformation needs that the similar+phonetic phenomenae (e. g. the double sounds -- the prolonged ones) belongs to the one syllable and not to the different ones+(so they are not related to different syllables, but just to the one and the same). Since such assumption is used, we can further+represent the function by the following data type and operations with it, see 'SegmentationPredFData'.+-} data SegmentationPredFunction = PF (SegmentationInfo1 -> [(Char, Char)] -> [PRS] -> Bool) +data SegmentationPredFData a b = L Int [Int] (Array Int a) | NEC Int Int (Array Int a) [b] | C (SegmentationPredFData a b) (SegmentationPredFData a b) |+ D (SegmentationPredFData a b) (SegmentationPredFData a b) deriving (Eq, Read, Show)++class Eval2Bool a where+ eval2Bool :: a -> Bool++type SegmentationFDP = SegmentationPredFData PRS (Char, Char)++instance Eval2Bool (SegmentationPredFData PRS (Char, Char)) where+ eval2Bool (L i js arr)+ | all (<= n) js && i <= n && i >= 1 && all (>=1) js = fromPhoneticType (phoneType (unsafeAt arr $ i - 1)) `elem` js+ | otherwise = error "Data.Phonetic.Languages.Syllables.eval2Bool: 'L' element is not properly defined. "+ where n = numElements arr+ eval2Bool (NEC i j arr ks)+ | i >= 1 && j >= 1 && i /= j && i <= n && j <= n = notEqC ks (unsafeAt arr $ i - 1) (unsafeAt arr $ j - 1)+ | otherwise = error "Data.Phonetic.Languages.Syllables.eval2Bool: 'NEC' element is not properly defined. "+ where n = numElements arr+ eval2Bool (C x y) = eval2Bool x && eval2Bool y+ eval2Bool (D x y) = eval2Bool x || eval2Bool y+ type DListFunctionResult = ([PRS] -> [PRS],[PRS] -> [PRS]) class DListRepresentation a b where@@ -210,7 +251,8 @@ where (ts,zs) = splitAt (fromEnum left) xs data SegmentationLineFunction = LFS {- predF :: SegmentationPredFunction, -- ^ The predicate to check the needed rule for segmentation.+ infoSP :: SegmentationInfo1,+ predF :: SegmentationFDP, -- ^ The predicate to check the needed rule for segmentation. resF :: Int8 -- ^ The result argument to be appended to the left of the group of consonants if the 'predF' returns 'True' for its arguments. Is an argument to the 'toDLR'. } @@ -233,7 +275,7 @@ divCnsnts :: [(Char,Char)] -> SegmentRulesG -> [PRS] -> DListFunctionResult divCnsnts ks gs xs@(_:_) = toDLR left xs where !js = fromJust . L.find ((== length xs) . fromEnum . fieldN . infoS) $ gs -- js :: SegmentationRules1- !left = resF . fromJust . L.find ((\(PF f) -> f (infoS js) ks xs) . predF). lineFs $ js+ !left = resF . fromJust . L.find (eval2Bool . predF). lineFs $ js divCnsnts _ _ [] = (id,id) reSyllableCntnts :: [(Char,Char)] -> SegmentRulesG -> [[PRS]] -> [[PRS]]
phonetic-languages-phonetics-basics.cabal view
@@ -3,7 +3,7 @@ -- http://haskell.org/cabal/users-guide/ name: phonetic-languages-phonetics-basics-version: 0.3.3.0+version: 0.3.4.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@@ -20,7 +20,7 @@ library exposed-modules: Data.Phonetic.Languages.Undefined, Data.Phonetic.Languages.Base, Data.Phonetic.Languages.Syllables -- other-modules:- other-extensions: CPP, BangPatterns, UnboxedTuples, MagicHash, MultiParamTypeClasses+ 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 -- hs-source-dirs: