00001 #include "moses/LM/oxlm/OxLMParallelMapper.h" 00002 00003 #include "lbl/parallel_vocabulary.h" 00004 00005 #include "moses/FactorCollection.h" 00006 00007 using namespace std; 00008 00009 namespace Moses 00010 { 00011 00012 OxLMParallelMapper::OxLMParallelMapper( 00013 const boost::shared_ptr<oxlm::Vocabulary>& vocab, 00014 bool pos_back_off, 00015 const FactorType& pos_factor_type) 00016 : OxLMMapper(vocab, pos_back_off, pos_factor_type) 00017 { 00018 boost::shared_ptr<oxlm::ParallelVocabulary> parallel_vocab = 00019 dynamic_pointer_cast<oxlm::ParallelVocabulary>(vocab); 00020 assert(parallel_vocab != nullptr); 00021 00022 for (int i = 0; i < parallel_vocab->sourceSize(); ++i) { 00023 string word = parallel_vocab->convertSource(i); 00024 FactorCollection& fc = FactorCollection::Instance(); 00025 const Moses::Factor* factor = fc.AddFactor(word, false); 00026 moses2SourceOxlm[factor] = i; 00027 } 00028 00029 kSOURCE_UNKNOWN = parallel_vocab->convertSource("<unk>"); 00030 } 00031 00032 int OxLMParallelMapper::convertSource(const Word& word) const 00033 { 00034 const Moses::Factor* word_factor = word.GetFactor(0); 00035 Coll::const_iterator iter = moses2SourceOxlm.find(word_factor); 00036 if (posBackOff && iter == moses2SourceOxlm.end()) { 00037 const Moses::Factor* pos_factor = word.GetFactor(posFactorType); 00038 iter = moses2SourceOxlm.find(pos_factor); 00039 } 00040 return iter == moses2SourceOxlm.end() ? kSOURCE_UNKNOWN : iter->second; 00041 } 00042 00043 } // namespace Moses