00001 // -*- c++ -*- 00002 /*********************************************************************** 00003 Moses - factored phrase-based language decoder 00004 Copyright (C) 2010 University of Edinburgh 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 ***********************************************************************/ 00020 00021 #ifndef _MOCK_HYPOTHESIS_ 00022 #define _MOCK_HYPOTHESIS_ 00023 00024 #include <memory> 00025 #include <vector> 00026 00027 #include "moses/FF/UnknownWordPenaltyProducer.h" 00028 #include "moses/FF/DistortionScoreProducer.h" 00029 #include "moses/FF/WordPenaltyProducer.h" 00030 #include "Hypothesis.h" 00031 #include "Manager.h" 00032 #include "TranslationOption.h" 00033 00034 namespace MosesTest 00035 { 00036 00037 // 00038 // Construct a hypothesis with arbitrary source and target phrase 00039 // sequences. Useful for testing feature functions. 00040 // 00041 00042 typedef std::pair<size_t,size_t> Alignment; //(first,last) in source 00043 00044 class MockHypothesisGuard 00045 { 00046 public: 00049 MockHypothesisGuard 00050 ( const std::string& sourceSentence, 00051 const std::vector<Alignment>& alignments, 00052 const std::vector<std::string>& targetSegments); 00053 00054 Moses::Hypothesis* operator*() const { 00055 return m_hypothesis; 00056 } 00057 00059 ~MockHypothesisGuard(); 00060 00061 private: 00062 Moses::TranslationOption m_initialTransOpt; 00063 boost::shared_ptr<Moses::Sentence> m_sentence; 00064 Moses::WordPenaltyProducer m_wp; 00065 Moses::UnknownWordPenaltyProducer m_uwp; 00066 Moses::DistortionScoreProducer m_dist; 00067 boost::shared_ptr<Moses::Manager> m_manager; 00068 boost::shared_ptr<Moses::TranslationTask> m_ttask; 00069 Moses::Hypothesis* m_hypothesis; 00070 std::vector<Moses::TargetPhrase> m_targetPhrases; 00071 std::vector<Moses::TranslationOption*> m_toptions; 00072 }; 00073 00074 class HypothesisFixture 00075 { 00076 public: 00077 HypothesisFixture(); 00078 const Moses::Hypothesis* empty() { 00079 return **m_empty; 00080 } 00081 const Moses::Hypothesis* partial() { 00082 return **m_partial; 00083 } 00084 const Moses::Hypothesis* full() { 00085 return **m_full; 00086 } 00087 00088 private: 00089 std::auto_ptr<MockHypothesisGuard> m_empty; 00090 std::auto_ptr<MockHypothesisGuard> m_partial; 00091 std::auto_ptr<MockHypothesisGuard> m_full; 00092 }; 00093 00094 00095 } 00096 00097 #endif