-- |
-- Module : Main
-- Copyright : (c) OleksandrZhabenko 2020
-- License : MIT
-- Stability : Experimental
-- Maintainer : olexandr543@yahoo.com
--
-- Prints the rearrangements with the \"property\" information for the Ukrainian language text.
{-# OPTIONS_GHC -threaded -rtsopts #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import Phonetic.Languages.Array.Ukrainian.PropertiesSyllablesG2
import System.Environment (getArgs)
import Phonetic.Languages.Simple
import Interpreter.StringConversion (readFileIfAny)
import Data.Maybe (fromMaybe)
import Text.Read (readMaybe)
-- | Prints the rearrangements with the \"property\" information for the Ukrainian language text. The first command line argument must be a
-- positive 'Int' number and is a number of printed variants for the line (if they are present, otherwise just all possible variants are printed).
-- The second one is the number of the intervals into which the all range of possible metrics values are divided. The next numeric arguments that must be
-- sequenced without interruptions further are treated as the numbers of the intervals (counting is started from 1) which values are moved to the maximum
-- values of the metrics interval using the 'unsafeSwapVecIWithMaxI' function. The first textual command line argument should be in the form either \"y0\",
-- or \"0y\", or \"yy\", or \"y\", or \"02y\", or \"y2\", or \"03y\", or \"yy2\", or \"y3\", or some other variant and specifies, which property or properties is or are evaluated.
-- The rest of the command line arguments is the Ukrainian text. Besides, you can use multiple metrices (no more than 5 different ones) together by
-- using \"+m\" ... \"-m\" command line arguments.
--
-- You can specify constraints according to the 'decodeLConstraints' function between +a and -a command line arguments. If so, the program will
-- ask you additional question before proceeding. The \"+m\" ... \"-m\" and \"+a\" ... \"-a\" groups must not mutually intersect one another.
main :: IO ()
main = do
args0000 <- getArgs
let args000 = filter (not . null) (takeWhile (\xs -> take 2 xs /= "*t") args0000 `mappend` (drop 1 . dropWhile (\xs -> take 2 xs /= "^t") $ args0000))
textProcessmentFssFs = drop 1 . dropWhile (\xs -> take 2 xs /= "*t") . takeWhile (\xs -> take 2 xs /= "^t") $ args0000
textProcessment0 = concat . filter (\xs -> take 2 xs == "*t") $ args0000
textProcessment1 = fromMaybe 70 (readMaybe (drop 2 textProcessment0)::Maybe Int)
args00 = filter (/= "+r") args000
recursiveMode = any (== "+r") args000 -- Specifies whether to use the interactive recursive mode
args0 = filter (\xs -> take 2 xs /= "+x" && xs /= "+b" && xs /= "+l" && xs /= "+bl" && xs /= "+i" && xs /= "+u") args00
lstW = if any (\x -> x == "+b" || x == "+bl") args00 then True else False -- If one of the command line options is \"+b\" or \"+bl\" then the last word of the line will remain the last one.
jstL0 = if any (\x -> x == "+l" || x == "+bl") args00 then True else False -- If one of the command line options is \"+l\" or \"+bl\" then the program outputs just lines without metrices values.
nativeUkrainian = if any (== "+u") args00 then True else False -- If one of the command line options is \"+u\" then the informational messages are printed in Ukrainian, otherwise (the default behaviour) they are in English.
toFileMode1 = concat . take 1 . drop 1 . dropWhile (/= "+f") $ args0 -- Prints the last resulting line of the interactive mode processment (the last selected variant) to the file and also to the stdout.
interactiveP = recursiveMode || if any (\xs -> xs == "+i" || xs == "+f") args00 then True else False -- If one of the command line options is \"+i\", or \"+f\" then the program prints the variants and then prompts for the preferred variant. Afterwards, it prints just that variant alone.
args01 = takeWhile (/= "+a") args0 `mappend` (drop 1 . dropWhile (/= "-a") $ args0)
args02
| null toFileMode1 = filter (/= "+f") args01
| otherwise = let (krs,lrs) = break (== "+f") args01
mrs = drop 2 lrs in krs `mappend` mrs
args = takeWhile (/= "+m") args02 `mappend` (drop 1 . dropWhile (/= "-m") $ args02)
coeffs = readCF . concat . take 1 $ args -- The first command line argument.
coeffsWX = readCF . drop 2 . concat . take 1 . filter (\xs -> take 2 xs == "+x") $ args00 -- The command line argument that starts with \"+x\".
textProcessmentFss0 <- mapM (readFileIfAny) textProcessmentFssFs
let textProcessmentFss = filter (not . null) textProcessmentFss0
if isPair coeffs then generalProc3G textProcessmentFss textProcessment0 textProcessment1 recursiveMode nativeUkrainian toFileMode1 interactiveP jstL0 args0 coeffs coeffsWX (drop 1 args) lstW
else generalProc3G textProcessmentFss textProcessment0 textProcessment1 recursiveMode nativeUkrainian toFileMode1 interactiveP jstL0 args0 coeffs coeffsWX args lstW