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 "Factor.h" 00023 #include "Word.h" 00024 00025 #include <boost/functional/hash.hpp> 00026 #include <boost/unordered_set.hpp> 00027 00028 #include <set> 00029 00030 namespace Moses 00031 { 00032 00036 class NonTerminalHasher 00037 { 00038 public: 00039 size_t operator()(const Word & k) const { 00040 // Assumes that only the first factor is relevant. 00041 const Factor * f = k[0]; 00042 return hash_value(*f); 00043 } 00044 }; 00045 00049 class NonTerminalEqualityPred 00050 { 00051 public: 00052 bool operator()(const Word & k1, const Word & k2) const { 00053 // Assumes that only the first factor is relevant. 00054 const Factor * f1 = k1[0]; 00055 const Factor * f2 = k2[0]; 00056 return !(f1->Compare(*f2)); 00057 } 00058 }; 00059 00060 typedef boost::unordered_set<Word, 00061 NonTerminalHasher, 00062 NonTerminalEqualityPred> NonTerminalSet; 00063 00064 } // namespace Moses
1.5.9