00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "moses/NonTerminal.h"
00021 #include "moses/TranslationModel/Scope3Parser/Parser.h"
00022 #include "moses/StaticData.h"
00023 #include "moses/TargetPhrase.h"
00024 #include "moses/TargetPhraseCollection.h"
00025 #include "moses/Util.h"
00026 #include "moses/Word.h"
00027 #include "UTrie.h"
00028 #include "Trie.h"
00029 #include "UTrieNode.h"
00030
00031 #include <boost/functional/hash.hpp>
00032 #include <boost/unordered_map.hpp>
00033 #include <boost/version.hpp>
00034
00035 #include <map>
00036 #include <vector>
00037
00038 namespace Moses
00039 {
00040
00041 TargetPhraseCollection &RuleTableUTrie::GetOrCreateTargetPhraseCollection(
00042 const Phrase &source, const TargetPhrase &target, const Word &sourceLHS)
00043 {
00044 UTrieNode &currNode = GetOrCreateNode(source, target, sourceLHS);
00045 return currNode.GetOrCreateTargetPhraseCollection(target);
00046 }
00047
00048 UTrieNode &RuleTableUTrie::GetOrCreateNode(const Phrase &source,
00049 const TargetPhrase &target,
00050 const Word &)
00051 {
00052 const size_t size = source.GetSize();
00053
00054 const AlignmentInfo &alignmentInfo = target.GetAlignNonTerm();
00055 AlignmentInfo::const_iterator iterAlign = alignmentInfo.begin();
00056
00057 UTrieNode *currNode = &m_root;
00058 for (size_t pos = 0 ; pos < size ; ++pos) {
00059 const Word &word = source.GetWord(pos);
00060
00061 if (word.IsNonTerminal()) {
00062 assert(iterAlign != alignmentInfo.end());
00063 assert(iterAlign->first == pos);
00064 size_t targetNonTermInd = iterAlign->second;
00065 ++iterAlign;
00066 const Word &targetNonTerm = target.GetWord(targetNonTermInd);
00067 currNode = currNode->GetOrCreateNonTerminalChild(targetNonTerm);
00068 } else {
00069 currNode = currNode->GetOrCreateTerminalChild(word);
00070 }
00071
00072 assert(currNode != NULL);
00073 }
00074
00075 return *currNode;
00076 }
00077
00078 ChartRuleLookupManager *RuleTableUTrie::CreateRuleLookupManager(
00079 const InputType &sentence,
00080 const ChartCellCollectionBase &cellCollection)
00081 {
00082
00083 size_t maxChartSpan = 0;
00084 return new Scope3Parser(sentence, cellCollection, *this, maxChartSpan);
00085 }
00086
00087 void RuleTableUTrie::SortAndPrune()
00088 {
00089 if (GetTableLimit()) {
00090 m_root.Sort(GetTableLimit());
00091 }
00092 }
00093
00094 }