2013-10-24 17:08:58 +02:00
|
|
|
#include <sstream>
|
2015-04-17 14:17:59 +02:00
|
|
|
#include <stdlib.h>
|
2013-10-24 17:08:58 +02:00
|
|
|
#include "concordia/concordia_config.hpp"
|
|
|
|
#include "concordia/common/logging.hpp"
|
|
|
|
|
|
|
|
#define PUDDLE_TAGSET_PARAM "puddle_tagset_path"
|
2013-11-28 16:47:57 +01:00
|
|
|
#define SUFFIX_ARRAY_PARAM "suffix_array_path"
|
2014-04-29 14:46:04 +02:00
|
|
|
#define HTML_TAGS_PARAM "html_tags_path"
|
2015-04-21 21:33:08 +02:00
|
|
|
#define STOP_WORDS_ENABLED_PARAM "stop_words_enabled"
|
2014-04-29 14:46:04 +02:00
|
|
|
#define STOP_WORDS_PARAM "stop_words_path"
|
|
|
|
#define NAMED_ENTITIES_PARAM "named_entities_path"
|
2015-04-16 11:39:39 +02:00
|
|
|
#define ANUBIS_THRESHOLD_PARAM "anubis_threshold"
|
2013-10-24 17:08:58 +02:00
|
|
|
|
2019-01-18 13:30:51 +01:00
|
|
|
ConcordiaConfig::ConcordiaConfig(const std::string & configFilePath) {
|
2013-10-24 17:08:58 +02:00
|
|
|
try {
|
|
|
|
_config.readFile(configFilePath.c_str());
|
2015-04-15 14:14:10 +02:00
|
|
|
} catch(libconfig::ParseException & e) {
|
2013-10-24 17:08:58 +02:00
|
|
|
throw ConcordiaException("Error parsing config file: "+configFilePath);
|
2015-04-15 14:14:10 +02:00
|
|
|
} catch(libconfig::FileIOException & e) {
|
2013-10-24 17:08:58 +02:00
|
|
|
throw ConcordiaException("I/O error reading config file: "
|
|
|
|
+configFilePath);
|
|
|
|
}
|
|
|
|
|
2014-04-29 14:46:04 +02:00
|
|
|
_htmlTagsFilePath =
|
|
|
|
ConcordiaConfig::_readConfigParameterStr(HTML_TAGS_PARAM);
|
2015-04-21 21:33:08 +02:00
|
|
|
_stopWordsEnabled =
|
|
|
|
ConcordiaConfig::_readConfigParameterStr(
|
|
|
|
STOP_WORDS_ENABLED_PARAM) != "false";
|
2014-04-29 14:46:04 +02:00
|
|
|
_stopWordsFilePath =
|
2015-04-30 21:15:18 +02:00
|
|
|
ConcordiaConfig::_readConfigParameterStr(STOP_WORDS_PARAM, "");
|
2014-04-29 14:46:04 +02:00
|
|
|
_namedEntitiesFilePath =
|
|
|
|
ConcordiaConfig::_readConfigParameterStr(NAMED_ENTITIES_PARAM);
|
2015-04-17 14:17:59 +02:00
|
|
|
_anubisThreshold = atof(ConcordiaConfig::_readConfigParameterStr(
|
2015-04-30 21:15:18 +02:00
|
|
|
ANUBIS_THRESHOLD_PARAM,
|
|
|
|
"0.3").c_str());
|
2013-10-24 17:08:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ConcordiaConfig::~ConcordiaConfig() {
|
|
|
|
}
|
|
|
|
|
2019-01-18 13:30:51 +01:00
|
|
|
std::string ConcordiaConfig::_readConfigParameterStr(const std::string & name) {
|
2013-10-24 17:08:58 +02:00
|
|
|
if (!_config.exists(name)) {
|
|
|
|
throw ConcordiaException("Config error: "+name+" setting not found");
|
|
|
|
} else {
|
|
|
|
return _config.lookup(name);
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 21:15:18 +02:00
|
|
|
|
|
|
|
std::string ConcordiaConfig::_readConfigParameterStr(
|
|
|
|
const std::string & name,
|
2019-01-18 13:30:51 +01:00
|
|
|
const std::string & defaultValue) {
|
2015-04-30 21:15:18 +02:00
|
|
|
if (!_config.exists(name)) {
|
|
|
|
return defaultValue;
|
|
|
|
} else {
|
|
|
|
return _config.lookup(name);
|
|
|
|
}
|
|
|
|
}
|