2012-07-18 17:52:48 +04:00
|
|
|
// vim:tabstop=2
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 University of Edinburgh
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-07-18 17:52:48 +04:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-07-18 17:52:48 +04:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-07-18 17:52:48 +04:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2015-03-28 16:09:03 +03:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <climits>
|
2012-10-08 23:52:27 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
2012-07-18 17:52:48 +04:00
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
2012-11-12 23:56:18 +04:00
|
|
|
#include "Loader.h"
|
|
|
|
#include "LoaderFactory.h"
|
2012-08-14 02:53:14 +04:00
|
|
|
#include "PhraseDictionaryFuzzyMatch.h"
|
2012-11-12 23:56:18 +04:00
|
|
|
#include "moses/FactorCollection.h"
|
|
|
|
#include "moses/Word.h"
|
|
|
|
#include "moses/Util.h"
|
|
|
|
#include "moses/InputFileStream.h"
|
|
|
|
#include "moses/StaticData.h"
|
|
|
|
#include "moses/WordsRange.h"
|
2012-11-27 21:23:31 +04:00
|
|
|
#include "moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerMemoryPerSentence.h"
|
2013-06-01 02:39:19 +04:00
|
|
|
#include "moses/TranslationModel/fuzzy-match/FuzzyMatchWrapper.h"
|
|
|
|
#include "moses/TranslationModel/fuzzy-match/SentenceAlignment.h"
|
2013-09-22 20:24:32 +04:00
|
|
|
#include "util/file.hh"
|
|
|
|
#include "util/exception.hh"
|
2015-04-23 15:27:21 +03:00
|
|
|
#include "util/random.hh"
|
2012-07-18 17:52:48 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2013-12-19 00:15:39 +04:00
|
|
|
#if defined __MINGW32__ && !defined mkdtemp
|
|
|
|
#include <windows.h>
|
2015-03-28 16:09:03 +03:00
|
|
|
#include <cerrno>
|
2014-05-19 17:35:45 +04:00
|
|
|
char *mkdtemp(char *tempbuf)
|
|
|
|
{
|
2013-12-19 00:15:39 +04:00
|
|
|
int rand_value = 0;
|
|
|
|
char* tempbase = NULL;
|
|
|
|
char tempbasebuf[MAX_PATH] = "";
|
|
|
|
|
|
|
|
if (strcmp(&tempbuf[strlen(tempbuf)-6], "XXXXXX")) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-23 15:27:21 +03:00
|
|
|
util::rand_init();
|
2015-04-23 20:22:25 +03:00
|
|
|
rand_value = util::rand_excl(1e6);
|
2013-12-19 00:15:39 +04:00
|
|
|
tempbase = strrchr(tempbuf, '/');
|
|
|
|
tempbase = tempbase ? tempbase+1 : tempbuf;
|
|
|
|
strcpy(tempbasebuf, tempbase);
|
|
|
|
sprintf(&tempbasebuf[strlen(tempbasebuf)-6], "%d", rand_value);
|
|
|
|
::GetTempPath(MAX_PATH, tempbuf);
|
|
|
|
strcat(tempbuf, tempbasebuf);
|
|
|
|
::CreateDirectory(tempbuf, NULL);
|
|
|
|
return tempbuf;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-18 17:52:48 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2012-07-27 03:10:49 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
PhraseDictionaryFuzzyMatch::PhraseDictionaryFuzzyMatch(const std::string &line)
|
2013-10-29 22:20:55 +04:00
|
|
|
:PhraseDictionary(line)
|
2013-12-06 18:23:22 +04:00
|
|
|
,m_config(3)
|
2014-05-31 17:33:31 +04:00
|
|
|
,m_FuzzyMatchWrapper(NULL)
|
2013-06-11 04:46:04 +04:00
|
|
|
{
|
2013-11-20 21:19:57 +04:00
|
|
|
ReadParameters();
|
2013-06-11 04:46:04 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2013-06-01 02:39:19 +04:00
|
|
|
PhraseDictionaryFuzzyMatch::~PhraseDictionaryFuzzyMatch()
|
2013-05-29 21:16:15 +04:00
|
|
|
{
|
2013-06-01 02:39:19 +04:00
|
|
|
delete m_FuzzyMatchWrapper;
|
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2013-06-01 02:39:19 +04:00
|
|
|
void PhraseDictionaryFuzzyMatch::Load()
|
|
|
|
{
|
2013-06-14 21:34:47 +04:00
|
|
|
SetFeaturesToApply();
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
m_FuzzyMatchWrapper = new tmmt::FuzzyMatchWrapper(m_config[0], m_config[1], m_config[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ChartRuleLookupManager *PhraseDictionaryFuzzyMatch::CreateRuleLookupManager(
|
2013-07-31 15:25:34 +04:00
|
|
|
const ChartParser &parser,
|
2014-03-14 12:49:09 +04:00
|
|
|
const ChartCellCollectionBase &cellCollection,
|
|
|
|
std::size_t /*maxChartSpan*/)
|
2013-05-29 21:16:15 +04:00
|
|
|
{
|
2013-07-31 15:25:34 +04:00
|
|
|
return new ChartRuleLookupManagerMemoryPerSentence(parser, cellCollection, *this);
|
2013-05-29 21:16:15 +04:00
|
|
|
}
|
|
|
|
|
2013-12-06 18:23:22 +04:00
|
|
|
void
|
|
|
|
PhraseDictionaryFuzzyMatch::
|
|
|
|
SetParameter(const std::string& key, const std::string& value)
|
|
|
|
{
|
|
|
|
if (key == "source") {
|
2014-01-15 19:49:57 +04:00
|
|
|
m_config[0] = value;
|
2013-12-06 18:23:22 +04:00
|
|
|
} else if (key == "target") {
|
2014-01-15 19:49:57 +04:00
|
|
|
m_config[1] = value;
|
2013-12-06 18:23:22 +04:00
|
|
|
} else if (key == "alignment") {
|
2014-01-15 19:49:57 +04:00
|
|
|
m_config[2] = value;
|
2013-12-06 18:23:22 +04:00
|
|
|
} else {
|
2014-01-15 19:49:57 +04:00
|
|
|
PhraseDictionary::SetParameter(key, value);
|
2013-12-06 18:23:22 +04:00
|
|
|
}
|
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
int removedirectoryrecursively(const char *dirname)
|
|
|
|
{
|
2013-12-19 00:15:39 +04:00
|
|
|
#if defined __MINGW32__
|
2014-05-19 17:35:45 +04:00
|
|
|
//TODO(jie): replace this function with boost implementation
|
2013-12-19 00:15:39 +04:00
|
|
|
#else
|
2013-05-29 21:16:15 +04:00
|
|
|
DIR *dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
|
|
|
dir = opendir(dirname);
|
|
|
|
if (dir == NULL) {
|
|
|
|
perror("Error opendir()");
|
|
|
|
return 0;
|
2012-07-18 17:52:48 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
while ((entry = readdir(dir)) != NULL) {
|
|
|
|
if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
|
|
|
|
snprintf(path, (size_t) PATH_MAX, "%s/%s", dirname, entry->d_name);
|
|
|
|
if (entry->d_type == DT_DIR) {
|
|
|
|
removedirectoryrecursively(path);
|
2012-10-08 23:52:27 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
remove(path);
|
|
|
|
/*
|
|
|
|
* Here, the actual deletion must be done. Beacuse this is
|
|
|
|
* quite a dangerous thing to do, and this program is not very
|
|
|
|
* well tested, we are just printing as if we are deleting.
|
|
|
|
*/
|
|
|
|
//printf("(not really) Deleting: %s\n", path);
|
|
|
|
/*
|
|
|
|
* When you are finished testing this and feel you are ready to do the real
|
|
|
|
* deleting, use this: remove*STUB*(path);
|
|
|
|
* (see "man 3 remove")
|
|
|
|
* Please note that I DONT TAKE RESPONSIBILITY for data you delete with this!
|
|
|
|
*/
|
2012-10-08 23:52:27 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
|
|
|
|
rmdir(dirname);
|
|
|
|
/*
|
|
|
|
* Now the directory is emtpy, finally delete the directory itself. (Just
|
|
|
|
* printing here, see above)
|
|
|
|
*/
|
|
|
|
//printf("(not really) Deleting: %s\n", dirname);
|
2013-12-19 00:15:39 +04:00
|
|
|
#endif
|
2013-05-29 21:16:15 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryFuzzyMatch::InitializeForInput(InputType const& inputSentence)
|
|
|
|
{
|
2013-12-19 00:15:39 +04:00
|
|
|
#if defined __MINGW32__
|
|
|
|
char dirName[] = "moses.XXXXXX";
|
|
|
|
#else
|
2013-05-29 21:16:15 +04:00
|
|
|
char dirName[] = "/tmp/moses.XXXXXX";
|
2013-12-19 00:15:39 +04:00
|
|
|
#endif // defined
|
2013-05-29 21:16:15 +04:00
|
|
|
char *temp = mkdtemp(dirName);
|
2013-11-23 00:27:46 +04:00
|
|
|
UTIL_THROW_IF2(temp == NULL,
|
2014-01-15 19:49:57 +04:00
|
|
|
"Couldn't create temporary directory " << dirName);
|
2013-11-20 21:19:57 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
string dirNameStr(dirName);
|
|
|
|
|
|
|
|
string inFileName(dirNameStr + "/in");
|
|
|
|
|
|
|
|
ofstream inFile(inFileName.c_str());
|
|
|
|
|
|
|
|
for (size_t i = 1; i < inputSentence.GetSize() - 1; ++i) {
|
|
|
|
inFile << inputSentence.GetWord(i);
|
2012-10-08 23:52:27 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
inFile << endl;
|
|
|
|
inFile.close();
|
|
|
|
|
|
|
|
long translationId = inputSentence.GetTranslationId();
|
|
|
|
string ptFileName = m_FuzzyMatchWrapper->Extract(translationId, dirNameStr);
|
|
|
|
|
|
|
|
// populate with rules for this sentence
|
|
|
|
PhraseDictionaryNodeMemory &rootNode = m_collection[translationId];
|
|
|
|
FormatType format = MosesFormat;
|
2012-10-08 23:52:27 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
// data from file
|
|
|
|
InputFileStream inStream(ptFileName);
|
|
|
|
|
|
|
|
// copied from class LoaderStandard
|
|
|
|
PrintUserTime("Start loading fuzzy-match phrase model");
|
|
|
|
|
|
|
|
const StaticData &staticData = StaticData::Instance();
|
|
|
|
|
|
|
|
|
|
|
|
string lineOrig;
|
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
while(getline(inStream, lineOrig)) {
|
|
|
|
const string *line;
|
|
|
|
if (format == HieroFormat) { // reformat line
|
2013-09-22 20:24:32 +04:00
|
|
|
UTIL_THROW(util::Exception, "Cannot be Hiero format");
|
2013-05-29 21:16:15 +04:00
|
|
|
//line = ReformatHieroRule(lineOrig);
|
|
|
|
} else {
|
|
|
|
// do nothing to format of line
|
|
|
|
line = &lineOrig;
|
2012-07-19 22:36:46 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
vector<string> tokens;
|
|
|
|
vector<float> scoreVector;
|
|
|
|
|
|
|
|
TokenizeMultiCharSeparator(tokens, *line , "|||" );
|
|
|
|
|
|
|
|
if (tokens.size() != 4 && tokens.size() != 5) {
|
2014-01-13 22:32:22 +04:00
|
|
|
UTIL_THROW2("Syntax error at " << ptFileName << ":" << count);
|
2012-07-23 15:26:15 +04:00
|
|
|
}
|
2012-07-23 17:07:36 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
const string &sourcePhraseString = tokens[0]
|
|
|
|
, &targetPhraseString = tokens[1]
|
|
|
|
, &scoreString = tokens[2]
|
|
|
|
, &alignString = tokens[3];
|
|
|
|
|
|
|
|
bool isLHSEmpty = (sourcePhraseString.find_first_not_of(" \t", 0) == string::npos);
|
|
|
|
if (isLHSEmpty && !staticData.IsWordDeletionEnabled()) {
|
|
|
|
TRACE_ERR( ptFileName << ":" << count << ": pt entry contains empty target, skipping\n");
|
|
|
|
continue;
|
2012-07-23 17:07:36 +04:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
Tokenize<float>(scoreVector, scoreString);
|
|
|
|
const size_t numScoreComponents = GetNumScoreComponents();
|
|
|
|
if (scoreVector.size() != numScoreComponents) {
|
2014-01-13 22:32:22 +04:00
|
|
|
UTIL_THROW2("Size of scoreVector != number (" << scoreVector.size() << "!="
|
2014-01-15 19:49:57 +04:00
|
|
|
<< numScoreComponents << ") of score components on line " << count);
|
2012-07-23 17:07:36 +04:00
|
|
|
}
|
2013-11-20 21:19:57 +04:00
|
|
|
|
2013-11-23 00:27:46 +04:00
|
|
|
UTIL_THROW_IF2(scoreVector.size() != numScoreComponents,
|
2014-01-15 19:49:57 +04:00
|
|
|
"Number of scores incorrectly specified");
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
// parse source & find pt node
|
|
|
|
|
|
|
|
// constituent labels
|
|
|
|
Word *sourceLHS;
|
|
|
|
Word *targetLHS;
|
|
|
|
|
|
|
|
// source
|
|
|
|
Phrase sourcePhrase( 0);
|
2014-05-31 17:33:31 +04:00
|
|
|
sourcePhrase.CreateFromString(Input, m_input, sourcePhraseString, &sourceLHS);
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
// create target phrase obj
|
2014-08-04 22:28:04 +04:00
|
|
|
TargetPhrase *targetPhrase = new TargetPhrase(this);
|
2014-05-31 17:33:31 +04:00
|
|
|
targetPhrase->CreateFromString(Output, m_output, targetPhraseString, &targetLHS);
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
// rest of target phrase
|
|
|
|
targetPhrase->SetAlignmentInfo(alignString);
|
|
|
|
targetPhrase->SetTargetLHS(targetLHS);
|
|
|
|
//targetPhrase->SetDebugOutput(string("New Format pt ") + line);
|
|
|
|
|
|
|
|
// component score, for n-best output
|
|
|
|
std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),TransformScore);
|
|
|
|
std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),FloorScore);
|
|
|
|
|
|
|
|
targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
|
2014-08-08 18:59:34 +04:00
|
|
|
targetPhrase->EvaluateInIsolation(sourcePhrase, GetFeaturesToApply());
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(rootNode, sourcePhrase, *targetPhrase, sourceLHS);
|
|
|
|
phraseColl.Add(targetPhrase);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (format == HieroFormat) { // reformat line
|
|
|
|
delete line;
|
|
|
|
} else {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2012-07-18 20:59:21 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
|
|
|
// sort and prune each target phrase collection
|
|
|
|
SortAndPrune(rootNode);
|
|
|
|
|
|
|
|
//removedirectoryrecursively(dirName);
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetPhraseCollection &PhraseDictionaryFuzzyMatch::GetOrCreateTargetPhraseCollection(PhraseDictionaryNodeMemory &rootNode
|
|
|
|
, const Phrase &source
|
|
|
|
, const TargetPhrase &target
|
|
|
|
, const Word *sourceLHS)
|
|
|
|
{
|
|
|
|
PhraseDictionaryNodeMemory &currNode = GetOrCreateNode(rootNode, source, target, sourceLHS);
|
2013-07-16 19:55:56 +04:00
|
|
|
return currNode.GetTargetPhraseCollection();
|
2013-05-29 21:16:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PhraseDictionaryNodeMemory &PhraseDictionaryFuzzyMatch::GetOrCreateNode(PhraseDictionaryNodeMemory &rootNode
|
|
|
|
, const Phrase &source
|
|
|
|
, const TargetPhrase &target
|
|
|
|
, const Word *sourceLHS)
|
|
|
|
{
|
|
|
|
cerr << source << endl << target << endl;
|
|
|
|
const size_t size = source.GetSize();
|
|
|
|
|
|
|
|
const AlignmentInfo &alignmentInfo = target.GetAlignNonTerm();
|
|
|
|
AlignmentInfo::const_iterator iterAlign = alignmentInfo.begin();
|
|
|
|
|
|
|
|
PhraseDictionaryNodeMemory *currNode = &rootNode;
|
|
|
|
for (size_t pos = 0 ; pos < size ; ++pos) {
|
|
|
|
const Word& word = source.GetWord(pos);
|
|
|
|
|
|
|
|
if (word.IsNonTerminal()) {
|
|
|
|
// indexed by source label 1st
|
|
|
|
const Word &sourceNonTerm = word;
|
|
|
|
|
2013-11-23 00:27:46 +04:00
|
|
|
UTIL_THROW_IF2(iterAlign == alignmentInfo.end(),
|
2014-01-15 19:49:57 +04:00
|
|
|
"No alignment for non-term at position " << pos);
|
2013-11-23 00:27:46 +04:00
|
|
|
UTIL_THROW_IF2(iterAlign->first != pos,
|
2014-01-15 19:49:57 +04:00
|
|
|
"Alignment info incorrect at position " << pos);
|
2013-11-20 21:19:57 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
size_t targetNonTermInd = iterAlign->second;
|
|
|
|
++iterAlign;
|
|
|
|
const Word &targetNonTerm = target.GetWord(targetNonTermInd);
|
|
|
|
|
2014-03-21 14:53:15 +04:00
|
|
|
#if defined(UNLABELLED_SOURCE)
|
|
|
|
currNode = currNode->GetOrCreateNonTerminalChild(targetNonTerm);
|
|
|
|
#else
|
2013-05-29 21:16:15 +04:00
|
|
|
currNode = currNode->GetOrCreateChild(sourceNonTerm, targetNonTerm);
|
2014-03-21 14:53:15 +04:00
|
|
|
#endif
|
2013-05-29 21:16:15 +04:00
|
|
|
} else {
|
|
|
|
currNode = currNode->GetOrCreateChild(word);
|
|
|
|
}
|
|
|
|
|
2013-11-23 00:27:46 +04:00
|
|
|
UTIL_THROW_IF2(currNode == NULL,
|
2014-01-15 19:49:57 +04:00
|
|
|
"Node not found at position " << pos);
|
2013-11-20 21:19:57 +04:00
|
|
|
|
2012-07-19 21:59:50 +04:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
// finally, the source LHS
|
|
|
|
//currNode = currNode->GetOrCreateChild(sourceLHS);
|
|
|
|
|
|
|
|
return *currNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryFuzzyMatch::SortAndPrune(PhraseDictionaryNodeMemory &rootNode)
|
|
|
|
{
|
|
|
|
if (GetTableLimit()) {
|
|
|
|
rootNode.Sort(GetTableLimit());
|
2012-07-19 21:59:50 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryFuzzyMatch::CleanUpAfterSentenceProcessing(const InputType &source)
|
|
|
|
{
|
|
|
|
m_collection.erase(source.GetTranslationId());
|
|
|
|
}
|
|
|
|
|
2013-08-02 21:09:47 +04:00
|
|
|
const PhraseDictionaryNodeMemory &PhraseDictionaryFuzzyMatch::GetRootNode(long translationId) const
|
2013-05-29 21:16:15 +04:00
|
|
|
{
|
2013-08-02 21:09:47 +04:00
|
|
|
std::map<long, PhraseDictionaryNodeMemory>::const_iterator iter = m_collection.find(translationId);
|
2013-11-23 00:27:46 +04:00
|
|
|
UTIL_THROW_IF2(iter == m_collection.end(),
|
2014-01-15 19:49:57 +04:00
|
|
|
"Couldn't find root node for input: " << translationId);
|
2013-05-29 21:16:15 +04:00
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
PhraseDictionaryNodeMemory &PhraseDictionaryFuzzyMatch::GetRootNode(const InputType &source)
|
|
|
|
{
|
|
|
|
long transId = source.GetTranslationId();
|
|
|
|
std::map<long, PhraseDictionaryNodeMemory>::iterator iter = m_collection.find(transId);
|
2013-11-23 00:27:46 +04:00
|
|
|
UTIL_THROW_IF2(iter == m_collection.end(),
|
2014-01-15 19:49:57 +04:00
|
|
|
"Couldn't find root node for input: " << transId);
|
2013-05-29 21:16:15 +04:00
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
TO_STRING_BODY(PhraseDictionaryFuzzyMatch);
|
|
|
|
|
|
|
|
// friend
|
|
|
|
ostream& operator<<(ostream& out, const PhraseDictionaryFuzzyMatch& phraseDict)
|
|
|
|
{
|
2015-03-29 14:10:51 +03:00
|
|
|
/*
|
2013-05-29 21:16:15 +04:00
|
|
|
typedef PhraseDictionaryNodeMemory::TerminalMap TermMap;
|
|
|
|
typedef PhraseDictionaryNodeMemory::NonTerminalMap NonTermMap;
|
|
|
|
|
|
|
|
const PhraseDictionaryNodeMemory &coll = phraseDict.m_collection;
|
|
|
|
for (NonTermMap::const_iterator p = coll.m_nonTermMap.begin(); p != coll.m_nonTermMap.end(); ++p) {
|
|
|
|
const Word &sourceNonTerm = p->first.first;
|
|
|
|
out << sourceNonTerm;
|
2012-07-18 20:59:21 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
for (TermMap::const_iterator p = coll.m_sourceTermMap.begin(); p != coll.m_sourceTermMap.end(); ++p) {
|
|
|
|
const Word &sourceTerm = p->first;
|
|
|
|
out << sourceTerm;
|
2012-07-18 17:52:48 +04:00
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2012-07-18 17:52:48 +04:00
|
|
|
}
|