00001 /*********************************************************************** 00002 Moses - factored phrase-based language decoder 00003 Copyright (C) 2011 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 #pragma once 00021 00022 #include <vector> 00023 00024 #include "ChartRuleLookupManagerCYKPlus.h" 00025 #include "CompletedRuleCollection.h" 00026 #include "moses/NonTerminal.h" 00027 #include "moses/TranslationModel/PhraseDictionaryMemory.h" 00028 #include "moses/TranslationModel/PhraseDictionaryNodeMemory.h" 00029 #include "moses/StackVec.h" 00030 00031 namespace Moses 00032 { 00033 00034 class ChartParserCallback; 00035 class Range; 00036 00038 class ChartRuleLookupManagerMemory : public ChartRuleLookupManagerCYKPlus 00039 { 00040 public: 00041 typedef std::vector<ChartCellCache> CompressedColumn; 00042 typedef std::vector<CompressedColumn> CompressedMatrix; 00043 00044 00045 ChartRuleLookupManagerMemory(const ChartParser &parser, 00046 const ChartCellCollectionBase &cellColl, 00047 const PhraseDictionaryMemory &ruleTable); 00048 00049 ~ChartRuleLookupManagerMemory() {}; 00050 00051 virtual void GetChartRuleCollection( 00052 const InputPath &inputPath, 00053 size_t lastPos, // last position to consider if using lookahead 00054 ChartParserCallback &outColl); 00055 00056 private: 00057 00058 void GetTerminalExtension( 00059 const PhraseDictionaryNodeMemory *node, 00060 size_t pos); 00061 00062 void GetNonTerminalExtension( 00063 const PhraseDictionaryNodeMemory *node, 00064 size_t startPos); 00065 00066 void AddAndExtend( 00067 const PhraseDictionaryNodeMemory *node, 00068 size_t endPos); 00069 00070 void UpdateCompressedMatrix(size_t startPos, 00071 size_t endPos, 00072 size_t lastPos); 00073 00074 const PhraseDictionaryMemory &m_ruleTable; 00075 00076 // permissible soft nonterminal matches (target side) 00077 bool m_isSoftMatching; 00078 const std::vector<std::vector<Word> >& m_softMatchingMap; 00079 00080 // temporary storage of completed rules (one collection per end position; all rules collected consecutively start from the same position) 00081 std::vector<CompletedRuleCollection> m_completedRules; 00082 00083 size_t m_lastPos; 00084 size_t m_unaryPos; 00085 00086 StackVec m_stackVec; 00087 std::vector<float> m_stackScores; 00088 std::vector<const Word*> m_sourceWords; 00089 ChartParserCallback* m_outColl; 00090 00091 std::vector<CompressedMatrix> m_compressedMatrixVec; 00092 00093 00094 }; 00095 00096 } // namespace Moses 00097