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
diff options
context:
space:
mode:
authornicolabertoldi <nicolabertoldi@1f5c12ca-751b-0410-a591-d2e778427230>2008-06-05 11:23:34 +0400
committernicolabertoldi <nicolabertoldi@1f5c12ca-751b-0410-a591-d2e778427230>2008-06-05 11:23:34 +0400
commit281bf610b87a02c762cf2bece152e99c184069fa (patch)
treee11bb70d149d87574f2c04f1bbd2521afb081d85 /mert/FeatureStats.cpp
parent1b44c7c445ead80485186c1c92b18cfbd3b7992e (diff)
added binary read/load facility for feature data
added names of features in the header added methods to access the features by name git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1819 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'mert/FeatureStats.cpp')
-rw-r--r--mert/FeatureStats.cpp80
1 files changed, 59 insertions, 21 deletions
diff --git a/mert/FeatureStats.cpp b/mert/FeatureStats.cpp
index 62e59974a..bbceff135 100644
--- a/mert/FeatureStats.cpp
+++ b/mert/FeatureStats.cpp
@@ -9,18 +9,35 @@
#include <fstream>
#include "FeatureStats.h"
+#define AVAILABLE_ 8;
+
FeatureStats::FeatureStats()
-{};
+{
+ available_ = AVAILABLE_;
+ entries_ = 0;
+ array2_ = new FeatureStatsType[available_];
+};
+
+FeatureStats::~FeatureStats()
+{
+ delete array2_;
+};
-FeatureStats::FeatureStats(const FeatureStats &stats):
-array_(stats.array_)
-{};
+FeatureStats::FeatureStats(const FeatureStats &stats)
+{
+ available_ = stats.available();
+ entries_ = stats.size();
+ array2_ = new FeatureStatsType[available_];
+ memcpy(array2_,stats.getArray(),bytes_);
+};
FeatureStats::FeatureStats(const size_t size)
{
- for(unsigned int i = 0; i < size; i++)
- array_.push_back(0);
+ available_ = size;
+ entries_ = size;
+ array2_ = new FeatureStatsType[available_];
+ memset(array2_,0,bytes_);
};
@@ -29,30 +46,48 @@ FeatureStats::FeatureStats(std::string &theString)
set(theString);
}
+void FeatureStats::expand()
+{
+ available_*=2;
+ featstats_t t_ = new FeatureStatsType[available_];
+ memcpy(t_,array2_,bytes_);
+ delete array2_;
+ array2_=t_;
+}
+
+void FeatureStats::add(FeatureStatsType v)
+{
+ if (isfull()) expand();
+ array2_[entries_++]=v;
+}
+
void FeatureStats::set(std::string &theString)
{
std::string substring, stringBuf;
-
- int nextPound;
- FeatureStatsType sc;
-// TRACE_ERR("Decompounding string: " << theString << std::endl);
+ reset();
+
while (!theString.empty()){
- nextPound = getNextPound(theString, substring);
- sc = ATOFST(substring.c_str());
- array_.push_back(sc);
+ getNextPound(theString, substring);
+ add(ATOFST(substring.c_str()));
}
}
+
+void FeatureStats::loadbin(std::ifstream& inFile)
+{
+ inFile.read((char*) array2_, bytes_);
+}
+
void FeatureStats::loadtxt(std::ifstream& inFile)
{
- std::string theString;
+ std::string theString;
std::getline(inFile, theString);
set(theString);
}
void FeatureStats::loadtxt(const std::string &file)
{
-// TRACE_ERR("loading the stats from " << file << std::endl);
+ // TRACE_ERR("loading the stats from " << file << std::endl);
std::ifstream inFile(file.c_str(), std::ios::in); // matches a stream with a file. Opens the file
@@ -72,19 +107,22 @@ void FeatureStats::savetxt(const std::string &file)
void FeatureStats::savetxt(std::ofstream& outFile)
{
- TRACE_ERR("saving the stats" << std::endl);
+// TRACE_ERR("saving the stats" << std::endl);
outFile << *this;
}
void FeatureStats::savebin(std::ofstream& outFile)
{
- outFile << "S|";
- outFile << "|E";
+ outFile.write((char*) array2_, bytes_);
}
FeatureStats& FeatureStats::operator=(const FeatureStats &stats)
{
- array_ = stats.array_;
+ delete array2_;
+ available_ = stats.available();
+ entries_ = stats.size();
+ array2_ = new FeatureStatsType[available_];
+ memcpy(array2_,stats.getArray(),bytes_);
return *this;
}
@@ -92,7 +130,7 @@ FeatureStats& FeatureStats::operator=(const FeatureStats &stats)
/**write the whole object to a stream*/
ostream& operator<<(ostream& o, const FeatureStats& e){
- for (featstats_t::iterator i = e.getArray().begin(); i != e.getArray().end(); i++)
- o << *i << " ";
+ for (size_t i=0; i< e.size(); i++)
+ o << e.get(i) << " ";
return o;
}