From c08e8435108176438ec74e2226573a03d36d71d6 Mon Sep 17 00:00:00 2001 From: ZhigalskiiIvan <671342i@gmail.com> Date: Fri, 24 Mar 2023 17:34:33 +0300 Subject: [PATCH] added reading choice of output --- src/main/kotlin/Main.kt | 83 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 885288a..cff4efc 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,16 +1,73 @@ import java.io.File import java.util.Scanner import kotlin.system.exitProcess +import org.jetbrains.letsPlot.* +import org.jetbrains.letsPlot.intern.Plot + val scanner = Scanner(System.`in`) object StatisticBuilder { - fun askAndExecuteSelfCommands() {} + val plot: Plot? = null - private fun buildGraphic() {} + fun askAndExecuteSelfCommands() { + + val text = getTextData() ?: return + + var counter = 1 + val wordsCountsMap = text.getSentencesList().map { counter++ to it.getWordsCount() } + + println("Print \"console\" if you have see data in console, \"graphic\" if you have see histogram and \"both\" if you have see them together:") + whenStatShowCycle@ while (true) { + when (readln()) { + "console" -> printStatisticsInConsole(text.getName(), wordsCountsMap.toMap()) + "graphic" -> buildGraphic(text.getName(), wordsCountsMap.toMap()) + "both" -> { + buildGraphic(text.getName(), wordsCountsMap.toMap()) + printStatisticsInConsole(text.getName(), wordsCountsMap.toMap()) + } + + "return" -> return + else -> { + println("Repeat input or enter \"return\" to return in main menu") + continue@whenStatShowCycle + } + } + break@whenStatShowCycle + } + + } + + private fun buildGraphic(textName: String, mapOfSentenceNumToItsSize: Map) { + + } + + private fun printStatisticsInConsole(textName: String, mapOfSentenceNumToItsSize: Map) { + + } + + private fun getTextData(): TextData.Text? { + + println("Input name of text which you have to get statistics about:") + println("Saved texts: ${TextData.getTextsNamesInString()}") + + cycleSearchText@ while (true) { + return when (val name = readln().trim()) { + in TextData.getTextsNamesList() -> { + TextData.getTextByName(name)!! + } + + "return" -> null + else -> { + println("No text with name $name. Repeat input or enter return to return in main menu.") + continue@cycleSearchText + } + } + } + + } - private fun printStatisticsInConsole() {} } @@ -106,6 +163,19 @@ object TextReader { object TextData { private val textsList = mutableListOf() + fun getTextByName(searchingName: String): Text? { + for (text in textsList) if (text.getName() == searchingName) return text + return null + } + + fun getTextsNamesInString(delimiter: String = ", "): String { + return textsList.joinToString(delimiter) { it.getName() } + } + + fun getTextsNamesList(): List { + return textsList.map { it.getName() } + } + fun addNewText(textName: String, content: String) { textsList.add(TextAnalyzer.getTextObjFromContents(textName, content)) } @@ -144,6 +214,11 @@ object TextData { fun getSentencesCount() = sentencesCount fun getName() = name + + fun getSentencesList(): List { + return sentencesList + } + data class Sentence(private val wordsCount: Int) { fun getWordsCount() = wordsCount } @@ -176,8 +251,8 @@ object CommandCenter { } -fun main() { +fun main() { mainCycle@ while (true) { (CommandCenter.readCommandFromConsole())() }