commit be74a74ccbd51905c5d9a2d6e40bfc764ceef9b7 Author: aboelhamd Date: Fri Jun 7 21:37:23 2019 +0200 Solve access bug of map of maps in compilers > 5 diff --git a/src/BeamSearch.cpp b/src/BeamSearch.cpp index 2f0186c..b8b95ee 100644 --- a/src/BeamSearch.cpp +++ b/src/BeamSearch.cpp @@ -27,21 +27,21 @@ using namespace pugi; using namespace elem; int main(int argc, char **argv) { - string lextorFilePath, interInFilePath, localeId, transferFilePath, + string lextorFilePath, chunkerFilePath, localeId, transferFilePath, modelsDest, k; if (argc == 7) { localeId = argv[1]; transferFilePath = argv[2]; lextorFilePath = argv[3]; - interInFilePath = argv[4]; + chunkerFilePath = argv[4]; modelsDest = argv[5]; k = argv[6]; } else { localeId = "es_ES"; transferFilePath = "apertium-eng-spa.spa-eng.t1x"; lextorFilePath = "lextor.txt"; - interInFilePath = "beaminter.txt"; + chunkerFilePath = "beaminter.txt"; modelsDest = "/home/aboelhamd/Downloads/models"; k = "8"; @@ -67,7 +67,7 @@ int main(int argc, char **argv) { << "lextorFilePath : Apertium lextor file for the source language sentences." << endl; cout - << "interInFilePath : Output file of this program which is the input for apertium interchunk." + << "chunkerFilePath : Output file of this program which is the input for apertium interchunk." << endl; cout << "modelsDest : Yasmet models merged file destination." << endl; cout << "beamSize : The size of beam in beam search algorithm." << endl; @@ -75,8 +75,8 @@ int main(int argc, char **argv) { } ifstream lextorFile(lextorFilePath.c_str()); - ofstream interInFile(interInFilePath.c_str()); - if (lextorFile.is_open() && interInFile.is_open()) { + ofstream chunkerFile(chunkerFilePath.c_str()); + if (lextorFile.is_open() && chunkerFile.is_open()) { // load transfer file in an xml document object xml_document transferDoc; xml_parse_result result = transferDoc.load_file( @@ -173,10 +173,10 @@ int main(int argc, char **argv) { // write the outs for (unsigned j = 0; j < outs.size(); j++) - interInFile << outs[j] << endl; + chunkerFile << outs[j] << endl; } - interInFile.close(); + chunkerFile.close(); lextorFile.close(); } else { cout << "ERROR in opening files!" << endl; diff --git a/src/CLExec.cpp b/src/CLExec.cpp index e2215db..5d3439d 100644 --- a/src/CLExec.cpp +++ b/src/CLExec.cpp @@ -172,22 +172,41 @@ map > > CLExec::loadYasmetModels( strcpy(lineChar, line.c_str()); token = strtok(lineChar, ": "); +// cout << endl << token << endl; if (token == "file") { model = strtok(NULL, ": "); continue; } // skip rule_num - strtok(NULL, ": "); + /*cout << model << " " << */strtok(NULL, ": ") /*<< endl*/; // cout << "rulenum= " << strtok(NULL, ": ") << endl; weight = strtok(NULL, ": "); // cout << "weight= " << weight << endl; float w = strtof(weight.c_str(), NULL); +// cout << weight << " = " << w << endl; + // cout << w << endl; // if (w < 0) // cout << w << endl; - classWeights[model][token].push_back(w); +// classWeights[model][token].push_back(w); + map > >::iterator it1 = + classWeights.find(model); + if (it1 == classWeights.end()) { + classWeights.insert( + pair > >(model, + map >())); + it1=classWeights.find(model); + } + map >::iterator it2 = it1->second.find(token); + if (it2 != it1->second.end()) { + it2->second.push_back(w); + } else { + it1->second.insert( + pair >(token, vector())); + it2 = it1->second.find(token); + } // if (classWeights[model][token][classWeights[model][token].size() - 1] // < 0) // cout << w << endl; @@ -351,6 +370,24 @@ void CLExec::beamSearch( newTree[z].second += 1; cout << "word : " << word << " is not found in dataset : " << rulesNums << endl; + +// for (map > >::iterator it = +// classesWeights.begin(); it != classesWeights.end(); +// it++) { +// cout << "class weightssssssssssssssssss:" << endl; +// cout << "model : " << it->first << endl; +// for (map >::iterator it2 = +// it->second.begin(); it2 != it->second.end(); +// it2++) { +// cout << "word : " << it2->first << " " +// << it2->second.size() << endl; +// for (unsigned z = 0; z < it2->second.size(); z++) +// cout << it2->second[z] << " " << endl; +// cout << endl << endl; +// } +// } +// return; +// cout << "miss" << endl; } else { @@ -363,6 +400,8 @@ void CLExec::beamSearch( } for (unsigned z = 0; z < ambigRulesSize; z++) newTree[z].second += wordWeights[z]; + +// cout << "hit" << endl; } }