Commit c7267759 authored by Franck Dary's avatar Franck Dary
Browse files

Parallel decoding for trainer (devScore)

parent ee3d2d5e
......@@ -5,6 +5,7 @@ add_compile_definitions(BOOST_DISABLE_THREADS)
find_package(Torch REQUIRED)
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options)
find_package(TBB REQUIRED tbb)
include_directories(SYSTEM ${TORCH_INCLUDE_DIRS})
......
......@@ -9,6 +9,7 @@
#include <filesystem>
#include <experimental/source_location>
#include <boost/flyweight.hpp>
#include <boost/flyweight/no_tracking.hpp>
#include <boost/circular_buffer.hpp>
#include "fmt/core.h"
#include "utf8.hpp"
......@@ -16,6 +17,7 @@
namespace util
{
using String = boost::flyweights::flyweight<std::string,boost::flyweights::no_tracking>;
constexpr float float2longScale = 10000;
......@@ -56,18 +58,6 @@ float long2float(long l);
std::vector<std::vector<std::string>> readTSV(std::string_view tsvFilename);
template <typename T>
bool isEmpty(const std::vector<T> & s)
{
return s.empty();
}
template <typename T>
bool isEmpty(const std::basic_string<T> & s)
{
return s.empty();
}
template <typename T>
std::size_t getSize(const std::vector<T> & s)
{
......@@ -75,17 +65,11 @@ std::size_t getSize(const std::vector<T> & s)
}
template <typename T>
std::size_t getSize(const boost::flyweight<T> & s)
std::size_t getSize(const boost::flyweights::flyweight<T> & s)
{
return getSize(s.get());
}
template <typename T>
bool isEmpty(const boost::flyweight<T> & s)
{
return isEmpty(s.get());
}
bool doIfNameMatch(const std::regex & reg, std::string_view name, const std::function<void(const std::smatch &)> & f);
bool choiceWithProbability(float probability);
......@@ -156,16 +140,16 @@ struct fmt::formatter<std::experimental::source_location>
}
};
template <typename T>
struct fmt::formatter<boost::flyweight<T>>
{
constexpr auto parse(format_parse_context & ctx) { return ctx.begin(); }
template <typename FormatContext>
auto format(const boost::flyweight<T> & s, FormatContext & ctx)
{
return format_to(ctx.out(), "{}", s.get());
}
};
//template <typename T>
//struct fmt::formatter<boost::flyweights::flyweight<T>>
//{
// constexpr auto parse(format_parse_context & ctx) { return ctx.begin(); }
//
// template <typename FormatContext>
// auto format(const boost::flyweights::flyweight<T> & s, FormatContext & ctx)
// {
// return format_to(ctx.out(), "{}", s.get());
// }
//};
#endif
......@@ -10,10 +10,6 @@ void Decoder::decode(BaseConfig & baseConfig, std::size_t beamSize, float beamTh
{
constexpr int printInterval = 50;
torch::AutoGradMode useGrad(false);
machine.trainMode(false);
machine.setDictsState(Dict::State::Closed);
int nbExamplesProcessed = 0;
auto pastTime = std::chrono::high_resolution_clock::now();
......
......@@ -3,4 +3,5 @@ FILE(GLOB SOURCES src/*.cpp)
add_executable(macaon src/macaon.cpp)
target_link_libraries(macaon trainer)
target_link_libraries(macaon decoder)
target_link_libraries(macaon ${TBB_IMPORTED_TARGETS})
install(TARGETS macaon DESTINATION bin)
......@@ -4,7 +4,6 @@
#include <memory>
#include <string>
#include <vector>
#include <boost/flyweight.hpp>
#include <boost/circular_buffer.hpp>
#include "util.hpp"
#include "Dict.hpp"
......@@ -39,14 +38,13 @@ class Config
public :
using String = boost::flyweight<std::string>;
using Utf8String = util::utf8string;
using ValueIterator = std::vector<String>::iterator;
using ConstValueIterator = std::vector<String>::const_iterator;
using ValueIterator = std::vector<util::String>::iterator;
using ConstValueIterator = std::vector<util::String>::const_iterator;
private :
std::vector<String> lines;
std::vector<util::String> lines;
protected :
......@@ -54,8 +52,8 @@ class Config
std::size_t wordIndex{0};
std::size_t characterIndex{0};
std::size_t currentSentenceStartRawInput{0};
String state{"NONE"};
boost::circular_buffer<String> history{10};
util::String state{"NONE"};
boost::circular_buffer<util::String> history{10};
boost::circular_buffer<std::size_t> stack{50};
float chosenActionScore{0.0};
std::vector<std::string> extraColumns{commentsColName, rawRangeStartColName, rawRangeEndColName, isMultiColName, childsColName, sentIdColName, EOSColName};
......@@ -91,13 +89,13 @@ class Config
void addLines(unsigned int nbLines);
void resizeLines(unsigned int nbLines);
bool has(int colIndex, int lineIndex, int hypothesisIndex) const;
String & get(int colIndex, int lineIndex, int hypothesisIndex);
const String & getConst(int colIndex, int lineIndex, int hypothesisIndex) const;
String & getLastNotEmpty(int colIndex, int lineIndex);
String & getLastNotEmptyHyp(int colIndex, int lineIndex);
const String & getLastNotEmptyHypConst(int colIndex, int lineIndex) const;
const String & getLastNotEmptyConst(int colIndex, int lineIndex) const;
const String & getAsFeature(int colIndex, int lineIndex) const;
util::String & get(int colIndex, int lineIndex, int hypothesisIndex);
const util::String & getConst(int colIndex, int lineIndex, int hypothesisIndex) const;
util::String & getLastNotEmpty(int colIndex, int lineIndex);
util::String & getLastNotEmptyHyp(int colIndex, int lineIndex);
const util::String & getLastNotEmptyHypConst(int colIndex, int lineIndex) const;
const util::String & getLastNotEmptyConst(int colIndex, int lineIndex) const;
const util::String & getAsFeature(int colIndex, int lineIndex) const;
ValueIterator getIterator(int colIndex, int lineIndex, int hypothesisIndex);
ConstValueIterator getConstIterator(int colIndex, int lineIndex, int hypothesisIndex) const;
std::size_t & getStackRef(int relativeIndex);
......@@ -110,15 +108,15 @@ class Config
void print(FILE * dest, bool printHeader = true) const;
void printForDebug(FILE * dest) const;
bool has(const std::string & colName, int lineIndex, int hypothesisIndex) const;
String & get(const std::string & colName, int lineIndex, int hypothesisIndex);
const String & getConst(const std::string & colName, int lineIndex, int hypothesisIndex) const;
String & getLastNotEmpty(const std::string & colName, int lineIndex);
const String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const;
String & getLastNotEmptyHyp(const std::string & colName, int lineIndex);
const String & getLastNotEmptyHypConst(const std::string & colName, int lineIndex) const;
const String & getAsFeature(const std::string & colName, int lineIndex) const;
String & getFirstEmpty(int colIndex, int lineIndex);
String & getFirstEmpty(const std::string & colName, int lineIndex);
util::String & get(const std::string & colName, int lineIndex, int hypothesisIndex);
const util::String & getConst(const std::string & colName, int lineIndex, int hypothesisIndex) const;
util::String & getLastNotEmpty(const std::string & colName, int lineIndex);
const util::String & getLastNotEmptyConst(const std::string & colName, int lineIndex) const;
util::String & getLastNotEmptyHyp(const std::string & colName, int lineIndex);
const util::String & getLastNotEmptyHypConst(const std::string & colName, int lineIndex) const;
const util::String & getAsFeature(const std::string & colName, int lineIndex) const;
util::String & getFirstEmpty(int colIndex, int lineIndex);
util::String & getFirstEmpty(const std::string & colName, int lineIndex);
bool hasCharacter(int letterIndex) const;
const util::utf8char & getLetter(int letterIndex) const;
void addToHistory(const std::string & transition);
......@@ -143,12 +141,12 @@ class Config
std::size_t getCharacterIndex() const;
long getRelativeWordIndex(Object object, int relativeIndex) const;
bool hasRelativeWordIndex(Object object, int relativeIndex) const;
const String & getHistory(int relativeIndex) const;
const util::String & getHistory(int relativeIndex) const;
std::size_t getStack(int relativeIndex) const;
std::size_t getStackSize() const;
bool hasHistory(int relativeIndex) const;
bool hasStack(int relativeIndex) const;
String getState() const;
util::String getState() const;
void setState(const std::string state);
bool stateIsDone() const;
void addPredicted(const std::set<std::string> & predicted);
......
......@@ -18,7 +18,7 @@ class ReadingMachine
std::string name;
std::filesystem::path path;
std::vector<std::unique_ptr<Classifier>> classifiers;
std::map<std::string, int> state2classifier;
std::unordered_map<std::string, int> state2classifier;
std::vector<std::string> strategyDefinition;
std::vector<std::vector<std::string>> classifierDefinitions;
std::vector<std::string> classifierNames;
......
......@@ -153,7 +153,7 @@ Action Action::addToHypothesis(const std::string & colName, std::size_t lineInde
{
auto apply = [colName, lineIndex, addition](Config & config, Action &)
{
auto currentElems = util::split(config.getLastNotEmptyHypConst(colName, lineIndex).get(), '|');
auto currentElems = util::split(std::string(config.getLastNotEmptyHypConst(colName, lineIndex)), '|');
currentElems.emplace_back(addition);
std::sort(currentElems.begin(), currentElems.end());
......@@ -163,7 +163,7 @@ Action Action::addToHypothesis(const std::string & colName, std::size_t lineInde
auto undo = [colName, lineIndex, addition](Config & config, Action &)
{
auto curElems = util::split(config.getLastNotEmptyHypConst(colName, lineIndex).get(), '|');
auto curElems = util::split(std::string(config.getLastNotEmptyHypConst(colName, lineIndex)), '|');
std::vector<std::string> newElems;
for (auto & elem : curElems)
if (elem != addition)
......@@ -177,7 +177,7 @@ Action Action::addToHypothesis(const std::string & colName, std::size_t lineInde
if (!config.has(colName, lineIndex, 0))
return false;
auto & current = config.getLastNotEmptyHypConst(colName, lineIndex);
auto splited = util::split(current.get(), '|');
auto splited = util::split(std::string(current), '|');
for (auto & part : splited)
if (part == addition)
return false;
......@@ -191,10 +191,10 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
{
auto apply = [colName, lineIndex, addition, mean](Config & config, Action &)
{
std::string totalStr = config.getLastNotEmptyHypConst(colName, lineIndex).get();
std::string totalStr = std::string(config.getLastNotEmptyHypConst(colName, lineIndex));
if (totalStr.empty() || totalStr == "_")
totalStr = fmt::format("{}={}|{}", config.getState(), 0.0, 0);
totalStr = fmt::format("{}={}|{}", std::string(config.getState()), 0.0, 0);
auto byStates = util::split(totalStr, ',');
int index = -1;
......@@ -209,7 +209,7 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
}
if (index == -1)
{
byStates.emplace_back(fmt::format("{}={}|{}", config.getState(), 0.0, 0));
byStates.emplace_back(fmt::format("{}={}|{}", std::string(config.getState()), 0.0, 0));
index = byStates.size()-1;
}
......@@ -235,17 +235,17 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
curVal += addition;
}
byStates[index] = fmt::format("{}={}|{}", config.getState(), curVal, curNb);
byStates[index] = fmt::format("{}={}|{}", std::string(config.getState()), curVal, curNb);
config.getLastNotEmptyHyp(colName, lineIndex) = util::join(",", byStates);
};
auto undo = [colName, lineIndex, addition, mean](Config & config, Action &)
{
std::string totalStr = config.getLastNotEmptyHypConst(colName, lineIndex).get();
std::string totalStr = std::string(config.getLastNotEmptyHypConst(colName, lineIndex));
if (totalStr.empty() || totalStr == "_")
totalStr = fmt::format("{}={}|{}", config.getState(), 0.0, 0);
totalStr = fmt::format("{}={}|{}", std::string(config.getState()), 0.0, 0);
auto byStates = util::split(totalStr, ',');
int index = -1;
......@@ -260,7 +260,7 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
}
if (index == -1)
{
byStates.emplace_back(fmt::format("{}={}|{}", config.getState(), 0.0, 0));
byStates.emplace_back(fmt::format("{}={}|{}", std::string(config.getState()), 0.0, 0));
index = byStates.size()-1;
}
......@@ -282,7 +282,7 @@ Action Action::sumToHypothesis(const std::string & colName, std::size_t lineInde
else
curVal -= addition;
byStates[index] = fmt::format("{}={}|{}", config.getState(), curVal, curNb);
byStates[index] = fmt::format("{}={}|{}", std::string(config.getState()), curVal, curNb);
config.getLastNotEmptyHyp(colName, lineIndex) = util::join(",", byStates);
};
......@@ -456,9 +456,9 @@ Action Action::endWord()
auto appliable = [](const Config & config, const Action &)
{
if (util::isEmpty(config.getAsFeature("FORM", config.getWordIndex())))
if (std::string(config.getAsFeature("FORM", config.getWordIndex())).empty())
return false;
if (!util::isEmpty(config.getAsFeature(Config::idColName, config.getWordIndex())) and config.getAsFeature(Config::isMultiColName, config.getWordIndex()) != Config::EOSSymbol1)
if (!std::string(config.getAsFeature(Config::idColName, config.getWordIndex())).empty() and config.getAsFeature(Config::isMultiColName, config.getWordIndex()) != Config::EOSSymbol1)
return false;
return true;
......@@ -532,7 +532,7 @@ Action Action::assertIsEmpty(const std::string & colName, Config::Object object,
if (!config.hasRelativeWordIndex(object, relativeIndex))
return false;
auto lineIndex = config.getRelativeWordIndex(object, relativeIndex);
return util::isEmpty(config.getAsFeature(colName, lineIndex));
return std::string(config.getAsFeature(colName, lineIndex)).empty();
} catch (std::exception & e)
{
util::myThrow(fmt::format("colName='{}' object='{}' relativeIndex='{}' {}", colName, object == Config::Object::Stack ? "Stack" : "Buffer", relativeIndex, e.what()));
......@@ -561,7 +561,7 @@ Action Action::assertIsNotEmpty(const std::string & colName, Config::Object obje
if (!config.hasRelativeWordIndex(object, relativeIndex))
return false;
auto lineIndex = config.getRelativeWordIndex(object, relativeIndex);
return !util::isEmpty(config.getAsFeature(colName, lineIndex));
return !std::string(config.getAsFeature(colName, lineIndex)).empty();
} catch (std::exception & e)
{
util::myThrow(fmt::format("colName='{}' object='{}' relativeIndex='{}' {}", colName, object == Config::Object::Stack ? "Stack" : "Buffer", relativeIndex, e.what()));
......@@ -581,21 +581,21 @@ Action Action::addCharsToCol(const std::string & col, int n, Config::Object obje
auto & curWord = config.getLastNotEmptyHyp(col, index);
if (col == "FORM")
{
if (util::isEmpty(config.getAsFeature(Config::rawRangeStartColName, index)))
if (std::string(config.getAsFeature(Config::rawRangeStartColName, index)).empty())
config.getLastNotEmptyHyp(Config::rawRangeStartColName, index) = fmt::format("{}", config.getCharacterIndex());
config.getLastNotEmptyHyp(Config::rawRangeEndColName, index) = fmt::format("{}", config.getCharacterIndex());
int curEndValue = std::stoi(config.getAsFeature(Config::rawRangeEndColName, index));
config.getLastNotEmptyHyp(Config::rawRangeEndColName, index) = fmt::format("{}", curEndValue+n);
}
for (int i = 0; i < n; i++)
curWord = fmt::format("{}{}", curWord, config.getLetter(config.getCharacterIndex()+i));
curWord = fmt::format("{}{}", std::string(curWord), config.getLetter(config.getCharacterIndex()+i));
};
auto undo = [col, n, object, relativeIndex](Config & config, Action &)
{
auto index = config.getRelativeWordIndex(object, relativeIndex);
auto & curWord = config.getLastNotEmptyHyp(col, index);
auto newWord = util::splitAsUtf8(curWord.get());
auto newWord = util::splitAsUtf8(std::string(curWord));
for (int i = 0; i < n; i++)
newWord.pop_back();
curWord = fmt::format("{}", newWord);
......@@ -612,7 +612,7 @@ Action Action::addCharsToCol(const std::string & col, int n, Config::Object obje
auto firstLetter = config.getLetter(config.getCharacterIndex());
if (firstLetter == ' ' and util::isEmpty(config.getAsFeature(col, config.getRelativeWordIndex(object, relativeIndex))))
if (firstLetter == ' ' and std::string(config.getAsFeature(col, config.getRelativeWordIndex(object, relativeIndex))).empty())
return false;
for (int i = 0; i < n; i++)
......@@ -646,7 +646,7 @@ Action Action::setRoot(int bufferIndex)
if (config.getAsFeature(Config::EOSColName, i) == Config::EOSSymbol1)
break;
if (util::isEmpty(config.getAsFeature(Config::headColName, i)))
if (std::string(config.getAsFeature(Config::headColName, i)).empty())
{
rootIndex = i;
a.data.push_back(std::to_string(i));
......@@ -667,7 +667,7 @@ Action Action::setRoot(int bufferIndex)
if (config.getAsFeature(Config::EOSColName, i) == Config::EOSSymbol1)
break;
if (util::isEmpty(config.getAsFeature(Config::headColName, i)))
if (std::string(config.getAsFeature(Config::headColName, i)).empty())
{
if (i == rootIndex)
{
......@@ -752,13 +752,13 @@ Action Action::updateIds(int bufferIndex)
int firstIndex = 0;
int lastIndex = 0;
try {firstIndex = std::stoi(config.getAsFeature(Config::rawRangeStartColName, firstIndexOfSentence));}
catch (std::exception & e) {util::myThrow(fmt::format("{} : '{}'", e.what(), config.getAsFeature(Config::rawRangeStartColName, firstIndexOfSentence)));}
catch (std::exception & e) {util::myThrow(fmt::format("{} : '{}'", e.what(), std::string(config.getAsFeature(Config::rawRangeStartColName, firstIndexOfSentence))));}
try {lastIndex = std::stoi(config.getAsFeature(Config::rawRangeEndColName, lineIndex));}
catch (std::exception & e) {util::myThrow(fmt::format("{} : '{}'", e.what(), config.getAsFeature(Config::rawRangeEndColName, lineIndex)));}
catch (std::exception & e) {util::myThrow(fmt::format("{} : '{}'", e.what(), std::string(config.getAsFeature(Config::rawRangeEndColName, lineIndex))));}
for (auto i = firstIndex; i < lastIndex; i++)
textMetadata = fmt::format("{}{}", textMetadata, config.getLetter(i));
config.getLastNotEmptyHyp(Config::commentsColName, firstIndexOfSentence) = fmt::format("{}\n# sent_id = {}", textMetadata, config.getAsFeature(Config::sentIdColName, firstIndexOfSentence));
config.getLastNotEmptyHyp(Config::commentsColName, firstIndexOfSentence) = fmt::format("{}\n# sent_id = {}", textMetadata, std::string(config.getAsFeature(Config::sentIdColName, firstIndexOfSentence)));
}
};
......@@ -812,7 +812,7 @@ Action Action::attach(Config::Object governorObject, int governorIndex, Config::
return false;
// Check if dep is not already attached
if (!util::isEmpty(config.getAsFeature(Config::headColName, depLineIndex)))
if (!std::string(config.getAsFeature(Config::headColName, depLineIndex)).empty())
return false;
return true;
......@@ -877,7 +877,7 @@ Action Action::setRootUpdateIdsEmptyStackIfSentChanged()
break;
}
if (util::isEmpty(config.getAsFeature(Config::headColName, i)))
if (std::string(config.getAsFeature(Config::headColName, i)).empty())
rootIndex = i;
firstIndexOfSentence = i;
......@@ -894,7 +894,7 @@ Action Action::setRootUpdateIdsEmptyStackIfSentChanged()
if (!config.isTokenPredicted(i))
continue;
if (util::isEmpty(config.getAsFeature(Config::headColName, i)))
if (std::string(config.getAsFeature(Config::headColName, i)).empty())
{
if (i == rootIndex)
{
......@@ -968,11 +968,11 @@ Action Action::transformSuffix(std::string fromCol, Config::Object fromObj, int
if (toRemove.empty() and toAdd.empty())
{
addHypothesis(toCol, toLineIndex, config.getAsFeature(fromCol, fromLineIndex).get()).apply(config, a);
addHypothesis(toCol, toLineIndex, std::string(config.getAsFeature(fromCol, fromLineIndex))).apply(config, a);
return;
}
util::utf8string res = util::splitAsUtf8(util::lower(config.getAsFeature(fromCol, fromLineIndex).get()));
util::utf8string res = util::splitAsUtf8(util::lower(std::string(config.getAsFeature(fromCol, fromLineIndex))));
for (unsigned int i = 0; i < toRemove.size(); i++)
res.pop_back();
for (auto & letter : toAdd)
......@@ -993,7 +993,7 @@ Action Action::transformSuffix(std::string fromCol, Config::Object fromObj, int
int fromLineIndex = config.getRelativeWordIndex(fromObj, fromIndex);
int toLineIndex = config.getRelativeWordIndex(toObj, toIndex);
util::utf8string res = util::splitAsUtf8(util::lower(config.getAsFeature(fromCol, fromLineIndex).get()));
util::utf8string res = util::splitAsUtf8(util::lower(std::string(config.getAsFeature(fromCol, fromLineIndex))));
if (res.size() < toRemove.size())
return false;
......@@ -1069,7 +1069,7 @@ Action Action::uppercaseIndex(std::string col, Config::Object obj, int index, in
auto apply = [col, obj, index, inIndex](Config & config, Action & a)
{
int lineIndex = config.getRelativeWordIndex(obj, index);
auto res = util::splitAsUtf8(config.getAsFeature(col, lineIndex).get());
auto res = util::splitAsUtf8(std::string(config.getAsFeature(col, lineIndex)));
util::upper(res[inIndex]);
addHypothesis(col, lineIndex, fmt::format("{}", res)).apply(config, a);
......@@ -1079,7 +1079,7 @@ Action Action::uppercaseIndex(std::string col, Config::Object obj, int index, in
{
int lineIndex = config.getRelativeWordIndex(obj, index);
auto & value = config.getLastNotEmptyHyp(col, lineIndex);
auto res = util::splitAsUtf8(value.get());
auto res = util::splitAsUtf8(std::string(value));
value = fmt::format("{}", res);
};
......@@ -1090,7 +1090,7 @@ Action Action::uppercaseIndex(std::string col, Config::Object obj, int index, in
int lineIndex = config.getRelativeWordIndex(obj, index);
if ((int)util::splitAsUtf8(config.getAsFeature(col, lineIndex).get()).size() <= inIndex)
if ((int)util::splitAsUtf8(std::string(config.getAsFeature(col, lineIndex))).size() <= inIndex)
return false;
return addHypothesis(col, lineIndex, "").appliable(config, a);
......@@ -1133,7 +1133,7 @@ Action Action::lowercaseIndex(std::string col, Config::Object obj, int index, in
auto apply = [col, obj, index, inIndex](Config & config, Action & a)
{
int lineIndex = config.getRelativeWordIndex(obj, index);
auto res = util::splitAsUtf8(config.getAsFeature(col, lineIndex).get());
auto res = util::splitAsUtf8(std::string(config.getAsFeature(col, lineIndex)));
util::lower(res[inIndex]);
addHypothesis(col, lineIndex, fmt::format("{}", res)).apply(config, a);
......@@ -1143,7 +1143,7 @@ Action Action::lowercaseIndex(std::string col, Config::Object obj, int index, in
{
int lineIndex = config.getRelativeWordIndex(obj, index);
auto & value = config.getLastNotEmptyHyp(col, lineIndex);
auto res = util::splitAsUtf8(value.get());
auto res = util::splitAsUtf8(std::string(value));
value = fmt::format("{}", res);
};
......@@ -1154,7 +1154,7 @@ Action Action::lowercaseIndex(std::string col, Config::Object obj, int index, in
int lineIndex = config.getRelativeWordIndex(obj, index);
if ((int)util::splitAsUtf8(config.getAsFeature(col, lineIndex).get()).size() <= inIndex)
if ((int)util::splitAsUtf8(std::string(config.getAsFeature(col, lineIndex))).size() <= inIndex)
return false;
return addHypothesis(col, lineIndex, "").appliable(config, a);
......
......@@ -53,22 +53,22 @@ bool Config::has(const std::string & colName, int lineIndex, int hypothesisIndex
return hasColIndex(colName) && has(getColIndex(colName), lineIndex, hypothesisIndex);
}
Config::String & Config::get(const std::string & colName, int lineIndex, int hypothesisIndex)
util::String & Config::get(const std::string & colName, int lineIndex, int hypothesisIndex)
{
return get(getColIndex(colName), lineIndex, hypothesisIndex);
}
const Config::String & Config::getConst(const std::string & colName, int lineIndex, int hypothesisIndex) const
const util::String & Config::getConst(const std::string & colName, int lineIndex, int hypothesisIndex) const
{
return getConst(getColIndex(colName), lineIndex, hypothesisIndex);
}
Config::String & Config::get(int colIndex, int lineIndex, int hypothesisIndex)
util::String & Config::get(int colIndex, int lineIndex, int hypothesisIndex)
{
return *getIterator(colIndex, lineIndex, hypothesisIndex);
}
const Config::String & Config::getConst(int colIndex, int lineIndex, int hypothesisIndex) const
const util::String & Config::getConst(int colIndex, int lineIndex, int hypothesisIndex) const
{
return *getConstIterator(colIndex, lineIndex, hypothesisIndex);
}
......@@ -105,8 +105,8 @@ void Config::print(FILE * dest, bool printHeader) const
for (unsigned int line = 0; line < getNbLines(); line++)
{
if (!util::isEmpty(getAsFeature(commentsColName, getFirstLineIndex()+line)))
currentSequenceComments.emplace_back(fmt::format("{}\n", getAsFeature(commentsColName, getFirstLineIndex()+line)));
if (!std::string(getAsFeature(commentsColName, getFirstLineIndex()+line)).empty())
currentSequenceComments.emplace_back(fmt::format("{}\n", std::string(getAsFeature(commentsColName, getFirstLineIndex()+line))));
for (unsigned int i = 0; i < getNbColumns()-1; i++)
{
......@@ -175,14 +175,14 @@ void Config::printForDebug(FILE * dest) const
{
if ((isExtraColumn(getColName(i)) and exceptions.count(getColName(i)) == 0) and getColName(i) != EOSColName)
continue;
std::string colContent = has(i,line,0) ? getAsFeature(i, line).get() : "?";
std::string colContent = has(i,line,0) ? std::string(getAsFeature(i, line)) : "?";
std::string toPrintCol = colContent;
try
{
if (getColName(i) == headColName && toPrintCol != "_" && !toPrintCol.empty())
{
if (toPrintCol != "-1" && toPrintCol != "?")
toPrintCol = has(0,std::stoi(toPrintCol),0) ? getAsFeature(idColName, std::stoi(toPrintCol)).get() : "?";
toPrintCol = has(0,std::stoi(toPrintCol),0) ? std::string(getAsFeature(idColName, std::stoi(toPrintCol))) : "?";
else if (toPrintCol == "-1")
toPrintCol = "0";
}
......@@ -228,9 +228,9 @@ void Config::printForDebug(FILE * dest) const
fmt::print(dest, "{}\n", longLine);
for (std::size_t index = characterIndex; index < util::getSize(rawInput) and index - characterIndex < lettersWindowSize; index++)
fmt::print(dest, "{}", getLetter(index));
if (!util::isEmpty(rawInput))
if (!rawInput.empty())
fmt::print(dest, "\n{}\n", longLine);
fmt::print(dest, "State={}\nwordIndex={}/{} characterIndex={}/{}\nhistory=({})\nstack=({})\n", state, wordIndex, getNbLines(), characterIndex, rawInput.size(), historyStr, stackStr);
fmt::print(dest, "State={}\nwordIndex={}/{} characterIndex={}/{}\nhistory=({})\nstack=({})\n", std::string(state), wordIndex, getNbLines(), characterIndex, rawInput.size(), historyStr, stackStr);
fmt::print(dest, "{}\n", longLine);
for (unsigned int line = 0; line < toPrint.size(); line++)
......@@ -246,77 +246,77 @@ void Config::printForDebug(FILE * dest) const
fmt::print(dest, "{}\n", longLine);
}
Config::String & Config::getLastNotEmpty(int colIndex, int lineIndex)
util::String & Config::getLastNotEmpty(int colIndex, int lineIndex)
{
if (!has(colIndex, lineIndex, 0))
util::myThrow(fmt::format("asked for line {} but last line = {}", lineIndex, getNbLines()+getFirstLineIndex()-1));
int baseIndex = getIndexOfLine(lineIndex-getFirstLineIndex()) + getIndexOfCol(colIndex);
for (int i = nbHypothesesMax; i > 0; --i)
if (!util::isEmpty(lines[baseIndex+i]))
if (!std::string(lines[baseIndex+i]).empty())
return lines[baseIndex+i];