Skip to content

Commit

Permalink
Update on Hackage
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrZhabenko committed Dec 28, 2020
0 parents commit e9de865
Show file tree
Hide file tree
Showing 9 changed files with 616 additions and 0 deletions.
82 changes: 82 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Revision history for phonetic-languages-examples

## 0.1.0.0 -- 2020-10-30

* First version. Released on an unsuspecting world.

## 0.1.1.0 -- 2020-11-06

* First version revised A. Changed the dependency boundaries so that the package uses the latest versions.

## 0.1.2.0 -- 2020-11-06

* First version revised B. Fixed some issues with the text preprocessing so that avoid unconsistency between different packages. Some simplification of the code for the
propertiesTextG executable.

## 0.2.0.0 -- 2020-11-07

* Second version. Added the possibilities to use new related to generated with r-glpk-phonetic-languages-ukrainian-durations package duration metrices.
Changed the dependencies boundaries for this.

## 0.3.0.0 -- 2020-11-09

* Third version. Added the possibility to use coefficients' version of the rhythmicity-related functions from the phonetic-languages-rhythmicity and
phonetic-languages-properties packages.

## 0.3.1.0 -- 2020-11-09

* Third version revised A. Fixed issue with the wrong output option for one of the columns in the propertiesTextG executable running output.

## 0.3.1.1 -- 2020-11-09

* Third version revised A. Fixed the wrong comment about the first command line argument.

## 0.3.2.0 -- 2020-11-10

* Third version revised B. Fixed issue with missing variant for procBothF function in the working program. Updated the dependency boundaries of
the ukrainian-phonetics-basic.

## 0.3.3.0 -- 2020-11-10

* Third version revised C. Fixed issue with the reverse order of the output for the rewritePoemG executable.

## 0.4.0.0 -- 2020-11-12

* Fourth version. Added the possibility to use constraints from the phonetic-languages-constraints package (it is also a new leightweight dependency)
in the lineVariantsG executable. They allows to reduce number of computations needed and explicitly apply additional needed grammar rules, extend
the extent of understandable text and so on.

## 0.4.1.0 -- 2020-11-12

* Fourth version revised A. Fixed issue with incorrect behaviour because of phonetic-languages-constraints inner issue. Changed the dependency boundaries appropriately. Changed
the behaviour of the lineVariantsG so that you can use no coeffs (specially formatted first command line argument), this then is like for the versions before 0.3.0.0.

## 0.4.2.0 -- 2020-11-12

* Fourth version revised B. Fixed issues with maximumElBy from the phonetic-languages-general package by upgrading to the latest version.

## 0.5.0.0 -- 2020-11-13

* Fifth version. Added file README.md with the persistent link to the instruction (in Ukrainian) how to use the programs of the package.

## 0.6.0.0 -- 2020-11-16

* Sixth version. Added the possibility to select the lines for analysis by propertiesTextG and to print the analyzed text with line numbers. To print it with
line numbers use the command line argument @n. Afterwards, running again, specify the needed line numbers by the first one number and the last one number
separated with colon (':'). You can specify multiple times. The order would have been the same as you have specified.

## 0.6.1.0 -- 2020-11-18

* Sixth version revised A. Changed the usage of the maximumElBy from the Languages.UniquenessPeriods.Vector.General.DebugG module to the respective function from the
Languages.UniquenessPeriods.Vector.General.Simplified module to reduce computations. Changed the boundaries for the dependency of phonetic-languages-general and subG. Please,
update to the version with updating also phonetic-languages-general, phonetic-languages-common and subG.

## 0.6.2.0 -- 2020-11-18

* Sixth version revised B. Fixed issue with the wrong numeration in the propertiesTextG processment so that it does not equals to the needed and
documented one. Now works as expected.

## 0.6.3.0 -- 2020-11-27

* Sixth version revised C. Updated the dependencies boundaries.

