concordia-library/concordia/concordia_config.cpp

58 lines
2.1 KiB
C++

#include <sstream>
#include <stdlib.h>
#include "concordia/concordia_config.hpp"
#include "concordia/common/logging.hpp"
#define PUDDLE_TAGSET_PARAM "puddle_tagset_path"
#define SUFFIX_ARRAY_PARAM "suffix_array_path"
#define HTML_TAGS_PARAM "html_tags_path"
#define STOP_WORDS_ENABLED_PARAM "stop_words_enabled"
#define STOP_WORDS_PARAM "stop_words_path"
#define NAMED_ENTITIES_PARAM "named_entities_path"
#define ANUBIS_THRESHOLD_PARAM "anubis_threshold"
ConcordiaConfig::ConcordiaConfig(const std::string & configFilePath) {
try {
_config.readFile(configFilePath.c_str());
} catch(libconfig::ParseException & e) {
throw ConcordiaException("Error parsing config file: "+configFilePath);
} catch(libconfig::FileIOException & e) {
throw ConcordiaException("I/O error reading config file: "
+configFilePath);
}
_htmlTagsFilePath =
ConcordiaConfig::_readConfigParameterStr(HTML_TAGS_PARAM);
_stopWordsEnabled =
ConcordiaConfig::_readConfigParameterStr(
STOP_WORDS_ENABLED_PARAM) != "false";
_stopWordsFilePath =
ConcordiaConfig::_readConfigParameterStr(STOP_WORDS_PARAM, "");
_namedEntitiesFilePath =
ConcordiaConfig::_readConfigParameterStr(NAMED_ENTITIES_PARAM);
_anubisThreshold = atof(ConcordiaConfig::_readConfigParameterStr(
ANUBIS_THRESHOLD_PARAM,
"0.3").c_str());
}
ConcordiaConfig::~ConcordiaConfig() {
}
std::string ConcordiaConfig::_readConfigParameterStr(const std::string & name) {
if (!_config.exists(name)) {
throw ConcordiaException("Config error: "+name+" setting not found");
} else {
return _config.lookup(name);
}
}
std::string ConcordiaConfig::_readConfigParameterStr(
const std::string & name,
const std::string & defaultValue) {
if (!_config.exists(name)) {
return defaultValue;
} else {
return _config.lookup(name);
}
}