00001 /*********************************************************************** 00002 Moses - statistical machine translation system 00003 Copyright (C) 2006-2012 University of Edinburgh 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 ***********************************************************************/ 00019 00020 #include "ChartRuleLookupManagerCYKPlus.h" 00021 #include "DotChartInMemory.h" 00022 00023 #include "moses/InputType.h" 00024 #include "moses/StaticData.h" 00025 #include "moses/NonTerminal.h" 00026 #include "moses/ChartCellCollection.h" 00027 #include "moses/ChartParserCallback.h" 00028 #include "moses/TranslationModel/PhraseDictionaryMemory.h" 00029 00030 namespace Moses 00031 { 00032 00033 void ChartRuleLookupManagerCYKPlus::AddCompletedRule( 00034 const DottedRule &dottedRule, 00035 const TargetPhraseCollection &tpc, 00036 const Range &range, 00037 ChartParserCallback &outColl) 00038 { 00039 // Determine the rule's rank. 00040 size_t rank = 0; 00041 const DottedRule *node = &dottedRule; 00042 while (!node->IsRoot()) { 00043 if (node->IsNonTerminal()) { 00044 ++rank; 00045 } 00046 node = node->GetPrev(); 00047 } 00048 00049 // Fill m_stackVec with a stack pointer for each non-terminal. 00050 m_stackVec.resize(rank); 00051 node = &dottedRule; 00052 while (rank > 0) { 00053 if (node->IsNonTerminal()) { 00054 m_stackVec[--rank] = &node->GetChartCellLabel(); 00055 } 00056 node = node->GetPrev(); 00057 } 00058 00059 // Add the (TargetPhraseCollection, StackVec) pair to the collection. 00060 outColl.Add(tpc, m_stackVec, range); 00061 } 00062 00063 } // namespace Moses