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