From 39ac71d76d362e4e492051a1ef7ea39447bb5742 Mon Sep 17 00:00:00 2001 From: ZhigalskiiIvan <671342i@gmail.com> Date: Thu, 23 Mar 2023 21:15:28 +0300 Subject: [PATCH 01/11] create classes skeleton --- src/main/kotlin/Main.kt | 63 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index f2a59b6..f48cd29 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,7 +1,60 @@ -fun main(args: Array) { - println("Hello World!") +object StatisticBuilder { - // Try adding program arguments via Run/Debug configuration. - // Learn more about running applications: https://www.jetbrains.com/help/idea/running-applications.html. - println("Program arguments: ${args.joinToString()}") + fun buildGraphic() {} + + fun printStatisticsInConsole() {} + +} + + +object TextReader { + fun readFromConsole(): String { + TODO() + } +} + + +class TextData() { + private val textsList = mutableListOf() + + fun addNewText(textName: String, content: String) {} + + object TextAnalyzer { + private val DELIMITERS = listOf('.', '!', '?') + + fun returnListOfSentences(text: Text): List { TODO() } + + } + + class Text(private val name: String, private val sentencesCount: Int) { + + val sentencesList = listOf() + + fun getSentencesCount() {} + + class Sentence(val words_count: Int) {} + + } + +} + + +object CommandCenter { + + enum class Commands(val commandName: String, val executingFun: (Any) -> Any) { + Exit("exit", TODO()), + Add("add", TODO()) + } + + fun readCommandFromConsole() {} + + fun executeCommand() {} + +} + + +fun main(args: Array) { + + mainCycle@ while (true) { + } } \ No newline at end of file From 67c7a9dc6c5deabfcb569d2f9ec97df1a0f384ac Mon Sep 17 00:00:00 2001 From: ZhigalskiiIvan <671342i@gmail.com> Date: Thu, 23 Mar 2023 22:02:54 +0300 Subject: [PATCH 02/11] command center logic commit --- src/main/kotlin/Main.kt | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index f48cd29..4b72dbb 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,8 @@ +import java.util.Scanner +import kotlin.system.exitProcess + +val scanner = Scanner(System.`in`) + object StatisticBuilder { fun buildGraphic() {} @@ -22,7 +27,9 @@ class TextData() { object TextAnalyzer { private val DELIMITERS = listOf('.', '!', '?') - fun returnListOfSentences(text: Text): List { TODO() } + fun returnListOfSentences(text: Text): List { + TODO() + } } @@ -41,20 +48,35 @@ class TextData() { object CommandCenter { - enum class Commands(val commandName: String, val executingFun: (Any) -> Any) { - Exit("exit", TODO()), - Add("add", TODO()) + private enum class Commands(val executingFun: () -> Unit) { + EXIT({ + println("bye!") + exitProcess(0) + }), + ADD_TEXT({ println("add") }), + SHOW_STATISTICS({ println("sow") }), + REMOVE_TEXT({ println("remove") }) } - fun readCommandFromConsole() {} + fun readCommandFromConsole(): () -> Unit { + println("Input one Of the commands: ${Commands.values().joinToString { it.name.lowercase() }}:") + val funNameInUpCase = scanner.nextLine().uppercase() + + return if (funNameInUpCase in Commands.values().map { it.name }) + Commands.valueOf(funNameInUpCase).executingFun + else ::readCommandFromConsole + } fun executeCommand() {} } -fun main(args: Array) { +fun main() { mainCycle@ while (true) { + + (CommandCenter.readCommandFromConsole())() + } } \ No newline at end of file From 38e29bcd521ee692c323599247b17146b8cf21f9 Mon Sep 17 00:00:00 2001 From: ZhigalskiiIvan <671342i@gmail.com> Date: Thu, 23 Mar 2023 23:01:22 +0300 Subject: [PATCH 03/11] textReader done --- src/main/kotlin/Main.kt | 123 +++++++++++++++++++++++++++++++++------- 1 file changed, 102 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 4b72dbb..c9f8c4a 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,3 +1,4 @@ +import java.io.File import java.util.Scanner import kotlin.system.exitProcess @@ -5,21 +6,115 @@ val scanner = Scanner(System.`in`) object StatisticBuilder { - fun buildGraphic() {} + fun askAndExecuteSelfCommands() {} - fun printStatisticsInConsole() {} + private fun buildGraphic() {} + + private fun printStatisticsInConsole() {} } object TextReader { - fun readFromConsole(): String { - TODO() + fun askAndExecuteSelfCommands() { + + println("Where do you want to add the text: from the console of a file?") + when (readln().lowercase()) { + "console" -> readFromConsole() + "file" -> readFromFile() + "return" -> return + else -> { + println("Repeat input or print \"return\" to return in main menu:") + askAndExecuteSelfCommands() + } + } } + + private fun readFromConsole() { + + println("Input name of a text:") + val name = readln() + + println("Input a text content:") + var content: String = "" + readCycle@ while (true) { + val nextPart = scanner.next() + if (nextPart.isEmpty()) content += nextPart + else break@readCycle + } + + correctInputQuestion@ while (true) { + print("Input was correct?[yes, no]: ") + when (readln()) { + "yes" -> addTextToData(name, content) + "no" -> readFromConsole() + "return" -> return + else -> { + println("Input only \"yes\" or \"no\" or \"return\" if you want to exit in main menu:") + } + } + } + } + + private fun readFromFile() { + + println("Input a name of a text:") + val name = readln() + + val contentsFile: File + pathReadCycle@ while (true) { + println("Input a path to file:") + val filePath = readln() + val testFile = File(filePath) + + when { + filePath == "return" -> return + !testFile.exists() -> { + println("File path incorrect. Repeat input or enter \"return\" to return in main menu:") + continue@pathReadCycle + } + + else -> { + contentsFile = testFile + break@pathReadCycle + } + } + } + val content = contentsFile.readText() + + correctInputQuestion@ while (true) { + print("Input was correct?[yes, no]: ") + when (readln()) { + "yes" -> addTextToData(name, content) + "no" -> readFromFile() + "return" -> return + else -> { + println("Input only \"yes\" or \"no\" or \"return\" if you want to exit in main menu:") + } + } + } + + } + + private fun addTextToData(textName: String, content: String) { + TextData.addNewText(textName, content) + } + } -class TextData() { +data class Text(private val name: String, private val sentencesCount: Int) { + + val sentencesList = listOf() + + fun getSentencesCount() {} + + data class Sentence(val wordsCount: Int) {} + +} + + +object TextData { private val textsList = mutableListOf() fun addNewText(textName: String, content: String) {} @@ -30,17 +125,6 @@ class TextData() { fun returnListOfSentences(text: Text): List { TODO() } - - } - - class Text(private val name: String, private val sentencesCount: Int) { - - val sentencesList = listOf() - - fun getSentencesCount() {} - - class Sentence(val words_count: Int) {} - } } @@ -53,8 +137,8 @@ object CommandCenter { println("bye!") exitProcess(0) }), - ADD_TEXT({ println("add") }), - SHOW_STATISTICS({ println("sow") }), + ADD_TEXT({ TextReader.askAndExecuteSelfCommands() }), + SHOW_STATISTICS({ StatisticBuilder.askAndExecuteSelfCommands() }), REMOVE_TEXT({ println("remove") }) } @@ -67,11 +151,8 @@ object CommandCenter { else ::readCommandFromConsole } - fun executeCommand() {} - } - fun main() { mainCycle@ while (true) { From e89af5f144f90de18db838ae72b6027e299d7fba Mon Sep 17 00:00:00 2001 From: ZhigalskiiIvan <671342i@gmail.com> Date: Fri, 24 Mar 2023 00:16:51 +0300 Subject: [PATCH 04/11] textAnalyser methods done --- src/main/kotlin/Main.kt | 55 ++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index c9f8c4a..885288a 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -103,28 +103,51 @@ object TextReader { } -data class Text(private val name: String, private val sentencesCount: Int) { - - val sentencesList = listOf() - - fun getSentencesCount() {} - - data class Sentence(val wordsCount: Int) {} - -} - - object TextData { private val textsList = mutableListOf() - fun addNewText(textName: String, content: String) {} + fun addNewText(textName: String, content: String) { + textsList.add(TextAnalyzer.getTextObjFromContents(textName, content)) + } object TextAnalyzer { - private val DELIMITERS = listOf('.', '!', '?') + private val DELIMITERS = Regex("([!?.]|(\\.\\.\\.))\\s") + private val WHITESPACES_WITHOUT_SPACE = Regex("(?=\\s+)(?!=\\s)") + + + fun getTextObjFromContents(name: String, content: String): Text { + var sentencesCount = 0 + val listOfSentences = mutableListOf() + + val sentencesStringList = content.split(DELIMITERS).map { it.replace(WHITESPACES_WITHOUT_SPACE, " ") } + for (sentenceText in sentencesStringList) { + val wordsList = sentenceText.split(" ").toMutableList() + wordsList.removeIf { it == "" } + if (wordsList.isNotEmpty()) { + sentencesCount++ + listOfSentences.add(Text.Sentence(wordsList.size)) + } + } + println(sentencesStringList) + + return Text(name, sentencesCount, listOfSentences.toList()) - fun returnListOfSentences(text: Text): List { - TODO() } + + } + + data class Text( + private val name: String, + private val sentencesCount: Int, + private val sentencesList: List, + ) { + + fun getSentencesCount() = sentencesCount + fun getName() = name + data class Sentence(private val wordsCount: Int) { + fun getWordsCount() = wordsCount + } + } } @@ -156,8 +179,6 @@ object CommandCenter { fun main() { mainCycle@ while (true) { - (CommandCenter.readCommandFromConsole())() - } } \ No newline at end of file From b10e1abf09f41d8dae84e8059fb75ece1fc4f33e Mon Sep 17 00:00:00 2001 From: ZhigalskiiIvan <671342i@gmail.com> Date: Fri, 24 Mar 2023 17:33:13 +0300 Subject: [PATCH 05/11] added lib for graphics --- .idea/gradle.xml | 1 + build.gradle | 1 + lib/base-portable-2.4.0-sources.jar | Bin 0 -> 175515 bytes lib/base-portable-2.4.0-sources1.jar | Bin 0 -> 175515 bytes lib/base-portable-2.4.0.jar | Bin 0 -> 57665 bytes lib/base-portable-2.4.01.jar | Bin 0 -> 57665 bytes lib/kotlin-stdlib-common-1.6.21-sources.jar | Bin 0 -> 298256 bytes lib/kotlin-stdlib-common-1.6.21-sources1.jar | Bin 0 -> 298256 bytes lib/kotlin-stdlib-common-1.6.21.jar | Bin 0 -> 200631 bytes lib/kotlin-stdlib-common-1.6.211.jar | Bin 0 -> 200631 bytes lib/lets-plot-kotlin-4.0.0-sources.jar | Bin 0 -> 258272 bytes lib/lets-plot-kotlin-4.0.0-sources1.jar | Bin 0 -> 258272 bytes lib/lets-plot-kotlin-4.0.0.jar | Bin 0 -> 54537 bytes lib/lets-plot-kotlin-4.0.01.jar | Bin 0 -> 54537 bytes lib/plot-base-portable-2.4.0-sources.jar | Bin 0 -> 338367 bytes lib/plot-base-portable-2.4.0-sources1.jar | Bin 0 -> 338367 bytes lib/plot-base-portable-2.4.0.jar | Bin 0 -> 72195 bytes lib/plot-base-portable-2.4.01.jar | Bin 0 -> 72195 bytes lib/plot-builder-portable-2.4.0-sources.jar | Bin 0 -> 297967 bytes lib/plot-builder-portable-2.4.0-sources1.jar | Bin 0 -> 297967 bytes lib/plot-builder-portable-2.4.0.jar | Bin 0 -> 78259 bytes lib/plot-builder-portable-2.4.01.jar | Bin 0 -> 78259 bytes lib/plot-common-portable-2.4.0-sources.jar | Bin 0 -> 43671 bytes lib/plot-common-portable-2.4.0-sources1.jar | Bin 0 -> 43671 bytes lib/plot-common-portable-2.4.0.jar | Bin 0 -> 15918 bytes lib/plot-common-portable-2.4.01.jar | Bin 0 -> 15918 bytes lib/plot-config-portable-2.4.0-sources.jar | Bin 0 -> 202991 bytes lib/plot-config-portable-2.4.0-sources1.jar | Bin 0 -> 202991 bytes lib/plot-config-portable-2.4.0.jar | Bin 0 -> 44496 bytes lib/plot-config-portable-2.4.01.jar | Bin 0 -> 44496 bytes 30 files changed, 2 insertions(+) create mode 100644 lib/base-portable-2.4.0-sources.jar create mode 100644 lib/base-portable-2.4.0-sources1.jar create mode 100644 lib/base-portable-2.4.0.jar create mode 100644 lib/base-portable-2.4.01.jar create mode 100644 lib/kotlin-stdlib-common-1.6.21-sources.jar create mode 100644 lib/kotlin-stdlib-common-1.6.21-sources1.jar create mode 100644 lib/kotlin-stdlib-common-1.6.21.jar create mode 100644 lib/kotlin-stdlib-common-1.6.211.jar create mode 100644 lib/lets-plot-kotlin-4.0.0-sources.jar create mode 100644 lib/lets-plot-kotlin-4.0.0-sources1.jar create mode 100644 lib/lets-plot-kotlin-4.0.0.jar create mode 100644 lib/lets-plot-kotlin-4.0.01.jar create mode 100644 lib/plot-base-portable-2.4.0-sources.jar create mode 100644 lib/plot-base-portable-2.4.0-sources1.jar create mode 100644 lib/plot-base-portable-2.4.0.jar create mode 100644 lib/plot-base-portable-2.4.01.jar create mode 100644 lib/plot-builder-portable-2.4.0-sources.jar create mode 100644 lib/plot-builder-portable-2.4.0-sources1.jar create mode 100644 lib/plot-builder-portable-2.4.0.jar create mode 100644 lib/plot-builder-portable-2.4.01.jar create mode 100644 lib/plot-common-portable-2.4.0-sources.jar create mode 100644 lib/plot-common-portable-2.4.0-sources1.jar create mode 100644 lib/plot-common-portable-2.4.0.jar create mode 100644 lib/plot-common-portable-2.4.01.jar create mode 100644 lib/plot-config-portable-2.4.0-sources.jar create mode 100644 lib/plot-config-portable-2.4.0-sources1.jar create mode 100644 lib/plot-config-portable-2.4.0.jar create mode 100644 lib/plot-config-portable-2.4.01.jar diff --git a/.idea/gradle.xml b/.idea/gradle.xml index f9163b4..ce1c62c 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,5 +1,6 @@ +