concordia-library/concordia/concordia.cpp

70 lines
2.0 KiB
C++
Raw Normal View History

2013-11-28 16:47:57 +01:00
#include <sstream>
2013-10-24 17:08:58 +02:00
#include "concordia/concordia.hpp"
#include "concordia/common/config.hpp"
// ===========================================
std::string _createLibraryVersion();
// ===========================================
std::string Concordia::_libraryVersion = _createLibraryVersion();
// ===========================================
2013-11-28 16:47:57 +01:00
Concordia::Concordia(const std::string & configFilePath)
throw(ConcordiaException) {
_config = boost::shared_ptr<ConcordiaConfig> (
2013-10-24 17:08:58 +02:00
new ConcordiaConfig(configFilePath));
2013-11-28 16:47:57 +01:00
_index = boost::shared_ptr<ConcordiaIndex>(
new ConcordiaIndex(_config->getWordMapFilePath(),
_config->getHashedIndexFilePath(),
_config->getSuffixArrayFilePath()));
_searcher = boost::shared_ptr<IndexSearcher>(new IndexSearcher());
2013-10-24 17:08:58 +02:00
}
Concordia::~Concordia() {
}
std::string & Concordia::getVersion() {
return _libraryVersion;
}
std::string _createLibraryVersion() {
std::stringstream version;
version << CONCORDIA_VERSION_MAJOR
<< "."
<< CONCORDIA_VERSION_MINOR;
return version.str();
}
2013-11-28 16:47:57 +01:00
void Concordia::addSentence(const std::string & sentence)
throw(ConcordiaException) {
_index->addSentence(sentence);
}
void Concordia::addAllSentences(vector<std::string> & sentences)
throw(ConcordiaException) {
_index->addAllSentences(sentences);
}
2013-11-28 16:47:57 +01:00
void Concordia::generateIndex() throw(ConcordiaException) {
_index->generateSuffixArray();
}
void Concordia::loadIndex() throw(ConcordiaException) {
2013-11-28 16:47:57 +01:00
_searcher->loadIndex(_config->getWordMapFilePath(),
_config->getHashedIndexFilePath(),
_config->getSuffixArrayFilePath());
}
std::vector<saidx_t> Concordia::simpleSearch(const std::string & pattern)
throw(ConcordiaException) {
return _searcher->simpleSearch(pattern);
}