Skip to content

Commit 478db63

Browse files
Update on Hackage
0 parents  commit 478db63

File tree

11 files changed

+730
-0
lines changed

11 files changed

+730
-0
lines changed

CHANGELOG.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Revision history for phonetic-languages-simplified-lists-examples
2+
3+
## 0.1.0.0 -- 2020-11-29
4+
5+
* First version. Released on an unsuspecting world.
6+
7+
## 0.2.0.0 -- 2020-12-01
8+
9+
* Second version. Added a new module Phonetic.Languages.Simplified.Lists.DeEnCoding for dealing with intersections using heaps functionality.
10+
For lineVariantsG2:
11+
** Added for this heaps as a new dependency (a lightweight one).
12+
13+
** Added the possibilities to leave the last word in the line on its place (this can lead to preserving rhymes in poetry, for example),
14+
to print either metrices information or not.
15+
16+
** Added the possibility to use multiple metrices at once by using +M ... -M blocks of command line arguments. The type of metrics is the first argument and
17+
the numeric arguments for it (as usual) are all further, then again you can specify up to two additional metrices with arguments enclosed by the block
18+
+M and -M delimiters.
19+
20+
## 0.3.0.0 -- 2020-12-03
21+
22+
* Third version. Extended the multiple properties mode up to 4 different properties. Added the possibility to use more
23+
intercation by interactive mode and to write the single line result to file in file writing mode.
24+
Some documentation improvements.
25+
26+
## 0.4.0.0 -- 2020-12-03
27+
28+
* Fourth version. Added the new properties ralated to the uzpp2Durat3 function -- 03y, y3 (and yy2 related to
29+
uzpp2Durat2 function).
30+
31+
## 0.5.0.0 -- 2020-12-05
32+
33+
* Fifth version. Switched to the Double instead of Float whenever possible. Some dependencies changes for this.
34+
35+
## 0.6.0.0 -- 2020-12-07
36+
37+
* Sixth version. Added multiproperties mode for propertiesTextG2 executable. Added constraint of ++B to it, too. Extended
38+
up to 5 possible properties for the lineVariantsG2 executable. Added 'whitelines' modes. Some code and documentation
39+
improvements. Added a new module Phonetic.Languages.Simplified.Lists.SimpleConstraints.
40+

