commit bee7b5f42e2969e7ac2925dee77f4a078655e28a Author: Eiji Miyamoto Date: Thu Aug 24 22:23:53 2023 +0100 fixed it as it did not work at all. still need to convert python file to this diff --git a/buffer_mecab.cpp b/buffer_mecab.cpp index 45c1491..bcd5614 100644 --- a/buffer_mecab.cpp +++ b/buffer_mecab.cpp @@ -11,13 +11,20 @@ void process_text(std::istream& sin, std::ostream& sout) { std::stringstream buffer; std::string tokenized; bool in_bracket = false; - for (char i : text) { + + // loop till it reaches size of text + for (std::size_t idx = 0; idx < text.length(); ++idx) { + char i = text[idx]; + buffer << i; - if (i == text.back()){ + + // text.back() to text.lenght() + if (idx == text.length() - 1) { std::string token = tagger->parse(buffer.str().c_str()); token.erase(token.find_last_not_of(" \n\r\t") + 1); tokenized += token; } + if (i == '[') { std::string temp = buffer.str(); temp.pop_back(); @@ -29,9 +36,11 @@ void process_text(std::istream& sin, std::ostream& sout) { buffer.clear(); in_bracket = true; } + if (in_bracket) { tokenized += i; } + if (i == ']') { in_bracket = false; buffer.str(""); @@ -39,12 +48,12 @@ void process_text(std::istream& sin, std::ostream& sout) { } } - sout << tokenized; - delete tagger; + + sout << tokenized; } int main() { process_text(std::cin, std::cout); return 0; -} +} \ No newline at end of file