Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/moses
diff options
context:
space:
mode:
authorheafield <heafield@1f5c12ca-751b-0410-a591-d2e778427230>2011-10-13 17:32:14 +0400
committerheafield <heafield@1f5c12ca-751b-0410-a591-d2e778427230>2011-10-13 17:32:14 +0400
commita95e7910565252e8eae90b35c95380962970b81e (patch)
tree914c3997070b3367dcb86b2c0b600773acb37754 /moses
parentf08424840530575aaf349fc01397a07678b8cbf5 (diff)
Back to using StringPiece
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@4349 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'moses')
-rw-r--r--moses/src/FactorCollection.cpp2
-rw-r--r--moses/src/FactorCollection.h11
-rw-r--r--moses/src/LanguageModelKen.cpp5
3 files changed, 8 insertions, 10 deletions
diff --git a/moses/src/FactorCollection.cpp b/moses/src/FactorCollection.cpp
index eeeffcd0d..4cc8a136f 100644
--- a/moses/src/FactorCollection.cpp
+++ b/moses/src/FactorCollection.cpp
@@ -33,7 +33,7 @@ namespace Moses
{
FactorCollection FactorCollection::s_instance;
-const Factor *FactorCollection::AddFactor(const string &factorString)
+const Factor *FactorCollection::AddFactor(const StringPiece &factorString)
{
// Sorry this is so complicated. Can't we just require everybody to use Boost >= 1.42? The issue is that I can't check BOOST_VERSION unless we have Boost.
#ifdef WITH_THREADS
diff --git a/moses/src/FactorCollection.h b/moses/src/FactorCollection.h
index 14d8d5c36..0281844d4 100644
--- a/moses/src/FactorCollection.h
+++ b/moses/src/FactorCollection.h
@@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <functional>
#include <string>
+#include "util/string_piece.hh"
#include "Factor.h"
namespace Moses
@@ -70,7 +71,7 @@ class FactorCollection
#ifdef HAVE_BOOST
struct HashFactor : public std::unary_function<const FactorFriend &, std::size_t> {
- std::size_t operator()(const std::string &str) const {
+ std::size_t operator()(const StringPiece &str) const {
return util::MurmurHashNative(str.data(), str.size());
}
std::size_t operator()(const FactorFriend &factor) const {
@@ -81,10 +82,10 @@ class FactorCollection
bool operator()(const FactorFriend &left, const FactorFriend &right) const {
return left.in.GetString() == right.in.GetString();
}
- bool operator()(const FactorFriend &left, const std::string &right) const {
+ bool operator()(const FactorFriend &left, const StringPiece &right) const {
return left.in.GetString() == right;
}
- bool operator()(const std::string &left, const FactorFriend &right) const {
+ bool operator()(const StringPiece &left, const FactorFriend &right) const {
return left == right.in.GetString();
}
};
@@ -122,10 +123,10 @@ public:
/** returns a factor with the same direction, factorType and factorString.
* If a factor already exist in the collection, return the existing factor, if not create a new 1
*/
- const Factor *AddFactor(const std::string &factorString);
+ const Factor *AddFactor(const StringPiece &factorString);
// TODO: remove calls to this function, replacing them with the simpler AddFactor(factorString)
- const Factor *AddFactor(FactorDirection /*direction*/, FactorType /*factorType*/, const std::string &factorString) {
+ const Factor *AddFactor(FactorDirection /*direction*/, FactorType /*factorType*/, const StringPiece &factorString) {
return AddFactor(factorString);
}
diff --git a/moses/src/LanguageModelKen.cpp b/moses/src/LanguageModelKen.cpp
index 596378f17..8e2cde4c9 100644
--- a/moses/src/LanguageModelKen.cpp
+++ b/moses/src/LanguageModelKen.cpp
@@ -141,8 +141,7 @@ public:
: m_factorCollection(factorCollection), m_mapping(mapping) {}
void Add(lm::WordIndex index, const StringPiece &str) {
- str_.assign(str.data(), str.size());
- std::size_t factorId = m_factorCollection.AddFactor(str_)->GetId();
+ std::size_t factorId = m_factorCollection.AddFactor(str)->GetId();
if (m_mapping.size() <= factorId) {
// 0 is <unk> :-)
m_mapping.resize(factorId + 1);
@@ -153,8 +152,6 @@ public:
private:
FactorCollection &m_factorCollection;
std::vector<lm::WordIndex> &m_mapping;
-
- std::string str_;
};
template <class Model> LanguageModelKen<Model>::LanguageModelKen(const std::string &file, ScoreIndexManager &manager, FactorType factorType, bool lazy) : m_factorType(factorType) {