mirror of
https://github.com/ZhigalskiiIvan/TextStatisticsProject.git
synced 2025-01-09 04:51:52 +03:00
Compare commits
No commits in common. "a8b42a7d42086da8aa3e21f9c8265efee073bba2" and "0bc2c199d6893269286ae1abf0660c8216df2cf2" have entirely different histories.
a8b42a7d42
...
0bc2c199d6
@ -8,17 +8,11 @@ version = '1.0-SNAPSHOT'
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.jetbrains.lets-plot:lets-plot-kotlin:4.0.0")
|
implementation("org.jetbrains.lets-plot:lets-plot-kotlin:4.0.0")
|
||||||
implementation("org.jetbrains.lets-plot:lets-plot-batik:3.1.0")
|
|
||||||
implementation("org.jetbrains.lets-plot:lets-plot-jfx:3.1.0")
|
|
||||||
implementation("org.slf4j:slf4j-nop:1.7.29")
|
|
||||||
implementation("org.jetbrains.lets-plot:lets-plot-image-export:3.1.0")
|
|
||||||
testImplementation 'org.jetbrains.kotlin:kotlin-test'
|
testImplementation 'org.jetbrains.kotlin:kotlin-test'
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
BIN
lib/base-portable-2.4.0-sources.jar
Normal file
BIN
lib/base-portable-2.4.0-sources.jar
Normal file
Binary file not shown.
BIN
lib/base-portable-2.4.0-sources1.jar
Normal file
BIN
lib/base-portable-2.4.0-sources1.jar
Normal file
Binary file not shown.
BIN
lib/base-portable-2.4.0.jar
Normal file
BIN
lib/base-portable-2.4.0.jar
Normal file
Binary file not shown.
BIN
lib/base-portable-2.4.01.jar
Normal file
BIN
lib/base-portable-2.4.01.jar
Normal file
Binary file not shown.
BIN
lib/kotlin-stdlib-common-1.6.21-sources.jar
Normal file
BIN
lib/kotlin-stdlib-common-1.6.21-sources.jar
Normal file
Binary file not shown.
BIN
lib/kotlin-stdlib-common-1.6.21-sources1.jar
Normal file
BIN
lib/kotlin-stdlib-common-1.6.21-sources1.jar
Normal file
Binary file not shown.
BIN
lib/kotlin-stdlib-common-1.6.21.jar
Normal file
BIN
lib/kotlin-stdlib-common-1.6.21.jar
Normal file
Binary file not shown.
BIN
lib/kotlin-stdlib-common-1.6.211.jar
Normal file
BIN
lib/kotlin-stdlib-common-1.6.211.jar
Normal file
Binary file not shown.
BIN
lib/lets-plot-kotlin-4.0.0-sources.jar
Normal file
BIN
lib/lets-plot-kotlin-4.0.0-sources.jar
Normal file
Binary file not shown.
BIN
lib/lets-plot-kotlin-4.0.0-sources1.jar
Normal file
BIN
lib/lets-plot-kotlin-4.0.0-sources1.jar
Normal file
Binary file not shown.
BIN
lib/lets-plot-kotlin-4.0.0.jar
Normal file
BIN
lib/lets-plot-kotlin-4.0.0.jar
Normal file
Binary file not shown.
BIN
lib/lets-plot-kotlin-4.0.01.jar
Normal file
BIN
lib/lets-plot-kotlin-4.0.01.jar
Normal file
Binary file not shown.
BIN
lib/plot-base-portable-2.4.0-sources.jar
Normal file
BIN
lib/plot-base-portable-2.4.0-sources.jar
Normal file
Binary file not shown.
BIN
lib/plot-base-portable-2.4.0-sources1.jar
Normal file
BIN
lib/plot-base-portable-2.4.0-sources1.jar
Normal file
Binary file not shown.
BIN
lib/plot-base-portable-2.4.0.jar
Normal file
BIN
lib/plot-base-portable-2.4.0.jar
Normal file
Binary file not shown.
BIN
lib/plot-base-portable-2.4.01.jar
Normal file
BIN
lib/plot-base-portable-2.4.01.jar
Normal file
Binary file not shown.
BIN
lib/plot-builder-portable-2.4.0-sources.jar
Normal file
BIN
lib/plot-builder-portable-2.4.0-sources.jar
Normal file
Binary file not shown.
BIN
lib/plot-builder-portable-2.4.0-sources1.jar
Normal file
BIN
lib/plot-builder-portable-2.4.0-sources1.jar
Normal file
Binary file not shown.
BIN
lib/plot-builder-portable-2.4.0.jar
Normal file
BIN
lib/plot-builder-portable-2.4.0.jar
Normal file
Binary file not shown.
BIN
lib/plot-builder-portable-2.4.01.jar
Normal file
BIN
lib/plot-builder-portable-2.4.01.jar
Normal file
Binary file not shown.
BIN
lib/plot-common-portable-2.4.0-sources.jar
Normal file
BIN
lib/plot-common-portable-2.4.0-sources.jar
Normal file
Binary file not shown.
BIN
lib/plot-common-portable-2.4.0-sources1.jar
Normal file
BIN
lib/plot-common-portable-2.4.0-sources1.jar
Normal file
Binary file not shown.
BIN
lib/plot-common-portable-2.4.0.jar
Normal file
BIN
lib/plot-common-portable-2.4.0.jar
Normal file
Binary file not shown.
BIN
lib/plot-common-portable-2.4.01.jar
Normal file
BIN
lib/plot-common-portable-2.4.01.jar
Normal file
Binary file not shown.
BIN
lib/plot-config-portable-2.4.0-sources.jar
Normal file
BIN
lib/plot-config-portable-2.4.0-sources.jar
Normal file
Binary file not shown.
BIN
lib/plot-config-portable-2.4.0-sources1.jar
Normal file
BIN
lib/plot-config-portable-2.4.0-sources1.jar
Normal file
Binary file not shown.
BIN
lib/plot-config-portable-2.4.0.jar
Normal file
BIN
lib/plot-config-portable-2.4.0.jar
Normal file
Binary file not shown.
BIN
lib/plot-config-portable-2.4.01.jar
Normal file
BIN
lib/plot-config-portable-2.4.01.jar
Normal file
Binary file not shown.
@ -1,12 +1,12 @@
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
import org.jetbrains.letsPlot.*
|
import org.jetbrains.letsPlot.*
|
||||||
import org.jetbrains.letsPlot.export.ggsave
|
import org.jetbrains.letsPlot.geom.geomBar
|
||||||
import org.jetbrains.letsPlot.geom.*
|
import org.jetbrains.letsPlot.intern.Plot
|
||||||
import kotlin.reflect.typeOf
|
import kotlin.reflect.typeOf
|
||||||
|
|
||||||
|
|
||||||
/** Gives statistics of saved texts.
|
/** Singleton object which gives statistics of saved texts.
|
||||||
*/
|
*/
|
||||||
class StatisticBuilder {
|
class StatisticBuilder {
|
||||||
|
|
||||||
@ -36,44 +36,32 @@ class StatisticBuilder {
|
|||||||
"console" -> printStatisticsInConsole(text.getName(), wordsCountsMap.toMap())
|
"console" -> printStatisticsInConsole(text.getName(), wordsCountsMap.toMap())
|
||||||
"graphic" -> buildGraphic(text.getName(), wordsCountsMap.toMap())
|
"graphic" -> buildGraphic(text.getName(), wordsCountsMap.toMap())
|
||||||
"both" -> {
|
"both" -> {
|
||||||
printStatisticsInConsole(text.getName(), wordsCountsMap.toMap())
|
|
||||||
buildGraphic(text.getName(), wordsCountsMap.toMap())
|
buildGraphic(text.getName(), wordsCountsMap.toMap())
|
||||||
|
printStatisticsInConsole(text.getName(), wordsCountsMap.toMap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Builds bar chart with data of mapOfSentenceNumToItsSize and saves image in file.
|
/** It builds bar chart with data of mapOfSentenceNumToItsSize.
|
||||||
* @param textName name of texts, which user want to see statistics about.
|
* textName: name of texts, which user want to see statistics about.
|
||||||
* @param mapOfSentenceNumToItsSize map of pairs of sentence numbers and their words count.
|
* mapOfSentenceNumToItsSize: map of pairs of sentence numbers and their words count.
|
||||||
*/
|
*/
|
||||||
private fun buildGraphic(textName: String, mapOfSentenceNumToItsSize: Map<Int, Int>) {
|
private fun buildGraphic(textName: String, mapOfSentenceNumToItsSize: Map<Int, Int>) {
|
||||||
|
|
||||||
val data = mapOf(
|
val plot: Plot =
|
||||||
"words count" to mapOfSentenceNumToItsSize.map { it.value.toFloat() / mapOfSentenceNumToItsSize.size },
|
ggplot(mapOfSentenceNumToItsSize) + ggsize(1000, 600) + geomBar { x = "sentence number"; y = "words count" }
|
||||||
)
|
|
||||||
|
|
||||||
val fig = ggplot(data) +
|
TODO("вил би сун")
|
||||||
geomBar(
|
|
||||||
color = "white",
|
|
||||||
fill = "red"
|
|
||||||
) { x = "words count" } +
|
|
||||||
geomArea(
|
|
||||||
stat = Stat.density(),
|
|
||||||
color = "white",
|
|
||||||
fill = "pink",
|
|
||||||
alpha = 0.4
|
|
||||||
) { x = "words count" } +
|
|
||||||
ggsize(1400, 800)
|
|
||||||
|
|
||||||
println("Graphic was save in ${ggsave(fig, "$textName.png")}")
|
|
||||||
fig.show()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints statistics according to data from mapOfSentenceNumToItsSize.
|
/**
|
||||||
* @param textName name of texts, which user want to see statistics about.
|
* Prints statistics according to data from mapOfSentenceNumToItsSize.
|
||||||
* @param mapOfSentenceNumToItsSize map of pairs of sentence numbers and their words count.
|
*
|
||||||
|
* textName: name of texts, which user want to see statistics about.
|
||||||
|
* mapOfSentenceNumToItsSize: map of pairs of sentence numbers and their words count.
|
||||||
*/
|
*/
|
||||||
private fun printStatisticsInConsole(textName: String, mapOfSentenceNumToItsSize: Map<Int, Int>) {
|
private fun printStatisticsInConsole(textName: String, mapOfSentenceNumToItsSize: Map<Int, Int>) {
|
||||||
|
|
||||||
@ -106,11 +94,12 @@ class StatisticBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Used for reading text from a file or console. */
|
/** Singleton object used for reading text from a file or console. */
|
||||||
class TextReader {
|
class TextReader {
|
||||||
|
|
||||||
/** Asks the user which where they want to read the text from and
|
/**
|
||||||
* calls special for file- and console- reading methods according the answer.
|
* Asks the user which where they want to read the text from and
|
||||||
|
* calls special for file- and console- reading methods according the answer.
|
||||||
*/
|
*/
|
||||||
fun readNewText(textData: TextData) {
|
fun readNewText(textData: TextData) {
|
||||||
|
|
||||||
@ -127,8 +116,8 @@ class TextReader {
|
|||||||
|
|
||||||
|
|
||||||
/** Read from console the name of text, checks that it hasn't saved yet and its contents,
|
/** Read from console the name of text, checks that it hasn't saved yet and its contents,
|
||||||
* asks if entered text is not correct and re-calls itself or
|
* asks if entered text is not correct and re-calls itself or
|
||||||
* calls method of adding received text to data.
|
* calls method of adding received text to data.
|
||||||
*/
|
*/
|
||||||
private fun readFromConsole(textData: TextData) {
|
private fun readFromConsole(textData: TextData) {
|
||||||
|
|
||||||
@ -166,10 +155,11 @@ class TextReader {
|
|||||||
else readFromConsole(textData)
|
else readFromConsole(textData)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asks for the name of text, path to file to read text from,
|
/**
|
||||||
* checks for its existing, reads contents and,
|
* Asks for the name of text, path to file to read text from,
|
||||||
* asks if entered names is not correct and re-calls itself or
|
* checks for its existing, reads contents and,
|
||||||
* calls method of adding received text to data.
|
* asks if entered names is not correct and re-calls itself or
|
||||||
|
* calls method of adding received text to data.
|
||||||
*/
|
*/
|
||||||
private fun readFromFile(textData: TextData) {
|
private fun readFromFile(textData: TextData) {
|
||||||
|
|
||||||
@ -218,8 +208,8 @@ class TextReader {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Stores data about tracking texts,
|
/** Object used for storing data about tracking texts,
|
||||||
* includes methods for work with them due the adding.
|
* includes methods for work with them.
|
||||||
*/
|
*/
|
||||||
class TextData {
|
class TextData {
|
||||||
|
|
||||||
@ -246,10 +236,11 @@ class TextData {
|
|||||||
println("Text ${removingText.getName()} removed.")
|
println("Text ${removingText.getName()} removed.")
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns Text object whose name matches searchingName or null
|
/**
|
||||||
* if there is no text with same name in the textsList.
|
* Returns Text object whose name matches searchingName or null
|
||||||
* @param searchingName name of the text to be found.
|
* if there is no text with same name in the textsList.
|
||||||
* @return the text with searchingName name or null.
|
* searchingName: name of the text to be found.
|
||||||
|
* return: the text with searchingName name or null.
|
||||||
*/
|
*/
|
||||||
private fun getTextByName(searchingName: String): Text? {
|
private fun getTextByName(searchingName: String): Text? {
|
||||||
|
|
||||||
@ -281,7 +272,7 @@ class TextData {
|
|||||||
* Reads name of the text to be found and returns it text if
|
* Reads name of the text to be found and returns it text if
|
||||||
* it exists.
|
* it exists.
|
||||||
* @param message message which prints with calling this method.
|
* @param message message which prints with calling this method.
|
||||||
* @return Text type object
|
* @return text
|
||||||
*/
|
*/
|
||||||
fun getTextData(message: String = "Input name of a text"): Text {
|
fun getTextData(message: String = "Input name of a text"): Text {
|
||||||
|
|
||||||
@ -360,24 +351,28 @@ fun exit(): Nothing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Reads commands from the console and storing data about
|
/** Singleton used for reading commands from console and storing data about
|
||||||
* the functions they should execute.
|
* the functions they should execute.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CommandCenter(
|
class CommandCenter(
|
||||||
private val textData: TextData,
|
private val textData: TextData,
|
||||||
private val textReader: TextReader,
|
private val textReader: TextReader,
|
||||||
private val statisticBuilder: StatisticBuilder
|
private val statisticBuilder: StatisticBuilder
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|
||||||
private val exitCommand = Command("exit", ::exit)
|
private val exitCommand = Command("exit", ::exit)
|
||||||
private val addCommand = Command("add text") { textReader.readNewText(textData) }
|
private val addCommand = Command("add text") { textReader.readNewText(textData) }
|
||||||
private val showStatisticsCommand = Command("show statistics") { statisticBuilder.getStatistics(textData) }
|
private val showStatisticsCommand = Command("show statistics") { statisticBuilder.getStatistics(textData) }
|
||||||
private val removeTextCommand = Command("remove text") { textData.removeText() }
|
private val removeTextCommand = Command("Remove text") { textData.removeText() }
|
||||||
|
|
||||||
private val commandsList = listOf(exitCommand, addCommand, showStatisticsCommand, removeTextCommand)
|
private val commandsList = listOf(exitCommand, addCommand, showStatisticsCommand, removeTextCommand)
|
||||||
private val commandsNames = commandsList.map { it.name }
|
val commandsNames = commandsList.map { it.name }
|
||||||
|
|
||||||
/** Stores command and its name */
|
/** Enumerating of available commands names and functions conjugated
|
||||||
|
* with them.
|
||||||
|
*/
|
||||||
class Command(val name: String, val executingFun: () -> Unit)
|
class Command(val name: String, val executingFun: () -> Unit)
|
||||||
|
|
||||||
/** Prints list of names of available commands, requests the name and
|
/** Prints list of names of available commands, requests the name and
|
||||||
@ -397,6 +392,32 @@ class CommandCenter(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Interface used to existing commands objects, whose exe value
|
||||||
|
* stores function which calls after request due the program.
|
||||||
|
*/
|
||||||
|
interface InputOutcomeCommand {
|
||||||
|
/** Function returned in a Main.requestInput method for returned to
|
||||||
|
* main menu of application or continuation of the process.
|
||||||
|
*/
|
||||||
|
val exe: () -> Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
/** If called exe of this object, program continue executing
|
||||||
|
* without changes.
|
||||||
|
*/
|
||||||
|
class ContinueCommand : InputOutcomeCommand {
|
||||||
|
override val exe: () -> Unit = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If called exe of this object, a custom ReturnException is thrown
|
||||||
|
* and process of executing some called command interrupted. Exception
|
||||||
|
* catches in mainCycle and program command request is repeated.
|
||||||
|
*/
|
||||||
|
class ReturnCommand : InputOutcomeCommand {
|
||||||
|
override val exe: () -> Unit = throw ReturnException()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Custom exception being thrown if user want to return to the menu. */
|
/** Custom exception being thrown if user want to return to the menu. */
|
||||||
class ReturnException : Exception()
|
class ReturnException : Exception()
|
||||||
@ -412,7 +433,7 @@ class InvalidInputTypeException : Exception()
|
|||||||
class InvalidElemInInputException : Exception()
|
class InvalidElemInInputException : Exception()
|
||||||
|
|
||||||
|
|
||||||
/** Function repeating the process of calling functions returned by
|
/** Method repeating the process of calling functions returned by
|
||||||
* CommandCenter. If ReturnException was thrown, it is caught here,
|
* CommandCenter. If ReturnException was thrown, it is caught here,
|
||||||
* last iteration breaks and new one is called.
|
* last iteration breaks and new one is called.
|
||||||
*/
|
*/
|
||||||
@ -428,7 +449,7 @@ fun workCycle(commandCenter: CommandCenter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Function reads from console input, check if it isn't available, repeat the request from the console
|
/** Method reads from console input, check if it isn't available, repeat the request from the console
|
||||||
* in this case and convert input in type T if possible, else throws an exception and repeat the
|
* in this case and convert input in type T if possible, else throws an exception and repeat the
|
||||||
* request.
|
* request.
|
||||||
*
|
*
|
||||||
@ -451,6 +472,7 @@ inline fun <reified T> requestInput(
|
|||||||
if (input == "return") return Pair(ReturnCommand(), "")
|
if (input == "return") return Pair(ReturnCommand(), "")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// inputT = input to typeOf<T>()
|
||||||
inputT = when (typeOf<T>()) {
|
inputT = when (typeOf<T>()) {
|
||||||
typeOf<Int>() -> input.toInt()
|
typeOf<Int>() -> input.toInt()
|
||||||
typeOf<Double>() -> input.toDouble()
|
typeOf<Double>() -> input.toDouble()
|
||||||
@ -501,36 +523,9 @@ inline fun <reified T> requestInput(
|
|||||||
continue@readingAndChangingTypeCycle
|
continue@readingAndChangingTypeCycle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Interface used to existing commands objects, whose exe value
|
|
||||||
* stores function which calls after requesting from console in
|
|
||||||
* requestInput function.
|
|
||||||
*/
|
|
||||||
interface InputOutcomeCommand {
|
|
||||||
/** Function returned in a Main.requestInput method for returned to
|
|
||||||
* main menu of application or continuation of the process.
|
|
||||||
*/
|
|
||||||
val exe: () -> Unit
|
|
||||||
}
|
|
||||||
|
|
||||||
/** If called exe of this object, program continue executing
|
|
||||||
* without changes.
|
|
||||||
*/
|
|
||||||
class ContinueCommand : InputOutcomeCommand {
|
|
||||||
override val exe: () -> Unit = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** If called exe of this object, a custom ReturnException is thrown
|
|
||||||
* and process of executing some called command interrupted. Exception
|
|
||||||
* catches in mainCycle and program command request is repeated.
|
|
||||||
*/
|
|
||||||
class ReturnCommand : InputOutcomeCommand {
|
|
||||||
override val exe: () -> Unit = throw ReturnException()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
|
|
||||||
val textData = TextData()
|
val textData = TextData()
|
||||||
|
Loading…
Reference in New Issue
Block a user