mirror of
https://github.com/ZhigalskiiIvan/TextStatisticsProject.git
synced 2024-11-10 02:01: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 {
|
||||
mavenCentral()
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
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'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
||||
}
|
||||
|
||||
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 kotlin.system.exitProcess
|
||||
import org.jetbrains.letsPlot.*
|
||||
import org.jetbrains.letsPlot.export.ggsave
|
||||
import org.jetbrains.letsPlot.geom.*
|
||||
import org.jetbrains.letsPlot.geom.geomBar
|
||||
import org.jetbrains.letsPlot.intern.Plot
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
|
||||
/** Gives statistics of saved texts.
|
||||
/** Singleton object which gives statistics of saved texts.
|
||||
*/
|
||||
class StatisticBuilder {
|
||||
|
||||
@ -36,44 +36,32 @@ class StatisticBuilder {
|
||||
"console" -> printStatisticsInConsole(text.getName(), wordsCountsMap.toMap())
|
||||
"graphic" -> buildGraphic(text.getName(), wordsCountsMap.toMap())
|
||||
"both" -> {
|
||||
printStatisticsInConsole(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.
|
||||
* @param textName name of texts, which user want to see statistics about.
|
||||
* @param mapOfSentenceNumToItsSize map of pairs of sentence numbers and their words count.
|
||||
/** It builds bar chart with data of mapOfSentenceNumToItsSize.
|
||||
* textName: name of texts, which user want to see statistics about.
|
||||
* mapOfSentenceNumToItsSize: map of pairs of sentence numbers and their words count.
|
||||
*/
|
||||
private fun buildGraphic(textName: String, mapOfSentenceNumToItsSize: Map<Int, Int>) {
|
||||
|
||||
val data = mapOf(
|
||||
"words count" to mapOfSentenceNumToItsSize.map { it.value.toFloat() / mapOfSentenceNumToItsSize.size },
|
||||
)
|
||||
val plot: Plot =
|
||||
ggplot(mapOfSentenceNumToItsSize) + ggsize(1000, 600) + geomBar { x = "sentence number"; y = "words count" }
|
||||
|
||||
val fig = ggplot(data) +
|
||||
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()
|
||||
TODO("вил би сун")
|
||||
|
||||
}
|
||||
|
||||
/** Prints statistics according to data from mapOfSentenceNumToItsSize.
|
||||
* @param textName name of texts, which user want to see statistics about.
|
||||
* @param mapOfSentenceNumToItsSize map of pairs of sentence numbers and their words count.
|
||||
/**
|
||||
* Prints statistics according to data from mapOfSentenceNumToItsSize.
|
||||
*
|
||||
* 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>) {
|
||||
|
||||
@ -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 {
|
||||
|
||||
/** 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) {
|
||||
|
||||
@ -127,8 +116,8 @@ class TextReader {
|
||||
|
||||
|
||||
/** 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
|
||||
* calls method of adding received text to data.
|
||||
* asks if entered text is not correct and re-calls itself or
|
||||
* calls method of adding received text to data.
|
||||
*/
|
||||
private fun readFromConsole(textData: TextData) {
|
||||
|
||||
@ -166,10 +155,11 @@ class TextReader {
|
||||
else readFromConsole(textData)
|
||||
}
|
||||
|
||||
/** Asks for the name of text, path to file to read text from,
|
||||
* checks for its existing, reads contents and,
|
||||
* asks if entered names is not correct and re-calls itself or
|
||||
* calls method of adding received text to data.
|
||||
/**
|
||||
* Asks for the name of text, path to file to read text from,
|
||||
* checks for its existing, reads contents and,
|
||||
* 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) {
|
||||
|
||||
@ -218,8 +208,8 @@ class TextReader {
|
||||
|
||||
}
|
||||
|
||||
/** Stores data about tracking texts,
|
||||
* includes methods for work with them due the adding.
|
||||
/** Object used for storing data about tracking texts,
|
||||
* includes methods for work with them.
|
||||
*/
|
||||
class TextData {
|
||||
|
||||
@ -246,10 +236,11 @@ class TextData {
|
||||
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.
|
||||
* @param searchingName name of the text to be found.
|
||||
* @return the text with searchingName name or null.
|
||||
/**
|
||||
* Returns Text object whose name matches searchingName or null
|
||||
* if there is no text with same name in the textsList.
|
||||
* searchingName: name of the text to be found.
|
||||
* return: the text with searchingName name or null.
|
||||
*/
|
||||
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
|
||||
* it exists.
|
||||
* @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 {
|
||||
|
||||
@ -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.
|
||||
*/
|
||||
|
||||
class CommandCenter(
|
||||
private val textData: TextData,
|
||||
private val textReader: TextReader,
|
||||
private val statisticBuilder: StatisticBuilder
|
||||
) {
|
||||
|
||||
|
||||
private val exitCommand = Command("exit", ::exit)
|
||||
private val addCommand = Command("add text") { textReader.readNewText(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 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)
|
||||
|
||||
/** 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. */
|
||||
class ReturnException : Exception()
|
||||
@ -412,7 +433,7 @@ class InvalidInputTypeException : 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,
|
||||
* 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
|
||||
* request.
|
||||
*
|
||||
@ -451,6 +472,7 @@ inline fun <reified T> requestInput(
|
||||
if (input == "return") return Pair(ReturnCommand(), "")
|
||||
|
||||
try {
|
||||
// inputT = input to typeOf<T>()
|
||||
inputT = when (typeOf<T>()) {
|
||||
typeOf<Int>() -> input.toInt()
|
||||
typeOf<Double>() -> input.toDouble()
|
||||
@ -501,36 +523,9 @@ inline fun <reified T> requestInput(
|
||||
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() {
|
||||
|
||||
val textData = TextData()
|
||||
|
Loading…
Reference in New Issue
Block a user