packages feed

phonetic-languages-simplified-examples-array-0.13.0.0: GetInfo/Main.hs

-- |
-- Module      :  Main
-- Copyright   :  (c) OleksandrZhabenko 2020-2021
-- License     :  MIT
-- Stability   :  Experimental
-- Maintainer  :  olexandr543@yahoo.com
--
-- 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 @propertiesTextG3@ executable with
-- @+RTS -threaded -RTS@ command line options with possibly @-N@ option inside.
--

{-# OPTIONS_GHC -threaded -rtsopts #-}

{-# LANGUAGE BangPatterns, FlexibleContexts #-}

module Main where

import Phonetic.Languages.GetTextualInfo
import Data.Maybe (fromMaybe)
import Text.Read (readMaybe)
import System.Environment (getArgs)
import Data.Monoid (mappend)
import Phonetic.Languages.Common
import Phonetic.Languages.Array.Ukrainian.PropertiesSyllablesG2
import Languages.UniquenessPeriods.Array.Constraints.Encoded

main :: IO ()
main = do
 args50 <- getArgs
 let !args0000 = filter (/= "+p") . (\xss -> takeWhile (/= "+d") xss `mappend` drop 2 (takeWhile (/= "+d") xss)) $ args50
     !pairwisePermutations = any (== "+p") args50
     !fileDu = concat . drop 1 . take 2 . dropWhile (/= "+d") $ args50
     !args000 = filter (\ts -> take 2 ts /= "+x" && take 2 ts /= "+g") args0000
     !growing = filter ((== "+g") . (take 2)) args0000
     (!gr1,!gr2)
            | null growing = (0,0)
            | otherwise = let (nms,mms) = splitAt 1 . drop 2 . take 4 $ growing
                              nm = readMaybe (concat nms)::Maybe Int
                              mm = readMaybe (concat mms)::Maybe Int in case (nm,mm) of
                                  (Just n4,Just m4) -> if (m4 `rem` 7) < (n4 `rem` 7) then (n4 `rem` 7 + 1, m4 `rem` 7 + 1) else (0,0)
                                  _ -> (0,0)
     !coeffsWX = readCF . drop 2 . concat . take 1 . filter (\xs -> take 2 xs == "+x") $ args0000 -- The command line argument that starts with \"+x\".
     !args00 = filter (/= "+b") args000
     !lstW = any (== "+b") args000
     !args0 = takeWhile (/= "+m") args00 `mappend` drop 1 (dropWhile (/= "-m") args00)
     !multiples = drop 1 . dropWhile (/= "+m") . takeWhile (/= "-m") $ args00 -- Arguments for multiple metrices mode
     !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 fileDu pairwisePermutations (gr1,gr2) lstW multiples lInes coeffs coeffsWX file gzS printLine toOneLine choice
  else do
   contents <- readFile file
   fLinesNIO (if pairwisePermutations then 10 else 7) 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 fileDu pairwisePermutations (gr1,gr2) lstW multiples lInes coeffs coeffsWX file gzS printLine toOneLine choice
  else do
   contents <- readFile file
   fLinesNIO (if pairwisePermutations then 10 else 7) contents