00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ApplicableRuleTrie.h"
00021
00022 namespace Moses
00023 {
00024
00025 void ApplicableRuleTrie::Extend(const UTrieNode &root, int minPos,
00026 const SentenceMap &sentMap, bool followsGap)
00027 {
00028 const UTrieNode::TerminalMap &termMap = root.GetTerminalMap();
00029 for (UTrieNode::TerminalMap::const_iterator p = termMap.begin();
00030 p != termMap.end(); ++p) {
00031 const Word &word = p->first;
00032 const UTrieNode &child = p->second;
00033 SentenceMap::const_iterator q = sentMap.find(word);
00034 if (q == sentMap.end()) {
00035 continue;
00036 }
00037 for (std::vector<size_t>::const_iterator r = q->second.begin();
00038 r != q->second.end(); ++r) {
00039 size_t index = *r;
00040 if (index == (size_t)minPos || (followsGap && index > (size_t)minPos) || minPos == -1) {
00041 ApplicableRuleTrie *subTrie = new ApplicableRuleTrie(index, index,
00042 child);
00043 subTrie->Extend(child, index+1, sentMap, false);
00044 m_children.push_back(subTrie);
00045 }
00046 }
00047 }
00048
00049 const UTrieNode *child = root.GetNonTerminalChild();
00050 if (!child) {
00051 return;
00052 }
00053 int start = followsGap ? -1 : minPos;
00054 ApplicableRuleTrie *subTrie = new ApplicableRuleTrie(start, -1, *child);
00055 int newMinPos = (minPos == -1 ? 1 : minPos+1);
00056 subTrie->Extend(*child, newMinPos, sentMap, true);
00057 m_children.push_back(subTrie);
00058 }
00059
00060 }