GetInfo/Main.hs

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
-- |
2+
-- Module : Main
3+
-- Copyright : (c) OleksandrZhabenko 2020
4+
-- License : MIT
5+
-- Stability : Experimental
6+
-- Maintainer : [email protected]
7+
--
8+
-- Analyzes a poetic text in Ukrainian, for every line prints statistic data and
9+
-- then for the whole poem prints the hypothesis evaluation information.
10+
--
11+
-- To enable parallel computations (potentially, they can speed up the work), please, run the @propertiesText@ executable with
12+
-- @+RTS -threaded -RTS@ command line options with possibly @-N@ option inside.
13+
--
14+
15+
{-# OPTIONS_GHC -threaded -rtsopts #-}
16+
17+
{-# LANGUAGE BangPatterns, FlexibleContexts #-}
18+
19+
module Main where
20+
21+
22+
import Data.SubG hiding (takeWhile,dropWhile)
23+
import System.IO
24+
import Control.Concurrent
25+
import Control.Exception
26+
import Control.Parallel.Strategies
27+
import Data.Maybe (fromMaybe)
28+
import Data.List (sort)
29+
import Text.Read (readMaybe)
30+
import qualified Data.Vector as VB
31+
import Melodics.ByteString.Ukrainian
32+
import System.Environment
33+
import Languages.Phonetic.Ukrainian.PrepareText
34+
import Numeric (showFFloat)
35+
import Languages.UniquenessPeriods.Vector.Filters
36+
import Data.Char (isAlpha)
37+
import Data.Statistics.RulesIntervalsPlus
38+
import Data.MinMax.Preconditions
39+
import Phonetic.Languages.Lists.Ukrainian.PropertiesSyllablesG2
40+
import Phonetic.Languages.Simplified.StrictVG
41+
import Phonetic.Languages.Permutations
42+
import Phonetic.Languages.Simplified.DataG
43+
import Phonetic.Languages.Simplified.Lists.Ukrainian.FuncRep2RelatedG2
44+
import Languages.UniquenessPeriods.Vector.Constraints.Encoded
45+
import Phonetic.Languages.Simplified.Lists.SimpleConstraints
46+
47+
main :: IO ()
48+
main = do
49+
args000 <- getArgs
50+
let !args00 = filter (/= "++B") args000
51+
!lstW = any (== "++B") args000
52+
!args0 = takeWhile (/= "+M") args00 `mappend` drop 1 (dropWhile (/= "-M") args00)
53+
!multiples = drop 1 . dropWhile (/= "+M") . takeWhile (/= "-M") $ args00 -- Arguments for multiple metrices mode
54+
!args = filter (\xs -> all (/= ':') xs && all (/= '@') xs) args0
55+
!coeffs = readCF . concat . take 1 $ args -- The first command line argument. If not sure, just enter \"1_\".
56+
!lInes = filter (any (== ':')) args0
57+
!numbersJustPrint = filter (== "@n") args0
58+
if isPair coeffs then do
59+
let !file = concat . drop 1 . take 2 $ args -- The second command line argument except those ones that are RTS arguments
60+
if null numbersJustPrint then do
61+
let !gzS = concat . take 1 . drop 2 $ args -- The third command line argument that controls the choice of the number of intervals
62+
!printLine = fromMaybe 0 (readMaybe (concat . take 1 . drop 3 $ args)::(Maybe Int)) -- The fourth command line argument except those ones that are RTS arguments. Set to 1 if you would like to print the current line within the information
63+
!toOneLine = fromMaybe 0 (readMaybe (concat . take 1 . drop 4 $ args)::(Maybe Int)) -- The fifth command line argument except those ones that are RTS arguments. Set to 1 if you would like to convert the text into one single line before applying to it the processment (it can be more conceptually consistent in such a case)
64+
!choice = concat . drop 5 . take 6 $ args -- The sixth command line argument that controls what properties are used.
65+
generalProc lstW multiples lInes coeffs file gzS printLine toOneLine choice
66+
else do
67+
contents <- readFile file
68+
fLinesIO contents
69+
else do
70+
let !file = concat . take 1 $ args
71+
if null numbersJustPrint then do
72+
let !gzS = concat . take 1 . drop 1 $ args
73+
!printLine = fromMaybe 0 (readMaybe (concat . take 1 . drop 2 $ args)::(Maybe Int))
74+
!toOneLine = fromMaybe 0 (readMaybe (concat . take 1 . drop 3 $ args)::(Maybe Int))
75+
!choice = concat . drop 4 . take 5 $ args
76+
generalProc lstW multiples lInes coeffs file gzS printLine toOneLine choice
77+
else do
78+
contents <- readFile file
79+
fLinesIO contents
80+
81+
generalProc :: Bool -> [String] -> [String] -> Coeffs2 -> FilePath -> String -> Int -> Int -> String -> IO ()
82+
generalProc lstW multiples2 lInes coeffs file gzS printLine toOneLine choice
83+
| null lInes = do
84+
contents <- readFile file
85+
let !flines = fLines toOneLine contents
86+
getData3 lstW coeffs (getIntervalsNS lstW gzS flines) printLine choice multiples2 flines
87+
| otherwise = do
88+
contents <- readFile file
89+
let !flines = fLines toOneLine . unlines . linesFromArgsG lInes . fLines 0 $ contents
90+
getData3 lstW coeffs (getIntervalsNS lstW gzS flines) printLine choice multiples2 flines
91+
92+
linesFromArgs1 :: Int -> String -> [String] -> [String]
93+
linesFromArgs1 n xs yss =
94+
let (!ys,!zs) = (\(x,z) -> (x, drop 1 z)) . break (== ':') $ xs
95+
!ts = sort . map (min n . abs) $ [fromMaybe 1 (readMaybe ys::Maybe Int), fromMaybe n (readMaybe zs::Maybe Int)] in
96+
drop (head ts - 1) . take (last ts) $ yss
97+
98+
linesFromArgsG :: [String] -> [String] -> [String]
99+
linesFromArgsG xss yss = let n = length yss in concatMap (\ts -> linesFromArgs1 n ts yss) xss
100+
101+
getData3 :: Bool -> Coeffs2 -> Int -> Int -> String -> [String] -> [String] -> IO ()
102+
getData3 lstW coeffs gz printLine choice multiples3 zss = let !permsV4 = genPermutationsVL in putStrLn (replicate (length multiples3 + 1) '\t' `mappend` show gz) >> mapM_ (process1Line lstW coeffs gz printLine choice multiples3 permsV4) zss
103+
104+
process1Line :: Bool -> Coeffs2 -> Int -> Int -> String -> [String] -> VB.Vector [VB.Vector Int] -> String -> IO ()
105+
process1Line lstW coeffs gz printLine choice multiples4 !permsV50 v
106+
| null multiples4 = bracket (do {
107+
myThread <- forkIO (do
108+
let !v2 = words v
109+
!l2 = length v2 - 2
110+
if l2 >= (if lstW then 1 else 0) then do
111+
let !permsV5 = decodeConstraint1 (fromMaybe (E 1) . readMaybeECG (l2 + 1) . showB (l2 + 2) $ lstW) .
112+
VB.unsafeIndex permsV50 $ l2
113+
((!minE,!maxE),!data2) = runEval (parTuple2 rpar rpar (minMax11C . map (toTransPropertiesF' (chooseMax id coeffs choice )) .
114+
uniquenessVariants2GNBL ' ' id id id permsV5 $ v2, toTransPropertiesF' (chooseMax id coeffs choice) . unwords . subG " 01-" $ v))
115+
(!wordsN,!intervalN) = (l2 + 2, intervalNRealFrac minE maxE gz data2)
116+
!ratio = if maxE == 0.0 then 0.0 else 2.0 * data2 / (minE + maxE)
117+
hPutStr stdout . showFFloat (precChoice choice) minE $ "\t"
118+
hPutStr stdout . showFFloat (precChoice choice) data2 $ "\t"
119+
hPutStr stdout . showFFloat (precChoice choice) maxE $ "\t"
120+
hPutStr stdout . showFFloat (Just 4) (data2 / minE) $ "\t"
121+
hPutStr stdout . showFFloat (Just 4) (maxE / minE) $ "\t"
122+
hPutStr stdout . showFFloat (Just 4) (maxE / data2) $ "\t"
123+
hPutStr stdout . showFFloat (Just 8) ratio $ "\t"
124+
hPutStr stdout ('\t':show (wordsN::Int))
125+
hPutStr stdout ('\t':show (intervalN::Int))
126+
hPutStrLn stdout (if printLine == 1 then '\t':v else "")
127+
else putStrLn (replicate (length multiples4) '\t' ++ if printLine == 1 then '\t':v else ""))
128+
; return myThread }) (killThread) (\_ -> putStr "")
129+
| otherwise = bracket (do {
130+
myThread <- forkIO (do
131+
let !v2 = words v
132+
!l2 = length v2 - 2
133+
if l2 >= (if lstW then 1 else 0) then do
134+
let !permsV5 = decodeConstraint1 (fromMaybe (E 1) . readMaybeECG (l2 + 1) . showB (l2 + 2) $ lstW) .
135+
VB.unsafeIndex permsV50 $ l2
136+
rs = parMap rpar (\choiceMMs -> (minMax11C .
137+
map (toTransPropertiesF' (chooseMax id coeffs choiceMMs)) .
138+
uniquenessVariants2GNBL ' ' id id id permsV5 $ v2,
139+
toTransPropertiesF' (chooseMax id coeffs choiceMMs) . unwords . subG " 01-" $ v,gz)) multiples4
140+
(!wordsN,!intervalNs) = (l2 + 2, map (\((!x,!y),!z,!t) -> intervalNRealFrac x y t z) rs)
141+
in do
142+
hPutStr stdout (show (wordsN::Int))
143+
mapM_ (\i -> hPutStr stdout ('\t':show (i::Int))) intervalNs
144+
hPutStrLn stdout (if printLine == 1 then '\t':v else "")
145+
else putStrLn (replicate (length multiples4) '\t' ++ if printLine == 1 then '\t':v else ""))
146+
; return myThread }) (killThread) (\_ -> putStr "")
147+
148+
fLines :: Int -> String -> [String]
149+
fLines !toOneLine ys =
150+
let preText = filter (any (\x -> isUkrainianL x && isAlpha x)) . prepareText . (\z -> if toOneLine == 1 then unwords . words $ z else z) $ ys
151+
wss = map (length . subG " 01-") preText
152+
g (t:ts) (r:rs) = if r > 7 then filter (`notElem` "01-") t:g ts rs else t:g ts rs
153+
g _ _ = []
154+
in g preText wss
155+
156+
fLinesIO :: String -> IO ()
157+
fLinesIO ys =
158+
let preText = filter (any (\x -> isUkrainianL x && isAlpha x)) . prepareText $ ys
159+
wss = map (length . subG " 01-") preText
160+
g (t:ts) (r:rs) = if r > 7 then filter (`notElem` "01-") t:g ts rs else t:g ts rs
161+
g _ _ = []
162+
in VB.mapM_ putStrLn . VB.map (\(i,x) -> show (i + 1) ++ "\t" ++ x) . VB.indexed . VB.fromList . g preText $ wss

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2020 OleksandrZhabenko
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included
12+
in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Lines/Main.hs

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
-- |
2+
-- Module : Main
3+
-- Copyright : (c) OleksandrZhabenko 2020
4+
-- License : MIT
5+
-- Stability : Experimental
6+
-- Maintainer : [email protected]
7+
--
8+
-- Inspired by: https://functional-art.org/2020/papers/Poetry-OleksandrZhabenko.pdf from the https://functional-art.org/2020/performances ;
9+
-- Allows to rewrite the given text (usually a poetical one).
10+
11+
{-# OPTIONS_GHC -threaded -rtsopts #-}
12+
13+
{-# LANGUAGE BangPatterns #-}
14+
15+
module Main where
16+
17+
import Phonetic.Languages.Simplified.Lists.DeEnCoding (newLineEnding)
18+
import System.IO
19+
import Data.SubG
20+
import Data.MinMax.Preconditions
21+
import qualified Data.Vector as VB
22+
import Data.List (sort)
23+
import Phonetic.Languages.Lists.Ukrainian.PropertiesSyllablesG2
24+
import Phonetic.Languages.Simplified.StrictVG
25+
import Phonetic.Languages.Permutations
26+
import Languages.UniquenessPeriods.Vector.Filters (unsafeSwapVecIWithMaxI)
27+
import Text.Read (readMaybe)
28+
import Data.Maybe (fromMaybe)
29+
import System.Environment
30+
import Languages.Phonetic.Ukrainian.PrepareText
31+
import Phonetic.Languages.Simplified.DataG
32+
import Data.Char (isDigit)
33+
import Phonetic.Languages.Simplified.Lists.Ukrainian.FuncRep2RelatedG2
34+
import Data.Monoid (mappend)
35+
36+
-- | The function allows to rewrite the Ukrainian text in the file given as the first command line argument to a new file. In between, it is rewritten
37+
-- so that every last word on the lines is preserved at its position, and the rest of the line is rearranged using the specified other command line
38+
-- arguments. They are general for the whole program. The first command line argument is a FilePath to the file with a Ukrainian text to be rewritten.
39+
-- The second one is a variant of the \"properties\" used to evaluate the variants.
40+
-- The further command line arguments are: the number of the intervals and the numbers of the intervals
41+
-- that are swapped with the maximum one so that they are available for further usage by the program. See documentation for @uniqueness-periods-vector-filters@
42+
-- package
43+
-- 'https://hackage.haskell.org/package/uniqueness-periods-vector-filters'
44+
--
45+
main :: IO ()
46+
main = do
47+
args <- getArgs
48+
let coeffs = readCF . concat . take 1 $ args -- The first command line argument. If not sure, pass just \"1_\".
49+
if isPair coeffs then do
50+
let !numericArgs = filter (all isDigit) . drop 3 $ args
51+
!choice = concat . drop 2 . take 3 $ args
52+
!numberI = fromMaybe 1 (readMaybe (concat . take 1 $ numericArgs)::Maybe Int)
53+
!file = concat . drop 1 . take 2 $ args
54+
generalProcessment coeffs numericArgs choice numberI file
55+
else do
56+
let !numericArgs = filter (all isDigit) . drop 2 $ args
57+
!choice = concat . drop 1 . take 2 $ args
58+
!numberI = fromMaybe 1 (readMaybe (concat . take 1 $ numericArgs)::Maybe Int)
59+
!file = concat . take 1 $ args
60+
generalProcessment coeffs numericArgs choice numberI file
61+
62+
generalProcessment :: Coeffs2 -> [String] -> String -> Int -> FilePath -> IO ()
63+
generalProcessment coeffs numericArgs choice numberI file = do
64+
contents <- readFile file
65+
let !permsV = VB.force genPermutationsVL
66+
!flines = fLines contents
67+
!lasts = map (\ts -> if null . words $ ts then [] else last . words $ ts) flines
68+
if compare numberI 2 == LT then toFileStr (file ++ ".new.txt") (circle2 coeffs permsV choice [] $ flines)
69+
else do
70+
let !intervalNmbrs = (\vs -> if null vs then VB.singleton numberI else VB.uniq . VB.fromList $ vs) . sort . filter (<= numberI) .
71+
map (\t -> fromMaybe numberI (readMaybe t::Maybe Int)) . drop 2 $ numericArgs
72+
!us = words . concat . take 1 $ flines
73+
!l2 = (subtract 3) . length $ us
74+
if compare l2 0 /= LT then do
75+
let !perms2 = VB.unsafeIndex permsV $ l2
76+
(!minE,!maxE) = let !frep20 = chooseMax id coeffs choice in minMax11C . map (toPropertiesF' frep20) .
77+
uniquenessVariants2GNPBL [] (concat . take 1 $ lasts) ' ' id id id perms2 . init $ us
78+
toFileStr (file ++ ".new.txt") (circle2I coeffs permsV choice [] numberI intervalNmbrs minE maxE $ flines)
79+
else toFileStr (file ++ ".new.txt") ((concat . take 1 $ flines):(circle2I coeffs permsV choice [] numberI intervalNmbrs 0.0 0.0 . drop 1 $ flines))
80+
81+
fLines :: String -> [String]
82+
fLines ys =
83+
let preText = prepareText ys
84+
wss = map (length . subG " 01-") preText
85+
g (t:ts) (r:rs) = if r > 7 then filter (`notElem` "01-") t:g ts rs else t:g ts rs
86+
g _ _ = []
87+
in g preText wss
88+
89+
-- | Processment without rearrangements.
90+
circle2 :: Coeffs2 -> VB.Vector [VB.Vector Int] -> String -> [String] -> [String] -> [String]
91+
circle2 coeffs permsG1 choice yss xss
92+
| null xss = yss
93+
| otherwise = circle2 coeffs permsG1 choice (yss `mappend` [ws]) tss
94+
where (!zss,!tss) = splitAt 1 xss
95+
!rs = words . concat $ zss
96+
!l = length rs
97+
!frep2 = chooseMax id coeffs choice
98+
!ws = if compare l 3 == LT then unwords rs else line . maximumElR . map (toResultR frep2) .
99+
uniquenessVariants2GNPBL [] (last rs) ' ' id id id (VB.unsafeIndex permsG1 (l - 3)) . init $ rs
100+
101+
102+
-- | Processment with rearrangements.
103+
circle2I :: Coeffs2 -> VB.Vector [VB.Vector Int] -> String -> [String] -> Int -> VB.Vector Int -> Double -> Double -> [String] -> [String]
104+
circle2I coeffs permsG1 choice yss numberI vI minE maxE xss
105+
| null xss = yss
106+
| otherwise = circle2I coeffs permsG1 choice (yss `mappend` [ws]) numberI vI minE1 maxE1 tss
107+
where (!zss,!tss) = splitAt 1 xss
108+
!w2s = words . concat . take 1 $ tss
109+
!l3 = (subtract 3) . length $ w2s
110+
!rs = words . concat $ zss
111+
!l = length rs
112+
!frep2 = chooseMax (unsafeSwapVecIWithMaxI minE maxE numberI vI) coeffs choice
113+
!ws = if compare (length rs) 3 == LT then unwords rs else line . maximumElR . map (toResultR frep2) .
114+
uniquenessVariants2GNPBL [] (last rs) ' ' id id id (VB.unsafeIndex permsG1 (l - 3)) . init $ rs
115+
(!minE1,!maxE1)
116+
| compare l3 0 /= LT =
117+
let !perms3 = VB.unsafeIndex permsG1 l3
118+
!v4 = init w2s
119+
!frep20 = chooseMax id coeffs choice in minMax11C . map (toPropertiesF' frep20) .
120+
uniquenessVariants2GNPBL [] (last w2s) ' ' id id id perms3 $ v4
121+
| otherwise = (0.0,0.0)
122+
123+
-- | Prints every element from the structure on the new line to the file. Uses 'appendFile' function inside. Is taken from
124+
-- the Languages.UniquenessPeriods.Vector.General.DebugG module from the @phonetic-languages-general@ package.
125+
toFileStr ::
126+
FilePath -- ^ The 'FilePath' to the file to be written in the 'AppendMode' (actually appended with) the information output.
127+
-> [String] -- ^ Each element is appended on the new line to the file.
128+
-> IO ()
129+
toFileStr file xss = mapM_ (\xs -> appendFile file (xs `mappend` newLineEnding)) xss

0 commit comments

Comments
 (0)