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