|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/property_tree/ptree.hpp> |
|
|
#include <boost/property_tree/xml_parser.hpp> |
|
|
#include <boost/algorithm/string.hpp> |
|
|
|
|
|
#include "SentenceWithCandidates.h" |
|
|
#include "../System.h" |
|
|
#include "../parameters/AllOptions.h" |
|
|
#include "../legacy/Util2.h" |
|
|
#include <unordered_map> |
|
|
|
|
|
using namespace std; |
|
|
using namespace boost; |
|
|
|
|
|
namespace Moses2 |
|
|
{ |
|
|
|
|
|
const string SentenceWithCandidates::INPUT_PART_DELIM = "@@@"; |
|
|
const string SentenceWithCandidates::PT_LINE_DELIM = "$$$"; |
|
|
|
|
|
SentenceWithCandidates *SentenceWithCandidates::CreateFromString(MemPool &pool, FactorCollection &vocab, |
|
|
const System &system, const std::string &str) |
|
|
{ |
|
|
SentenceWithCandidates *ret; |
|
|
|
|
|
|
|
|
typedef split_iterator<string::const_iterator> string_split_iterator; |
|
|
vector<string> input_parts; |
|
|
for(string_split_iterator It= make_split_iterator(str, first_finder(SentenceWithCandidates::INPUT_PART_DELIM, is_iequal())); |
|
|
It!=string_split_iterator(); |
|
|
++It) |
|
|
{ |
|
|
input_parts.push_back(copy_range<std::string>(*It)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (input_parts.size() ==2 ) { |
|
|
|
|
|
} else { |
|
|
|
|
|
cerr << "INCORRECT number of parts" << endl ; |
|
|
exit(1); |
|
|
} |
|
|
|
|
|
trim(input_parts[0]); |
|
|
trim(input_parts[1]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const string partstr = input_parts[0]; |
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> toks = Tokenize(partstr); |
|
|
|
|
|
size_t size = toks.size(); |
|
|
ret = new (pool.Allocate<SentenceWithCandidates>()) SentenceWithCandidates(pool, size); |
|
|
ret->PhraseImplTemplate<Word>::CreateFromString(vocab, system, toks, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret->m_phraseTableString = replace_all_copy(input_parts[1],PT_LINE_DELIM,"\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
} |
|
|
|
|
|
SentenceWithCandidates::SentenceWithCandidates(MemPool &pool, size_t size) |
|
|
:Sentence(pool, size) |
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
SentenceWithCandidates::~SentenceWithCandidates() |
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
std::string SentenceWithCandidates::Debug(const System &system) const |
|
|
{ |
|
|
return "SentenceWithCandidates::Debug"; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|