Commit 432c6850 authored by Igor Danielewicz's avatar Igor Danielewicz

Code cleared and added new utilities to replace

parent bbe9a633
# ediText
\ No newline at end of file
## ediText
Highly configurable tool for processing text. Input is processed by chain of functions defined by the user as an argument in JSON format.
# Usage
Exeplary JSON:
{
"0":
{
"function": {"name": "replace", "arg": {"from": "a", "to": "b", "case_sensitive": false}},
"iterator": {"name": "line"}
},
"1":
{
"function": {"name": "replace", "arg": {"from": "c", "to": "d"}},
"iterator": {"name": "token"}
}
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ private:
void ediText_Worker::static_init(ptree config)
{
;
;// Check if nkjp.ini for tokenizer is present
}
void ediText_Worker::init(ptree config)
......
......@@ -4,9 +4,12 @@ using ptree = boost::property_tree::ptree;
Replace::Replace(ptree& config)
{
from = config.get<std::string>("from");
to = config.get<std::string>("to");
reg = from;
std::string from = config.get<std::string>("from");
auto flags = std::regex_constants::optimize;
if(!config.get<bool>("case_sensitive", true))
flags = flags | std::regex_constants::icase;
reg = std::regex(from, flags);
}
std::string Replace::process(std::string str)
......
#pragma once
#include "functions/Function.hpp"
#include <boost/property_tree/ptree.hpp>
#include <regex>
#include "functions/Function.hpp"
using ptree = boost::property_tree::ptree;
class Replace : public Function
......@@ -16,6 +16,3 @@ private:
std::string from, to;
std::regex reg;
};
// TODO: Clean up code
// TODO: Make two versions direct replace and regex replace
\ No newline at end of file
#pragma once
#include "textIterators/TextIterator.hpp"
class LineIterator : public TextIterator
{
public:
......@@ -15,9 +16,4 @@ public:
{
return !input.eof();
}
;
protected:
;
private:
;
};
\ No newline at end of file
#pragma once
#include "textIterators/TextIterator.hpp"
#include "textIterators/Tokenizer.hpp"
#include <iostream>
class SentenceIterator : public TextIterator, public Tokenizer
......@@ -13,7 +10,6 @@ public:
std::string get()
{
// std::cout << "GET" << std::endl;
std::string tokenstr;
auto& tokens = getSentence();
for(auto& token : tokens)
......@@ -28,6 +24,4 @@ public:
{
return tokenizer.has_more();
}
protected:
private:
};
\ No newline at end of file
#pragma once
#include "textIterators/TextIterator.hpp"
#include "textIterators/Tokenizer.hpp"
#include <iostream>
// #include <iostream>
class TokenIterator : public TextIterator, public Tokenizer
......@@ -23,6 +21,4 @@ public:
{
return tokenizer.has_more() || !sentence->empty();
}
protected:
private:
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment