packages feed

phonetic-languages-ukrainian-array 0.2.1.0 → 0.3.0.0

raw patch · 4 files changed

+114/−79 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -12,3 +12,9 @@  * Second version revised A. Changed the prepareGrowTextN function (and renamed it to prepareGrowTextMN) so that it has some additional meaning.++## 0.3.0.0 -- 2021-08-30++* Third version. Added new variants of the concatenations. Some code improvements. Fixed several issues with+consequently going complex words and a prepositions (not very common but actually usable and possible variant).+Added some improvements to deal with some rare cases.
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2020 OleksandrZhabenko+Copyright (c) 2020-2021 OleksandrZhabenko  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
Phonetic/Languages/Ukrainian/PrepareText.hs view
@@ -48,7 +48,7 @@ import GHC.List (scanl1)  -- | Is used to convert a Ukrainian text into list of 'String' each of which is ready to be--- used by the functions from the other modules in the package.+-- used by the functions of the modules for the phonetic languages approach. -- It applies minimal grammar links and connections between the most commonly used Ukrainian -- words that \"should\" be paired and not dealt with separately -- to avoid the misinterpretation and preserve maximum of the semantics for the@@ -60,67 +60,95 @@ -- | Concatenates complex words in Ukrainian 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 :: [String] -> [String]-complexWords (xs:ys:zs:ts:xss) =+complexWords wwss@(xs:ys:zs:ts:xss) =  getBFstL' (xs:complexWords (ys:zs:ts:xss)) ([("\1074",     if ys == "\1084\1110\1088\1091" && zs == "\1090\1086\1075\1086" &&-    ts == "\1103\1082" then (xs ++ ys ++ zs ++ ts ++ (concat . take 1 $ xss)):-    complexWords (drop 1 xss) else (xs ++ ys):complexWords (zs:ts:xss)),+    ts == "\1103\1082" then auxiliary2Inner (xs ++ ys ++ zs ++ ts) xss else auxiliary4 wwss),     ("\1076\1072\1088\1084\1072", if ys == "\1097\1086"-    then (xs ++ ys ++ zs):complexWords (ts:xss)-    else (xs ++ ys):complexWords (zs:ts:xss)), ("\1076\1083\1103",+    then auxiliary3 wwss else auxiliary4 wwss), ("\1076\1083\1103",     if ys == "\1090\1086\1075\1086" && zs == "\1097\1086\1073"-    then (xs ++ ys ++ zs ++ ts):complexWords xss-    else (xs ++ ys):complexWords (zs:ts:xss)), ("\1079",+    then auxiliary2Inner (xs ++ ys ++ zs ++ ts) xss+    else auxiliary4 wwss), ("\1079",       case ys of         "\1090\1080\1084" -> if zs == "\1097\1086\1073"-          then (xs ++ ys ++ zs):complexWords (ts:xss)-          else (xs ++ ys):complexWords (zs:ts:xss)+          then auxiliary2Inner (xs ++ ys ++ zs) (ts:xss)+          else auxiliary4 wwss         "\1090\1086\1075\1086" -> if zs == "\1095\1072\1089\1091" && ts == "\1103\1082"-          then (xs ++ ys ++ zs ++ "\1081\1072\1082" ++-          (concat . take 1 $ xss)):complexWords (drop 1 xss)-          else (xs ++ ys):complexWords (zs:ts:xss)-        _ -> (xs ++ ys):complexWords (zs:ts:xss)), ("\1079\1072\1084\1110\1089\1090\1100",+          then auxiliary2Inner (xs ++ ys ++ zs ++ "\1081\1072\1082") xss+          else auxiliary4 wwss+        _ -> auxiliary4 wwss), ("\1079\1072\1083\1077\1078\1085\1086",+    if ys == "\1074\1110\1076" then auxiliary3 wwss else auxiliary4 wwss),+    ("\1079\1072\1084\1110\1089\1090\1100",     if ys == "\1090\1086\1075\1086" && zs == "\1097\1086\1073"-    then (xs ++ ys ++ zs ++ ts):complexWords xss-    else (xs ++ ys):complexWords (zs:ts:xss)), ("\1087\1086\1087\1088\1080",-    if ys == "\1090\1077" && zs == "\1097\1086" then (xs ++ ys ++ zs ++ ts):complexWords xss-    else (xs ++ ys):complexWords (zs:ts:xss)), ("\1087\1088\1080",-    if ys == "\1094\1100\1086\1084\1091" then (xs ++ ys ++ zs):complexWords (ts:xss)-    else (xs ++ ys):complexWords (zs:ts:xss)), ("\1087\1110\1089\1083\1103",-    if ys == "\1090\1086\1075\1086" && zs == "\1103\1082" then (xs ++ ys ++ zs ++ ts):complexWords xss-    else (xs ++ ys):complexWords (zs:ts:xss)), ("\1090\1072\1082", if ys == "\1097\1086"-    then (xs ++ ys ++ zs):complexWords (ts:xss) else (xs ++ ys):complexWords (zs:ts:xss)),+    then auxiliary2Inner (xs ++ ys ++ zs) (ts:xss)+    else auxiliary4 wwss), ("\1087\1086\1087\1088\1080",+    if ys == "\1090\1077" && zs == "\1097\1086" then auxiliary2Inner (xs ++ ys ++ zs) (ts:xss)+    else auxiliary4 wwss),("\1085\1077\1079\1072\1083\1077\1078\1085\1086",+    if ys == "\1074\1110\1076" then auxiliary3 wwss else auxiliary4 wwss),+    ("\1085\1077\1079\1074\1072\1078\1072\1102\1095\1080", if ys == "\1085\1072" then+    if zs == "\1090\1077" && ts == "\1097\1086" then auxiliary2Inner (xs ++ ys ++ zs ++ ts) xss+    else auxiliary3 wwss else auxiliary4 wwss),+    ("\1087\1088\1080",+    if ys == "\1094\1100\1086\1084\1091" then auxiliary3 wwss+    else auxiliary4 wwss), ("\1087\1110\1089\1083\1103",+    if ys == "\1090\1086\1075\1086" && zs == "\1103\1082" then auxiliary2Inner (xs ++ ys ++ zs) (ts:xss)+    else auxiliary4 wwss), ("\1090\1072\1082", if ys == "\1097\1086" then auxiliary3 wwss else auxiliary4 wwss),+    ("\1090\1072\1082", if ys == "\1103\1082" then auxiliary3 wwss else auxiliary4 wwss),     ("\1090\1080\1084\1095\1072\1089\1086\1084", if ys == "\1103\1082"-    then (xs ++ ys ++ zs):complexWords (ts:xss) else (xs ++ ys):complexWords (zs:ts:xss)),-    ("\1090\1086\1084\1091", if ys == "\1103\1082" then (xs ++ "\1081\1072\1082" ++ zs):complexWords (ts:xss)-    else (xs ++ ys):complexWords (zs:ts:xss)), ("\1091", if ys == "\1084\1110\1088\1091" &&-    zs == "\1090\1086\1075\1086" && ts == "\1103\1082" then (xs ++ ys ++ zs ++ ts ++-    (concat . take 1 $ xss)):complexWords (drop 1 xss) else (xs ++ ys):complexWords (zs:ts:xss)),-    ("\1093\1086\1095", if ys == "\1073\1080" then (xs ++ ys ++ zs):complexWords (ts:xss)-    else (xs ++ ys):complexWords (zs:ts:xss)), ("\1093\1086\1095", if ys == "\1073\1080"-    then (xs ++ ys ++ zs):complexWords (ts:xss) else (xs ++ ys):complexWords (zs:ts:xss)),+    then auxiliary3 wwss else auxiliary4 wwss),+    ("\1090\1086\1084\1091", if ys == "\1103\1082" then auxiliary2Inner (xs ++ "\1081\1072\1082") (zs:ts:xss)+    else auxiliary4 wwss), ("\1091",+    if (ys == "\1079\1074'\1103\1079\1082\1091" || ys == "\1079\1074\x02BC\1103\1079\1082\1091") && zs == "\1079"+    then auxiliary2Inner (xs ++ "\1079\1074\1081\1072\1079\1082\1091" ++ zs) (ts:xss)+    else auxiliary2Inner "\1091" (ys:zs:ts:xss)),+    ("\1091", if ys == "\1084\1110\1088\1091" &&+    zs == "\1090\1086\1075\1086" && ts == "\1103\1082" then auxiliary2Inner (xs ++ ys ++ zs ++ ts) xss+    else auxiliary4 wwss),+    ("\1093\1086\1095", if ys == "\1073\1080" then auxiliary3 wwss+    else auxiliary4 wwss), ("\1093\1086\1095\1072", if ys == "\1073"+    then auxiliary3 wwss else auxiliary4 wwss),     ("\1095\1077\1088\1077\1079", if ys == "\1090\1077" && zs == "\1097\1086"-    then (xs ++ ys ++ zs ++ ts):complexWords xss else (xs ++ ys):complexWords (zs:ts:xss))]) xs-complexWords (xs:ys:zs:_) =- getBFstL' [xs,ys,zs] [-    ("\1076\1072\1088\1084\1072", if ys == "\1097\1086"-    then [xs ++ ys ++ zs]-    else [xs ++ ys,zs]), ("\1079",-      case ys of-        "\1090\1080\1084" -> if zs == "\1097\1086\1073"-          then [xs ++ ys ++ zs]-          else [xs ++ ys,zs]-        _ -> [xs ++ ys,zs]), ("\1087\1088\1080",-    if ys == "\1094\1100\1086\1084\1091" then [xs ++ ys ++ zs]-    else [xs ++ ys,zs]), ("\1090\1072\1082", if ys == "\1097\1086"-    then [xs ++ ys ++ zs] else [xs ++ ys,zs]),     ("\1090\1080\1084\1095\1072\1089\1086\1084",-    if ys == "\1103\1082" then [xs ++ ys ++ zs] else [xs ++ ys, zs]),-    ("\1090\1086\1084\1091", if ys == "\1103\1082" then [xs ++ "\1081\1072\1082" ++ zs]-    else [xs ++ ys,zs]), ("\1093\1086\1095", if ys == "\1073\1080" then [xs ++ ys ++ zs]-    else [xs ++ ys,zs]), ("\1093\1086\1095", if ys == "\1073\1080"-    then [xs ++ ys ++ zs] else [xs ++ ys,zs])] xs+    then auxiliary2Inner (xs ++ ys ++ zs) (ts:xss) else auxiliary4 wwss)]) xs+complexWords wwss@(xs:ys:zs:xss) =+ getBFstL' (xs:complexWords [ys,zs]) ([("\1076\1072\1088\1084\1072", if ys == "\1097\1086"+    then auxiliary3 wwss else auxiliary4 wwss), ("\1079\1072\1083\1077\1078\1085\1086",+    if ys == "\1074\1110\1076" then auxiliary3 wwss else auxiliary4 wwss),+    ("\1085\1077\1079\1072\1083\1077\1078\1085\1086",+    if ys == "\1074\1110\1076" then auxiliary3 wwss else auxiliary4 wwss),+    ("\1087\1088\1080",+    if ys == "\1094\1100\1086\1084\1091" then auxiliary3 wwss+    else auxiliary4 wwss), ("\1090\1072\1082", if ys == "\1097\1086" then auxiliary3 wwss else auxiliary4 wwss),+    ("\1090\1072\1082", if ys == "\1103\1082" then auxiliary3 wwss else auxiliary4 wwss),+    ("\1090\1080\1084\1095\1072\1089\1086\1084", if ys == "\1103\1082"+    then auxiliary3 wwss else auxiliary4 wwss),+    ("\1090\1086\1084\1091", if ys == "\1103\1082" then auxiliary2Inner (xs ++ "\1081\1072\1082") (zs:xss)+    else auxiliary4 wwss), ("\1093\1086\1095", if ys == "\1073\1080" then auxiliary3 wwss+    else auxiliary4 wwss), ("\1093\1086\1095\1072", if ys == "\1073"+    then auxiliary3 wwss else auxiliary4 wwss)]) xs+complexWords [xs,ys]+ | ys == "\1073" || ys == "\1073\1060" = [xs ++ ys]+ | xs == "\1076\1072\1088\1084\1072" && ys == "\1097\1086" = [xs ++ ys]+ | otherwise = [xs,ys] complexWords xss = xss +auxiliary2Inner :: String -> [String] -> [String]+auxiliary2Inner ts (xs:ys:xss)+  | (concatenated2 . auxiliary1 $ [xs,ys]) /= [xs,ys] = let (rs,ws) = splitAt 1 (concatenated2 . auxiliary1 $ [xs,ys]) in+       (ts ++ head rs):complexWords (concat [ws,xss])+  | otherwise = (ts ++ xs):complexWords (ys:xss)+auxiliary2Inner ts [xs] = [ts ++ xs]+auxiliary2Inner ts _ = [ts]++auxiliary3 :: [String] -> [String]+auxiliary3 (xs:ys:xss) = auxiliary2Inner (xs ++ ys) xss+auxiliary3 xss = xss+{-# INLINE auxiliary3 #-}++auxiliary4 :: [String] -> [String]+auxiliary4 (xs:xss) = auxiliary2Inner xs xss+auxiliary4 xss = xss+{-# INLINE auxiliary4 #-}+ -- | Since 0.2.1.0 version 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 = splitLinesN 7@@ -135,8 +163,9 @@  -- | A generalized variant of the 'prepareText' with the arbitrary maximum number of the words in the lines given as the first argument. prepareTextN :: Int -> String -> [String]-prepareTextN n = filter (any isUkrainianL) . splitLinesN n . map (unwords . concatenated2. auxiliary1 . complexWords . words . filter (\t -> isAlpha t || isSpC t)) . filter (not . null) . lines-+prepareTextN n = filter (any isUkrainianL) . splitLinesN n .+  map (unwords . concatenated2. auxiliary1 . complexWords . words . filter (\t -> isAlpha t || isSpC t)) .+       filter (not . null) . lines  auxiliary1 :: [String] -> [String] auxiliary1 (xs:ys:zs:xss)@@ -154,28 +183,28 @@   getBFstL' False    (zip ["\1030\1079", "\1041\1077\1079", "\1041\1110\1083\1103", "\1042",     "\1042\1110\1076", "\1044\1083\1103", "\1044\1086", "\1047",-     "\1047\1072", "\1047\1072\1088\1072\1076\1080", "\1047\1110",-      "\1050", "\1050\1086\1083\1086", "\1050\1088\1110\1079\1100",-       "\1050\1088\1110\1084", "\1052\1077\1078", "\1052\1077\1078\1080",-        "\1052\1110\1078", "\1053\1072", "\1053\1072\1076", "\1054",-         "\1054\1073", "\1054\1076", "\1054\1082\1088\1110\1084",-          "\1055\1077\1088\1077\1076", "\1055\1086", "\1055\1088\1080",-           "\1055\1088\1086", "\1055\1088\1086\1090\1080",-            "\1055\1110\1076", "\1055\1110\1089\1083\1103",-             "\1057\1077\1088\1077\1076", "\1057\1077\1088\1077\1076\1080",-              "\1059", "\1063\1077\1088\1077\1079", "\1073\1077\1079",-               "\1073\1110\1083\1103", "\1074", "\1074\1110\1076",-                "\1076\1083\1103", "\1076\1086", "\1079", "\1079\1072",-                 "\1079\1072\1088\1072\1076\1080", "\1079\1110",-                  "\1082", "\1082\1086\1083\1086", "\1082\1088\1110\1079\1100",-                   "\1082\1088\1110\1084", "\1084\1077\1078", "\1084\1077\1078\1080",-                    "\1084\1110\1078", "\1085\1072", "\1085\1072\1076", "\1086",-                     "\1086\1073", "\1086\1076", "\1086\1082\1088\1110\1084",-                      "\1087\1077\1088\1077\1076", "\1087\1086", "\1087\1088\1080",-                       "\1087\1088\1086", "\1087\1088\1086\1090\1080", "\1087\1110\1076",-                        "\1087\1110\1089\1083\1103", "\1089\1077\1088\1077\1076",-                         "\1089\1077\1088\1077\1076\1080", "\1091",-                          "\1095\1077\1088\1077\1079", "\1110\1079"] $+    "\1047\1072", "\1047\1072\1088\1072\1076\1080", "\1047\1110",+    "\1050", "\1050\1086\1083\1086", "\1050\1088\1110\1079\1100",+    "\1050\1088\1110\1084", "\1052\1077\1078", "\1052\1077\1078\1080",+    "\1052\1110\1078", "\1053\1072", "\1053\1072\1076", "\1054",+    "\1054\1073", "\1054\1076", "\1054\1082\1088\1110\1084",+    "\1055\1077\1088\1077\1076", "\1055\1086", "\1055\1088\1080",+    "\1055\1088\1086", "\1055\1088\1086\1090\1080",+    "\1055\1110\1076", "\1055\1110\1089\1083\1103",+    "\1057\1077\1088\1077\1076", "\1057\1077\1088\1077\1076\1080",+    "\1059", "\1063\1077\1088\1077\1079", "\1073\1077\1079",+    "\1073\1110\1083\1103", "\1074", "\1074\1110\1076",+    "\1076\1083\1103", "\1076\1086", "\1079", "\1079\1072",+    "\1079\1072\1088\1072\1076\1080", "\1079\1110",+    "\1082", "\1082\1086\1083\1086", "\1082\1088\1110\1079\1100",+    "\1082\1088\1110\1084", "\1084\1077\1078", "\1084\1077\1078\1080",+    "\1084\1110\1078", "\1085\1072", "\1085\1072\1076", "\1086",+    "\1086\1073", "\1086\1076", "\1086\1082\1088\1110\1084",+    "\1087\1077\1088\1077\1076", "\1087\1086", "\1087\1088\1080",+    "\1087\1088\1086", "\1087\1088\1086\1090\1080", "\1087\1110\1076",+    "\1087\1110\1089\1083\1103", "\1089\1077\1088\1077\1076",+    "\1089\1077\1088\1077\1076\1080", "\1091",+    "\1095\1077\1088\1077\1079", "\1110\1079"] $                            replicate 200 True) ts {-# INLINE isPreposition #-} @@ -282,8 +311,8 @@ {-| @ since 0.2.0.0 The function combines the 'prepareTextN' and 'growLinesN' function. Applies needed phonetic language preparations to the Ukrainian text and tries to \'grow\' the resulting 'String's in the list so that the number of the words in every-of them is no greater than the given first 'Int' number. --}             +of them is no greater than the given first 'Int' number.+-} prepareGrowTextMN   :: 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.
phonetic-languages-ukrainian-array.cabal view
@@ -2,9 +2,9 @@ --  further documentation, see http://haskell.org/cabal/users-guide/  name:                phonetic-languages-ukrainian-array-version:             0.2.1.0+version:             0.3.0.0 synopsis:            Prepares Ukrainian text to be used as a phonetic language text-description:         Prepares Ukrainian text to be used as a phonetic language text. Applies needed minimal grammar connections so that the text afterwards can be processed by dobutokO-poetry related programs. Uses arrays instead of vectors.+description:         Applies needed minimal grammar connections so that the text afterwards can be processed by dobutokO-poetry or phonetic languages approach related programs. Uses arrays instead of vectors. homepage:            https://hackage.haskell.org/package/phonetic-languages-ukrainian-array license:             MIT license-file:        LICENSE