From 397a3de3fa60d5a03dd12254a70dccaf72c50bfc Mon Sep 17 00:00:00 2001 From: Enadream Date: Wed, 4 Jan 2023 18:38:15 +0300 Subject: [PATCH] V 0.71 --- dict/nouns.txt | 1 - dict/verbs.txt | 4 +- src/ecli.cpp | 4 +- src/helper.cpp | 147 ------------------------------------------- src/main.cpp | 2 +- src/main_handler.cpp | 6 +- src/main_handler.hpp | 3 +- 7 files changed, 9 insertions(+), 158 deletions(-) delete mode 100644 src/helper.cpp diff --git a/dict/nouns.txt b/dict/nouns.txt index d167413..1fee4d8 100644 --- a/dict/nouns.txt +++ b/dict/nouns.txt @@ -34,7 +34,6 @@ Tuna , Tuna Quiz , Quizzes Index , Indices ########## DATA BASE ########## -'hood a'man a-bomb a-horizon diff --git a/dict/verbs.txt b/dict/verbs.txt index aa801e2..b615c28 100644 --- a/dict/verbs.txt +++ b/dict/verbs.txt @@ -3797,7 +3797,7 @@ fossilise fossilize foster foul -found +found /U0 founder fowl fox @@ -5541,7 +5541,7 @@ occidentalize occlude occult occupy -occur +occur /DL odorize odourise off diff --git a/src/ecli.cpp b/src/ecli.cpp index fde4815..0d5f959 100644 --- a/src/ecli.cpp +++ b/src/ecli.cpp @@ -28,7 +28,7 @@ void Ecli::Start() { auto printHeader = []() { SetColor(3); - std::cout << "__________________ Welcome to the ChatBot (V0.70 @enadream) __________________\n\n" << std::endl; + std::cout << "__________________ Welcome to the ChatBot (V0.71 @enadream) __________________\n\n" << std::endl; SetColor(7); }; @@ -175,7 +175,7 @@ void Ecli::Start() { } else { WordToken a; - mainHandler.ParseMultithread(params[0].value, true, a); + mainHandler.ParseMultiple(params[0].value, true, a); } std::cout << "\n"; diff --git a/src/helper.cpp b/src/helper.cpp deleted file mode 100644 index 7dfc3aa..0000000 --- a/src/helper.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include -#include - -typedef unsigned long long ull; - -char IsPunctuation(const char& one_char); -bool IsChar(const char& letter); -#define FILE_SIZE 550000 - - -void tokenize(const char* file_in, const ull& size, char*& file_out, ull& out_size) { - bool line_empty = true; - file_out = new char[size * 1.5]; - bool save = true; - ull lastWordEndIndex = 0; - - for (ull i = 0; i < size; i++) { // Parse sentences into tokens - if (file_in[i] != ' ' && file_in[i] != '\n' && file_in[i] != '\t' && file_in[i] != '\r' && file_in[i] != '\0') { - if (save) { - if (IsPunctuation(file_in[i])) { - if (!line_empty) - file_out[out_size++] = '\n'; - file_out[out_size++] = file_in[i]; - file_out[out_size++] = '\n'; - lastWordEndIndex = out_size; - line_empty = true; - } - else if (IsChar(file_in[i])) { - file_out[out_size++] = file_in[i]; - line_empty = false; - } - else { - if (!line_empty) { - file_out[out_size++] = '\n'; - lastWordEndIndex = out_size; - } - out_size = lastWordEndIndex; - line_empty = true; - save = false; - } - } - } - else { - if (!save) - save = true; - if (!line_empty) { - file_out[out_size++] = '\n'; - lastWordEndIndex = out_size; - } - line_empty = true; - } - } -} - -int main() { - std::string file_name; - char* buffer; - char* buffer_out; - ull size; - ull out_size = 0; - - // Read file - std::cin >> file_name; - std::ifstream file(file_name, std::ios::in | std::ios::binary | std::ios::ate); - - if (!file.is_open()) { - std::cout << "No file with that name.\n"; - return -1; - } - - // Take data into buffer - //size = file.tellg(); - size = FILE_SIZE; - buffer = new char[FILE_SIZE]; - file.seekg(0, std::ios::beg); - file.read(buffer, FILE_SIZE); - file.close(); - - // Make operation - tokenize(buffer, size, buffer_out, out_size); - - // Write file - file_name = "test.txt"; - std::ofstream out_file(file_name, std::ios::out); - out_file.write(buffer_out, out_size); - out_file.close(); - - delete[] buffer; - delete[] buffer_out; - - std::cout << "Operation Done!\n"; - return 0; -} - - -char IsPunctuation(const char& one_char) { - switch (one_char) - { - case ',': // Comma - return 1; - case '\"': // Quotation Mark - return 2; - case ':': // Colon Mark - return 3; - case ';': // Semicolon Mark - return 4; - case '(': // Open Parantheses - return 5; - case ')': // Close Parantheses - return 6; - case '[': // Open Brackets - return 7; - case ']': // Close Brackets - return 8; - case '/': // Slash - return 9; - case '.': // Full stop - return 10; - case '?': // Question mark - return 11; - case '!': // Exclamation point - return 12; - case '%': // Slash - return 13; - default: - return 0; - } -} - -bool IsChar(const char& letter) { // returns the character if it's alpha otherwise returns 0 - if (letter > 64 && letter < 91) { // Capital letter - return true; - } - else if (letter > 96 && letter < 123) { // Char already lowercase - return true; - } - else if (letter == '\'') { - return true; - } - else if (letter == '-') { - return true; - } - else { // Character is not alphabetic - return false; - } -} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 2ed040f..e5a9bdf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ /* * Eren ALPAR enadream.com -* APP VERSION 0.70 +* APP VERSION 0.71 * C++ VERSION 17 */ diff --git a/src/main_handler.cpp b/src/main_handler.cpp index f07db77..7ab7c3c 100644 --- a/src/main_handler.cpp +++ b/src/main_handler.cpp @@ -48,7 +48,7 @@ namespace handle { if (tempLine.Length() > 0) { // Parse each line - ParseMultithread(tempLine, false, word); + ParseMultiple(tempLine, false, word); // Write word to file util::IntToStr(out_str, lineNumber); out_str.Append("- ", 2); @@ -215,7 +215,7 @@ namespace handle { } } - void MainHandler::ParseMultithread(const String& raw_word, const bool print_result, WordToken& word) { // Multithread parser + void MainHandler::ParseMultiple(const String& raw_word, const bool print_result, WordToken& word) { // Multithread parser util::Array result; String outStrs[result.GetSize()]; @@ -284,7 +284,7 @@ namespace handle { words.push_back(WordToken()); words.back().data = &tokenize.sentences[i][j]; // Parse token - ParseMultithread(tokenize.sentences[i][j], false, words.back()); + ParseMultiple(tokenize.sentences[i][j], false, words.back()); } // Words to string out_str += "\n\x1b[38;5;198m[SENTENCE "; diff --git a/src/main_handler.hpp b/src/main_handler.hpp index 5212813..4d52a24 100644 --- a/src/main_handler.hpp +++ b/src/main_handler.hpp @@ -15,7 +15,6 @@ namespace handle { - class MainHandler { private: // variables noun::NounHandler noun; @@ -49,7 +48,7 @@ namespace handle { MainHandler() = default; void Read(const WordType type, String& dir); void Delete(const WordType type); - void ParseMultithread(const String& raw_word, const bool print_result, WordToken& word); + void ParseMultiple(const String& raw_word, const bool print_result, WordToken& word); void ParseWithType(const WordType type, const String& str); void ParseSentence(const String& str); void PrintResult(const WordType type, const int32& result, const String& str);