concordia-library/concordia/sentence_anonymizer.hpp

68 lines
2.0 KiB
C++
Raw Normal View History

#ifndef SENTENCE_ANONYMIZER_HDR
#define SENTENCE_ANONYMIZER_HDR
#include <string>
#include <vector>
#include "concordia/common/config.hpp"
2015-06-22 13:52:56 +02:00
#include "concordia/anonymized_sentence.hpp"
#include "concordia/regex_rule.hpp"
#include "concordia/concordia_config.hpp"
#include "concordia/concordia_exception.hpp"
#include <boost/shared_ptr.hpp>
#include <boost/filesystem.hpp>
/*!
2015-05-01 14:52:53 +02:00
Class for anonymizing sentence before generating hash.
This operation is is used to
remove unnecessary symbols and possibly words from sentences added to index
and search patterns. Anonymizer removes html tags, substitutes predefined symbols
with a single space, removes stop words (if the option is enabled), as well as
named entities and special symbols. All these have to be listed in files
(see \ref tutorial3).
*/
class SentenceAnonymizer {
public:
2015-05-01 14:52:53 +02:00
/*! Constructor.
\param config config object, holding paths to necessary files
*/
explicit SentenceAnonymizer(boost::shared_ptr<ConcordiaConfig> config)
throw(ConcordiaException);
/*! Destructor.
*/
virtual ~SentenceAnonymizer();
2015-05-01 14:52:53 +02:00
/*! Anonymizes the sentence.
\param sentence input sentence
\returns altered version of the input sentence
*/
2015-06-22 13:52:56 +02:00
boost::shared_ptr<AnonymizedSentence>
anonymize(const std::string & sentence);
private:
void _createNeRules(std::string & namedEntitiesPath);
void _createHtmlTagsRule(std::string & htmlTagsPath);
2015-06-22 13:52:56 +02:00
boost::shared_ptr<RegexRule> _getMultipleReplacementRule(
std::string & filePath,
std::string replacement,
bool wholeWord = false);
2015-06-22 13:52:56 +02:00
std::vector<RegexRule> _namedEntities;
2015-06-22 13:52:56 +02:00
boost::shared_ptr<RegexRule> _htmlTags;
bool _stopWordsEnabled;
2015-06-22 13:52:56 +02:00
boost::shared_ptr<RegexRule> _stopWords;
2015-06-22 13:52:56 +02:00
boost::shared_ptr<RegexRule> _stopSymbols;
2015-06-22 13:52:56 +02:00
boost::shared_ptr<RegexRule> _spaceSymbols;
};
#endif