154 changes: 154 additions & 0 deletions GetInfo/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
-- |
-- Module : Main
-- Copyright : (c) OleksandrZhabenko 2020
-- License : MIT
-- Stability : Experimental
-- Maintainer : [email protected]
--
-- Analyzes a poetic text in Ukrainian, for every line prints statistic data and
-- then for the whole poem prints the hypothesis evaluation information.
--
-- To enable parallel computations (potentially, they can speed up the work), please, run the @propertiesText@ executable with
-- @+RTS -threaded -RTS@ command line options with possibly @-N@ option inside.
--

{-# OPTIONS_GHC -threaded -rtsopts #-}

{-# LANGUAGE BangPatterns, FlexibleContexts #-}

module Main where


import Data.SubG
import System.IO
import Control.Concurrent
import Control.Exception
import Control.Parallel.Strategies
import Data.Maybe (fromMaybe)
import Data.List (sort)
import Text.Read (readMaybe)
import qualified Data.Vector as VB
import Languages.UniquenessPeriods.Vector.General.Simplified
import Languages.UniquenessPeriods.Vector.General.DebugG hiding (newLineEnding,maximumElBy)
import Languages.UniquenessPeriods.Vector.PropertiesG
import Languages.UniquenessPeriods.Vector.PropertiesFuncRepG
import Languages.UniquenessPeriods.Vector.PropertiesSyllablesG
import Melodics.ByteString.Ukrainian
import System.Environment
import Languages.Phonetic.Ukrainian.PrepareText
import Languages.UniquenessPeriods.Vector.DataG
import Languages.UniquenessPeriods.Vector.AuxiliaryG
import Languages.UniquenessPeriods.Vector.StrictVG
import Numeric (showFFloat)
import Languages.UniquenessPeriods.Vector.Filters
import Data.Char (isAlpha)
import Data.Statistics.RulesIntervals
import Languages.UniquenessPeriods.Vector.FuncRepRelatedG


main :: IO ()
main = do
args0 <- getArgs
let args = filter (\xs -> all (/= ':') xs && all (/= '@') xs) args0
!coeffs = readCF . concat . take 1 $ args -- The first command line argument. If not sure, just enter \"1_\".
!lInes = filter (any (== ':')) args0
!numbersJustPrint = filter (== "@n") args0
if isPair coeffs then do
let !file = concat . drop 1 . take 2 $ args -- The second command line argument except those ones that are RTS arguments
if null numbersJustPrint then do
let !gzS = concat . take 1 . drop 2 $ args -- The third command line argument that controls the choice of the number of intervals
!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
!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)
!choice = concat . drop 5 . take 6 $ args -- The sixth command line argument that controls what properties are used.
generalProc lInes coeffs file gzS printLine toOneLine choice
else do
contents <- readFile file
fLinesIO contents
else do
let !file = concat . take 1 $ args
if null numbersJustPrint then do
let !gzS = concat . take 1 . drop 1 $ args
!printLine = fromMaybe 0 (readMaybe (concat . take 1 . drop 2 $ args)::(Maybe Int))
!toOneLine = fromMaybe 0 (readMaybe (concat . take 1 . drop 3 $ args)::(Maybe Int))
!choice = concat . drop 4 . take 5 $ args
generalProc lInes coeffs file gzS printLine toOneLine choice
else do
contents <- readFile file
fLinesIO contents

generalProc :: [String] -> Coeffs2 -> FilePath -> String -> Int -> Int -> String -> IO ()
generalProc lInes coeffs file gzS printLine toOneLine choice
| null lInes = do
contents <- readFile file
let !flines = fLines toOneLine contents
getData3 coeffs (getIntervalsN gzS flines) printLine choice flines
| otherwise = do
contents <- readFile file
let flines = fLines toOneLine . unlines . linesFromArgsG lInes . map VB.toList . fLines 0 $ contents
getData3 coeffs (getIntervalsN gzS flines) printLine choice flines

linesFromArgs1 :: Int -> String -> [String] -> [String]
linesFromArgs1 n xs yss =
let (!ys,!zs) = (\(x,z) -> (x, drop 1 z)) . break (== ':') $ xs
!ts = sort . map (min n . abs) $ [fromMaybe 1 (readMaybe ys::Maybe Int), fromMaybe n (readMaybe zs::Maybe Int)] in
drop (head ts - 1) . take (last ts) $ yss

linesFromArgsG :: [String] -> [String] -> [String]
linesFromArgsG xss yss = let n = length yss in concatMap (\ts -> linesFromArgs1 n ts yss) xss

getIntervalsN :: String -> [VB.Vector Char] -> Int
getIntervalsN xs ys
| xs == "s" = sturgesH (length ys)
| xs == "l" = levynskyiMod (length ys)
| otherwise = fromMaybe 9 (readMaybe xs::(Maybe Int))
{-# INLINE getIntervalsN #-}

getData3 :: Coeffs2 -> Int -> Int -> String -> [VB.Vector Char] -> IO ()
getData3 coeffs gz printLine choice zs = let !permsV4 = genPermutationsV in mapM_ (process1Line coeffs gz printLine choice permsV4) zs

process1Line :: Coeffs2 -> Int -> Int -> String -> VB.Vector (VB.Vector (VB.Vector Int)) -> VB.Vector Char -> IO ()
process1Line coeffs gz printLine choice !permsV5 v = bracket (do
myThread <- forkIO (do
let !whspss = VB.fromList " 01-"
!v2 = subG whspss v
!l2 = (subtract 2) . VB.length $ v2
(!maxE,!minE,!data2)
| compare l2 0 /= LT = runEval (parTuple3 rpar rpar rpar ((\k -> if k == 0.0 then 1.0 else k) . (\ls -> if null ls then 0.0 else head ls) .
firstFrom3 . maximumElBy 1 (VB.singleton oneProperty) .
uniquenessVariants2GNB ' ' id id id (VB.unsafeIndex permsV5 l2) (VB.singleton oneProperty) (chooseMax coeffs choice) $ v2,
(\k -> if k == 0.0 then 1.0 else k) . abs . (\ls -> if null ls then 0.0 else head ls) .
firstFrom3 . maximumElBy 1 (VB.singleton oneProperty) .
uniquenessVariants2GNB ' ' id id id (VB.unsafeIndex permsV5 l2) (VB.singleton oneProperty) (chooseMin coeffs choice) $ v2,
(\k -> if k == 0.0 then 1.0 else k) . head . getAC (chooseMax coeffs choice) $ v))
| otherwise = let !mono = (\k -> if k == 0.0 then 1.0 else k) . head . getAC (chooseMax coeffs choice) $ v in (mono,mono,mono)
(!wordsN,!intervalN)
| maxE == 1.0 = (0, 0)
| otherwise = runEval (parTuple2 rpar rpar (l2 + 2, intervalNRealFrac minE maxE gz data2))
!ratio = if maxE == 1.0 then 0.0 else 2.0 * data2 / (minE + maxE) in do
hPutStr stdout . showFFloat (precChoice choice) minE $ "\t"
hPutStr stdout . showFFloat (precChoice choice) data2 $ "\t"
hPutStr stdout . showFFloat (precChoice choice) maxE $ "\t"
hPutStr stdout . showFFloat (Just 4) (data2 / minE) $ "\t"
hPutStr stdout . showFFloat (Just 4) (maxE / minE) $ "\t"
hPutStr stdout . showFFloat (Just 4) (maxE / data2) $ "\t"
hPutStr stdout . showFFloat Nothing ratio $ "\t"
hPutStr stdout ('\t':show (wordsN::Int))
hPutStr stdout ('\t':show (intervalN::Int))
hPutStrLn stdout (if printLine == 1 then '\t':(VB.toList v) else ""))
return myThread) (killThread) (\_ -> putStr "")

fLines :: Int -> String -> [VB.Vector Char]
fLines !toOneLine ys =
let preText = filter (any (\x -> isUkrainianL x && isAlpha x)) . prepareText . (\z -> if toOneLine == 1 then unwords . words $ z else z) $ ys
wss = map (length . subG " 01-") preText
g (t:ts) (r:rs) = if r > 7 then filter (`notElem` "01-") t:g ts rs else t:g ts rs
g _ _ = []
in map VB.fromList . g preText $ wss

fLinesIO :: String -> IO ()
fLinesIO ys =
let preText = filter (any (\x -> isUkrainianL x && isAlpha x)) . prepareText $ ys
wss = map (length . subG " 01-") preText
g (t:ts) (r:rs) = if r > 7 then filter (`notElem` "01-") t:g ts rs else t:g ts rs
g _ _ = []
in VB.mapM_ putStrLn . VB.map (\(i,x) -> show (i + 1) ++ "\t" ++ x) . VB.indexed . VB.fromList . g preText $ wss
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2020 OleksandrZhabenko

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47 changes: 47 additions & 0 deletions Languages/UniquenessPeriods/Vector/FuncRepRelatedG.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- |
-- Module : Languages.UniquenessPeriods.Vector.FuncRepRelatedG
-- Copyright : (c) OleksandrZhabenko 2020
-- License : MIT
-- Stability : Experimental
-- Maintainer : [email protected]
--
-- Functions to choose from the 'FuncRep' variants.

{-# LANGUAGE BangPatterns #-}

module Languages.UniquenessPeriods.Vector.FuncRepRelatedG where

import Data.Maybe (isNothing,fromMaybe)
import Text.Read
import CaseBi (getBFst')
import qualified Data.Vector as VB
import Languages.UniquenessPeriods.Vector.DataG
import String.Languages.UniquenessPeriods.VectorG
import Languages.UniquenessPeriods.Vector.PropertiesFuncRepG
import Languages.UniquenessPeriods.Vector.PropertiesSyllablesG
import Languages.UniquenessPeriods.Vector.PropertiesG

-- | Allows to choose the variant of the computations in case of usual processment.
chooseMax :: Coeffs2 -> String -> FuncRep (VB.Vector Char) (UniquenessGeneral2 Char) [Float]
chooseMax coeffs choice
| isPair coeffs =
let !k2 = fromMaybe 1.0 . fstCF $ coeffs
!k3 = fromMaybe 1.0 . sndCF $ coeffs in getBFst' (procBoth2InvF coeffs, VB.fromList [("02y",procRhythmicity232F "02y" coeffs),
("0y",procRhythmicity23F "0y" coeffs),("y",procBothF coeffs),("y0",procDiverse2F),("y2",procBoth2F coeffs),("yy",procBothInvF coeffs)]) choice
| otherwise = getBFst' (procBoth2InvF coeffs, VB.fromList [("02y",procRhythmicity232F "02y" coeffs),("0y",procRhythmicity23F "0y" coeffs),
("y",procBothF coeffs),("y0",procDiverse2F),("y2",procBoth2F coeffs),("yy",procBothInvF coeffs)]) choice

