136 lines
2.3 KiB
C++
136 lines
2.3 KiB
C++
#include "other.h"
|
|
|
|
#include <iostream> //Xperimental -- for debug only
|
|
|
|
#include "utf8utf16.h"
|
|
|
|
#include "boost/regex.hpp"
|
|
#include "boost/algorithm/string/regex.hpp"
|
|
|
|
|
|
namespace OT
|
|
{
|
|
|
|
std::vector<OtherWordRecord> OtherWordRecordArr;
|
|
|
|
OtherWordRecord::OtherWordRecord()
|
|
{
|
|
SetAllFields();
|
|
}
|
|
|
|
OtherWordRecord::OtherWordRecord(std::wstring line)
|
|
{
|
|
std::vector<std::wstring> lineArr;
|
|
|
|
boost::split_regex(lineArr, line, boost::wregex(L" "));
|
|
|
|
SetWord(lineArr[1]);
|
|
|
|
SetAllFields(lineArr);
|
|
|
|
FillTranslationUnit(lineArr, 3);
|
|
}
|
|
|
|
std::wstring OtherWordRecord::getType() const
|
|
{
|
|
return properties.get<std::wstring>(L"type");
|
|
}
|
|
|
|
void OtherWordRecord::SetAllFields()
|
|
{
|
|
properties.put(L"type", "");
|
|
}
|
|
|
|
void OtherWordRecord::SetAllFields(const std::vector<std::wstring>& lineArr)
|
|
{
|
|
properties.put(L"type", lineArr[2]);
|
|
}
|
|
|
|
|
|
/*
|
|
boost::property_tree::wptree OtherWordModificator::GetModificators() const
|
|
{
|
|
return boost::property_tree::wptree();
|
|
}
|
|
*/
|
|
|
|
OtherWordPair::OtherWordPair()
|
|
{
|
|
}
|
|
|
|
OtherWordPair::OtherWordPair(OtherWordModificator iModificator, OtherWordRecord iWordRecord)
|
|
: modificator(iModificator)
|
|
, wordRecord(iWordRecord)
|
|
{
|
|
}
|
|
|
|
const WordModificatorInterface& OtherWordPair::wordModificator() const
|
|
{
|
|
return modificator;
|
|
}
|
|
|
|
const WordHolder& OtherWordPair::word() const
|
|
{
|
|
return wordRecord;
|
|
}
|
|
|
|
std::wstring OtherWordPair::getType()
|
|
{
|
|
return L"other";
|
|
}
|
|
|
|
|
|
void RecognizeWord(std::wstring word, std::vector<std::shared_ptr<WordPairInterface>>& wordPair)
|
|
{
|
|
|
|
for (auto& wordRecord : OtherWordRecordArr)
|
|
{
|
|
if (wordRecord.GetWord() == word)
|
|
{
|
|
wordPair.push_back(std::shared_ptr<WordPairInterface>(new OtherWordPair(OtherWordModificator(), wordRecord)));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void LoadWordSet(std::string filename)
|
|
{
|
|
|
|
|
|
#ifdef _WIN32
|
|
std::ifstream f("C:/Workplace/ChineseJournal/rudict/" + filename);
|
|
|
|
#else
|
|
std::ifstream f("/home/devuser/workplace/rudict/" + filename);
|
|
#endif
|
|
|
|
std::string line;
|
|
std::wstring wline;
|
|
|
|
if (f.is_open())
|
|
{
|
|
|
|
getline(f, line); //Skip one line
|
|
|
|
std::cout << "File found!" << std::endl;
|
|
while (getline(f, line))
|
|
{
|
|
|
|
wline = string_to_wstring(line);
|
|
OtherWordRecord otherWordRecord(wline);
|
|
|
|
OtherWordRecordArr.push_back(otherWordRecord);
|
|
|
|
}
|
|
f.close();
|
|
}
|
|
else
|
|
{
|
|
std::cout << "file not found!" << std::endl;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
} |