2011-01-13 03:25:10 +03:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2011 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Factor.h"
|
|
|
|
#include "Word.h"
|
|
|
|
|
2013-08-02 18:54:49 +04:00
|
|
|
#include <iostream>
|
2011-01-13 03:25:10 +03:00
|
|
|
#include <boost/functional/hash.hpp>
|
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
2011-11-08 19:43:07 +04:00
|
|
|
|
2012-06-29 02:29:46 +04:00
|
|
|
/** Functor to create hash for words.
|
|
|
|
* @todo uses all factors, not just factor 0
|
|
|
|
*/
|
2011-01-13 03:25:10 +03:00
|
|
|
class NonTerminalHasher
|
|
|
|
{
|
|
|
|
public:
|
2011-02-24 16:14:42 +03:00
|
|
|
size_t operator()(const Word & k) const {
|
|
|
|
// Assumes that only the first factor is relevant.
|
|
|
|
const Factor * f = k[0];
|
|
|
|
return hash_value(*f);
|
|
|
|
}
|
2011-01-13 03:25:10 +03:00
|
|
|
};
|
|
|
|
|
2012-06-29 02:29:46 +04:00
|
|
|
/** Functor to test whether 2 words are the same
|
|
|
|
* @todo uses all factors, not just factor 0
|
|
|
|
*/
|
2011-01-13 03:25:10 +03:00
|
|
|
class NonTerminalEqualityPred
|
|
|
|
{
|
|
|
|
public:
|
2011-02-24 16:14:42 +03:00
|
|
|
bool operator()(const Word & k1, const Word & k2) const {
|
|
|
|
// Assumes that only the first factor is relevant.
|
|
|
|
const Factor * f1 = k1[0];
|
|
|
|
const Factor * f2 = k2[0];
|
|
|
|
return !(f1->Compare(*f2));
|
|
|
|
}
|
2011-01-13 03:25:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef boost::unordered_set<Word,
|
2011-02-24 16:14:42 +03:00
|
|
|
NonTerminalHasher,
|
|
|
|
NonTerminalEqualityPred> NonTerminalSet;
|
2011-01-13 03:25:10 +03:00
|
|
|
|
2013-08-02 18:54:49 +04:00
|
|
|
std::ostream& operator<<(std::ostream&, const NonTerminalSet&);
|
|
|
|
|
2011-01-13 03:25:10 +03:00
|
|
|
} // namespace Moses
|