-- | Allows to choose the variant of the computations in case of minimum lookup. Uses @-neg@ variants.
chooseMin :: Coeffs2 -> String -> FuncRep (VB.Vector Char) (UniquenessGeneral2 Char) [Float]
chooseMin coeffs choice
| isPair coeffs =
let !k2 = fromMaybe 1.0 . fstCF $ coeffs
!k3 = fromMaybe 1.0 . sndCF $ coeffs in getBFst' (procBoth2InvFneg coeffs, VB.fromList [("02y",procRhythmicity232Fneg "02y" coeffs),
("0y",procRhythmicity23Fneg "0y" coeffs),("y",procBothFneg coeffs),("y0",procDiverse2Fneg),("y2",procBoth2Fneg coeffs),
("yy",procBothInvFneg coeffs)]) choice
| otherwise = getBFst' (procBoth2InvFneg coeffs, VB.fromList [("02y",procRhythmicity232Fneg "02y" coeffs),("0y",procRhythmicity23Fneg "0y" coeffs),
("y",procBothFneg coeffs),("y0",procDiverse2Fneg),("y2",procBoth2Fneg coeffs),("yy",procBothInvFneg coeffs)]) choice

-- | Allows to choose precision in the Numeric.showFFloat function being given a choice parameter.
precChoice :: String -> Maybe Int
precChoice = getBFst' (Just 4, VB.fromList [("02y",Just 0),("0y",Just 0),("y",Just 0),("y0",Just 0),("y2",Just 0)])
Loading

0 comments on commit e9de865

Please sign in to comment.