concordia-library/concordia/regex_rule.hpp

50 lines
1.3 KiB
C++
Raw Normal View History

2015-06-22 13:52:56 +02:00
#ifndef REGEX_ANNOTATION_HDR
#define REGEX_ANNOTATION_HDR
#include <string>
#include "concordia/common/config.hpp"
2015-06-22 13:52:56 +02:00
#include "concordia/anonymized_sentence.hpp"
#include "concordia/concordia_exception.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/regex.hpp>
#include <boost/regex/icu.hpp>
2015-06-22 13:52:56 +02:00
#include <unicode/unistr.h>
typedef boost::error_info<struct my_tag, std::string> my_tag_error_info;
2015-05-01 14:52:53 +02:00
/*!
2015-06-22 13:52:56 +02:00
Class for representing a regular expression annotation rule.
2015-05-01 14:52:53 +02:00
Holds regex pattern string for matching and replacement string for
2015-06-22 13:52:56 +02:00
annotating found matches.
2015-05-01 14:52:53 +02:00
*/
2015-06-22 13:52:56 +02:00
class RegexRule {
public:
2015-05-01 14:52:53 +02:00
/*!
Constructor.
\param patternString regex pattern to match
\param replacement string to substitute the found match
\param caseSensitive case sensitivity of the pattern
*/
2015-06-22 13:52:56 +02:00
RegexRule(std::string patternString, std::string value,
bool caseSensitive = true)
throw(ConcordiaException);
/*! Destructor.
*/
2015-06-22 13:52:56 +02:00
virtual ~RegexRule();
2015-06-22 13:52:56 +02:00
/*! Applies the operation on anonymized sentence.
\param sentence the input sentence
2015-05-01 14:52:53 +02:00
*/
2015-06-22 13:52:56 +02:00
void apply(boost::shared_ptr<AnonymizedSentence> sentence);
private:
boost::u32regex _pattern;
2015-06-22 13:52:56 +02:00
std::string _value;
};
#endif