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::shared_ptr
00042 RuleTableUTrie::
00043 GetOrCreateTargetPhraseCollection(const Phrase &source,
00044 const TargetPhrase &target,
00045 const Word *sourceLHS)
00046 {
00047 UTrieNode &currNode = GetOrCreateNode(source, target, sourceLHS);
00048 return currNode.GetOrCreateTargetPhraseCollection(target);
00049 }
00050
00051 UTrieNode &RuleTableUTrie::GetOrCreateNode(const Phrase &source,
00052 const TargetPhrase &target,
00053 const Word *)
00054 {
00055 const size_t size = source.GetSize();
00056
00057 const AlignmentInfo &alignmentInfo = target.GetAlignNonTerm();
00058 AlignmentInfo::const_iterator iterAlign = alignmentInfo.begin();
00059
00060 UTrieNode *currNode = &m_root;
00061 for (size_t pos = 0 ; pos < size ; ++pos) {
00062 const Word &word = source.GetWord(pos);
00063
00064 if (word.IsNonTerminal()) {
00065 assert(iterAlign != alignmentInfo.end());
00066 assert(iterAlign->first == pos);
00067 size_t targetNonTermInd = iterAlign->second;
00068 ++iterAlign;
00069 const Word &targetNonTerm = target.GetWord(targetNonTermInd);
00070 currNode = currNode->GetOrCreateNonTerminalChild(targetNonTerm);
00071 } else {
00072 currNode = currNode->GetOrCreateTerminalChild(word);
00073 }
00074
00075 assert(currNode != NULL);
00076 }
00077
00078 return *currNode;
00079 }
00080
00081 ChartRuleLookupManager *RuleTableUTrie::CreateRuleLookupManager(
00082 const ChartParser &parser,
00083 const ChartCellCollectionBase &cellCollection,
00084 std::size_t maxChartSpan)
00085 {
00086 return new Scope3Parser(parser, cellCollection, *this, maxChartSpan);
00087 }
00088
00089 void RuleTableUTrie::SortAndPrune()
00090 {
00091 if (GetTableLimit()) {
00092 m_root.Sort(GetTableLimit());
00093 }
00094 }
00095
00096 }