00001 // $Id$ 00002 00003 /*********************************************************************** 00004 Moses - factored phrase-based language decoder 00005 Copyright (C) 2006 University of Edinburgh 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 ***********************************************************************/ 00021 00022 #include "PhraseDictionaryNode.h" 00023 #include "TargetPhrase.h" 00024 #include "PhraseDictionaryMemory.h" 00025 00026 namespace Moses 00027 { 00028 PhraseDictionaryNode::~PhraseDictionaryNode() 00029 { 00030 delete m_targetPhraseCollection; 00031 } 00032 00033 void PhraseDictionaryNode::Sort(size_t tableLimit) 00034 { 00035 // recusively sort 00036 NodeMap::iterator iter; 00037 for (iter = m_map.begin() ; iter != m_map.end() ; ++iter) { 00038 iter->second.Sort(tableLimit); 00039 } 00040 00041 // sort TargetPhraseCollection in this node 00042 if (m_targetPhraseCollection != NULL) 00043 m_targetPhraseCollection->NthElement(tableLimit); 00044 } 00045 00046 PhraseDictionaryNode *PhraseDictionaryNode::GetOrCreateChild(const Word &word) 00047 { 00048 NodeMap::iterator iter = m_map.find(word); 00049 if (iter != m_map.end()) 00050 return &iter->second; // found it 00051 00052 // can't find node. create a new 1 00053 return &(m_map[word] = PhraseDictionaryNode()); 00054 } 00055 00056 const PhraseDictionaryNode *PhraseDictionaryNode::GetChild(const Word &word) const 00057 { 00058 NodeMap::const_iterator iter = m_map.find(word); 00059 if (iter != m_map.end()) 00060 return &iter->second; // found it 00061 00062 // don't return anything 00063 return NULL; 00064 } 00065 00066 } 00067
1.5.9