mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
refactor class BleuScoreFeature
This commit is contained in:
parent
967ac6542a
commit
47fe787f58
@ -1,5 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<?fileVersion 4.0.0?>
|
||||
|
||||
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.162355801">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.162355801" moduleId="org.eclipse.cdt.core.settings" name="Debug">
|
||||
@ -74,7 +76,6 @@
|
||||
<listOptionValue builtIn="false" value="boost_system-mt"/>
|
||||
<listOptionValue builtIn="false" value="boost_thread-mt"/>
|
||||
<listOptionValue builtIn="false" value="boost_filesystem-mt"/>
|
||||
<listOptionValue builtIn="false" value="rt"/>
|
||||
</option>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.128214028" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<?fileVersion 4.0.0?>
|
||||
|
||||
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
|
||||
<storageModule moduleId="org.eclipse.cdt.core.settings">
|
||||
<cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.461114338">
|
||||
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.461114338" moduleId="org.eclipse.cdt.core.settings" name="Debug">
|
||||
@ -72,7 +74,6 @@
|
||||
<listOptionValue builtIn="false" value="boost_thread-mt"/>
|
||||
<listOptionValue builtIn="false" value="lm"/>
|
||||
<listOptionValue builtIn="false" value="util"/>
|
||||
<listOptionValue builtIn="false" value="rt"/>
|
||||
</option>
|
||||
<option id="gnu.cpp.link.option.userobjs.1542590830" name="Other objects" superClass="gnu.cpp.link.option.userobjs" valueType="userObjs">
|
||||
<listOptionValue builtIn="false" value=""${workspace_loc}/../../boost/lib64/libboost_system-mt.a""/>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "BleuScoreFeature.h"
|
||||
|
||||
#include "StaticData.h"
|
||||
#include "UserMessage.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -87,56 +88,49 @@ m_scale_by_inverse_length(false),
|
||||
m_scale_by_avg_inverse_length(false),
|
||||
m_scale_by_x(1),
|
||||
m_historySmoothing(0.9),
|
||||
m_smoothing_scheme(PLUS_POINT_ONE) {}
|
||||
m_smoothing_scheme(PLUS_POINT_ONE)
|
||||
{
|
||||
vector<string> referenceFiles = m_parameter->GetParam("references");
|
||||
if ((!referenceFiles.size() && bleuWeightStr.size()) || (referenceFiles.size() && !bleuWeightStr.size())) {
|
||||
UserMessage::Add("You cannot use the bleu feature without references, and vice-versa");
|
||||
return false;
|
||||
}
|
||||
if (!referenceFiles.size()) {
|
||||
return true;
|
||||
}
|
||||
if (bleuWeightStr.size() > 1) {
|
||||
UserMessage::Add("Can only specify one weight for the bleu feature");
|
||||
return false;
|
||||
}
|
||||
vector<string> toks = Tokenize(line);
|
||||
for (size_t i = 0; i < toks.size(); ++i) {
|
||||
vector<string> args = Tokenize(toks[i], "=");
|
||||
CHECK(args.size() == 2);
|
||||
|
||||
float bleuWeight = Scan<float>(bleuWeightStr[0]);
|
||||
BleuScoreFeature *bleuScoreFeature = new BleuScoreFeature();
|
||||
SetWeight(bleuScoreFeature, bleuWeight);
|
||||
|
||||
cerr << "Loading reference file " << referenceFiles[0] << endl;
|
||||
vector<vector<string> > references(referenceFiles.size());
|
||||
for (size_t i =0; i < referenceFiles.size(); ++i) {
|
||||
ifstream in(referenceFiles[i].c_str());
|
||||
if (!in) {
|
||||
stringstream strme;
|
||||
strme << "Unable to load references from " << referenceFiles[i];
|
||||
UserMessage::Add(strme.str());
|
||||
return false;
|
||||
}
|
||||
string line;
|
||||
while (getline(in,line)) {
|
||||
/* if (GetSearchAlgorithm() == ChartDecoding) {
|
||||
stringstream tmp;
|
||||
tmp << "<s> " << line << " </s>";
|
||||
line = tmp.str();
|
||||
}*/
|
||||
references[i].push_back(line);
|
||||
}
|
||||
if (i > 0) {
|
||||
if (references[i].size() != references[i-1].size()) {
|
||||
UserMessage::Add("Reference files are of different lengths");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
//Set the references in the bleu feature
|
||||
bleuScoreFeature->LoadReferences(references);
|
||||
if (args[0] == "references") {
|
||||
vector<string> referenceFiles = Tokenize(args[1]);
|
||||
CHECK(referenceFiles.size());
|
||||
vector<vector<string> > references(referenceFiles.size());
|
||||
|
||||
for (size_t i =0; i < referenceFiles.size(); ++i) {
|
||||
ifstream in(referenceFiles[i].c_str());
|
||||
if (!in) {
|
||||
stringstream strme;
|
||||
strme << "Unable to load references from " << referenceFiles[i];
|
||||
UserMessage::Add(strme.str());
|
||||
abort();
|
||||
}
|
||||
string line;
|
||||
while (getline(in,line)) {
|
||||
/* if (GetSearchAlgorithm() == ChartDecoding) {
|
||||
stringstream tmp;
|
||||
tmp << "<s> " << line << " </s>";
|
||||
line = tmp.str();
|
||||
}
|
||||
*/
|
||||
references[i].push_back(line);
|
||||
}
|
||||
if (i > 0) {
|
||||
if (references[i].size() != references[i-1].size()) {
|
||||
UserMessage::Add("Reference files are of different lengths");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
} // for (size_t i =0; i < referenceFiles.size(); ++i) {
|
||||
|
||||
//Set the references in the bleu feature
|
||||
LoadReferences(references);
|
||||
} // if (args[0] == "references") {
|
||||
} // for (size_t i = 0; i < toks.size(); ++i) {
|
||||
}
|
||||
|
||||
void BleuScoreFeature::PrintHistory(std::ostream& out) const {
|
||||
|
Loading…
Reference in New Issue
Block a user