concordia index stub
This commit is contained in:
parent
b238995a16
commit
656e9dbae9
@ -6,6 +6,7 @@ foreach(dir ${ALL_DIRECTORIES})
|
||||
endforeach(dir)
|
||||
|
||||
add_library(concordia SHARED
|
||||
concordia_index.cpp
|
||||
word_map.cpp
|
||||
hash_generator.cpp
|
||||
concordia.cpp
|
||||
|
40
concordia/concordia_index.cpp
Normal file
40
concordia/concordia_index.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "concordia/concordia_index.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
ConcordiaIndex::ConcordiaIndex(const string & wordMapFilepath,
|
||||
const string & hashedIndexFilepath,
|
||||
const string & suffixArrayFilepath)
|
||||
throw(ConcordiaException) {
|
||||
if (boost::filesystem::exists(wordMapFilepath)) {
|
||||
if (boost::filesystem::exists(hashedIndexFilepath)) {
|
||||
// create hashed index file for appending
|
||||
} else {
|
||||
throw ConcordiaException("E01: Word map file exists "
|
||||
"but hashed index file absent.");
|
||||
}
|
||||
} else { // WordMap file does not exist
|
||||
if (boost::filesystem::exists(hashedIndexFilepath)) {
|
||||
throw ConcordiaException("E02: Hashed index file exists "
|
||||
"but word map file absent.");
|
||||
} else {
|
||||
// create hashed index file for writing
|
||||
}
|
||||
}
|
||||
_hashGenerator = boost::shared_ptr<HashGenerator>(
|
||||
new HashGenerator(wordMapFilepath));
|
||||
}
|
||||
|
||||
ConcordiaIndex::~ConcordiaIndex() {
|
||||
}
|
||||
|
||||
void ConcordiaIndex::serializeWordMap() {
|
||||
_hashGenerator->serializeWordMap();
|
||||
}
|
||||
|
||||
void ConcordiaIndex::generateSuffixArray() {
|
||||
}
|
||||
|
||||
void ConcordiaIndex::addSentence(const string & sentence) {
|
||||
}
|
||||
|
36
concordia/concordia_index.hpp
Normal file
36
concordia/concordia_index.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef CONCORDIA_INDEX_HDR
|
||||
#define CONCORDIA_INDEX_HDR
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include "concordia/hash_generator.hpp"
|
||||
#include "concordia/concordia_exception.hpp"
|
||||
|
||||
/*!
|
||||
Class for creating and maintaining the index.
|
||||
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
|
||||
class ConcordiaIndex {
|
||||
public:
|
||||
explicit ConcordiaIndex(const string & wordMapFilepath,
|
||||
const string & hashedIndexFilepath,
|
||||
const string & suffixArrayFilepath)
|
||||
throw(ConcordiaException);
|
||||
|
||||
/*! Destructor.
|
||||
*/
|
||||
virtual ~ConcordiaIndex();
|
||||
|
||||
void addSentence(const string & sentence);
|
||||
|
||||
void serializeWordMap();
|
||||
|
||||
void generateSuffixArray();
|
||||
|
||||
private:
|
||||
boost::shared_ptr<HashGenerator> _hashGenerator;
|
||||
};
|
||||
|
||||
#endif
|
@ -5,12 +5,12 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <fstream>
|
||||
|
||||
HashGenerator::HashGenerator(const string & wordMapFilename)
|
||||
HashGenerator::HashGenerator(const string & wordMapFilePath)
|
||||
throw(ConcordiaException) :
|
||||
_wordMapFilename(wordMapFilename),
|
||||
_wordMapFilePath(wordMapFilePath),
|
||||
_wordMap(boost::shared_ptr<WordMap>(new WordMap)) {
|
||||
if (boost::filesystem::exists(_wordMapFilename)) {
|
||||
ifstream ifs(_wordMapFilename.c_str(), std::ios::binary);
|
||||
if (boost::filesystem::exists(_wordMapFilePath)) {
|
||||
ifstream ifs(_wordMapFilePath.c_str(), std::ios::binary);
|
||||
boost::archive::binary_iarchive ia(ifs);
|
||||
boost::shared_ptr<WordMap> restoredWordMap(new WordMap);
|
||||
ia >> *_wordMap;
|
||||
@ -36,7 +36,7 @@ vector<int> HashGenerator::generateHash(const string & sentence) {
|
||||
}
|
||||
|
||||
void HashGenerator::serializeWordMap() {
|
||||
ofstream ofs(_wordMapFilename.c_str(), std::ios::binary);
|
||||
ofstream ofs(_wordMapFilePath.c_str(), std::ios::binary);
|
||||
boost::archive::binary_oarchive oa(ofs);
|
||||
oa << *_wordMap;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ using namespace std;
|
||||
|
||||
class HashGenerator {
|
||||
public:
|
||||
explicit HashGenerator(const string & wordMapFilename)
|
||||
explicit HashGenerator(const string & wordMapFilePath)
|
||||
throw(ConcordiaException);
|
||||
|
||||
/*! Destructor.
|
||||
@ -31,7 +31,7 @@ public:
|
||||
private:
|
||||
boost::shared_ptr<WordMap> _wordMap;
|
||||
|
||||
string _wordMapFilename;
|
||||
string _wordMapFilePath;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3,6 +3,7 @@ add_library(concordia-tests
|
||||
test_concordia_config.cpp
|
||||
test_word_map.cpp
|
||||
test_hash_generator.cpp
|
||||
test_concordia_index.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(concordia-tests concordia ${LIBCONFIG_LIB} concordia-tests-common)
|
||||
|
18
concordia/t/test_concordia_index.cpp
Normal file
18
concordia/t/test_concordia_index.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "tests/unit-tests/unit_tests_globals.hpp"
|
||||
|
||||
#include "concordia/concordia_index.hpp"
|
||||
#include "tests/common/test_resources_manager.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(concordia_index)
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ResourcesExistenceTest1 )
|
||||
{
|
||||
ConcordiaIndex index(TestResourcesManager::getTestWordMapFilePath("mock_word_map.bin"),
|
||||
TestResourcesManager::getTestHashIndexFilePath("mock_hash_index.bin"),
|
||||
TestResourcesManager::getTestSuffixArrayFilePath());
|
||||
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
@ -3,6 +3,7 @@
|
||||
#define PUDDLE_TEST_DIRECTORY "puddle"
|
||||
#define CONCORDIA_TAGSET_DIRECTORY "concordia-tagset"
|
||||
#define CONCORDIA_CONFIG_DIRECTORY "concordia-config"
|
||||
#define CONCORDIA_INDEX_DIRECTORY "concordia-index"
|
||||
|
||||
string TestResourcesManager::getPuddleFilePath(const string & filename) {
|
||||
string result = string(TEST_RESOURCES_DIRECTORY);
|
||||
@ -15,6 +16,21 @@ string TestResourcesManager::getTestConcordiaConfigFilePath(const string & filen
|
||||
return result + "/" + CONCORDIA_CONFIG_DIRECTORY + "/" + filename;
|
||||
}
|
||||
|
||||
string TestResourcesManager::getTestWordMapFilePath(const string & filename) {
|
||||
string result = string(TEST_RESOURCES_DIRECTORY);
|
||||
return result + "/" + CONCORDIA_INDEX_DIRECTORY + "/" + filename;
|
||||
}
|
||||
|
||||
string TestResourcesManager::getTestHashIndexFilePath(const string & filename) {
|
||||
string result = string(TEST_RESOURCES_DIRECTORY);
|
||||
return result + "/" + CONCORDIA_INDEX_DIRECTORY + "/" + filename;
|
||||
}
|
||||
|
||||
string TestResourcesManager::getTestSuffixArrayFilePath() {
|
||||
string result = string(TEST_RESOURCES_DIRECTORY);
|
||||
return result + "/" + CONCORDIA_INDEX_DIRECTORY + "/test_SA.bin";
|
||||
}
|
||||
|
||||
string TestResourcesManager::getProdConcordiaConfigFilePath(const string & filename) {
|
||||
string result = string(PROD_RESOURCES_DIRECTORY);
|
||||
return result + "/" + CONCORDIA_CONFIG_DIRECTORY + "/" + filename;
|
||||
|
@ -14,6 +14,12 @@ public:
|
||||
|
||||
static string getTestConcordiaConfigFilePath(const string & filename);
|
||||
|
||||
static string getTestWordMapFilePath(const string & filename);
|
||||
|
||||
static string getTestHashIndexFilePath(const string & filename);
|
||||
|
||||
static string getTestSuffixArrayFilePath();
|
||||
|
||||
static string getProdConcordiaConfigFilePath(const string & filename);
|
||||
};
|
||||
|
||||
|
0
tests/resources/concordia-index/mock_hash_index.bin
Normal file
0
tests/resources/concordia-index/mock_hash_index.bin
Normal file
BIN
tests/resources/concordia-index/mock_word_map.bin
Normal file
BIN
tests/resources/concordia-index/mock_word_map.bin
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user