Newer
Older
Franck Dary
committed
#include "ReadingMachine.hpp"
#include "util.hpp"
ReadingMachine::ReadingMachine(std::filesystem::path path) : path(path)
Franck Dary
committed
{
Franck Dary
committed
char buffer[1024];
Franck Dary
committed
while (!std::feof(file))
{
if (buffer != std::fgets(buffer, 1024, file))
break;
// If line is blank or commented (# or //), ignore it
if (util::doIfNameMatch(std::regex("((\\s|\\t)*)(((#|//).*)|)(\n|)"), buffer, [](auto){}))
continue;
Franck Dary
committed
if (buffer[std::strlen(buffer)-1] == '\n')
buffer[std::strlen(buffer)-1] = '\0';
lines.emplace_back(buffer);
Franck Dary
committed
}
std::fclose(file);
try
{
unsigned int curLine = 0;
if (!util::doIfNameMatch(std::regex("Name : (.+)"), lines[curLine++], [this](auto sm){name = sm[1];}))
util::myThrow("No name specified");
while (util::doIfNameMatch(std::regex("Classifier : (.+) (.+) (.+)"), lines[curLine++], [this](auto sm){classifier.reset(new Classifier(sm[1], sm[2], sm[3]));}));
if (!classifier.get())
util::myThrow("No Classifier specified");
--curLine;
//std::vector<std::string_view> restOfFile;
//while (curLine < lines.size() and !util::doIfNameMatch(std::regex("Strategy(.*)"),lines[curLine], [](auto){}))
// restOfFile.emplace_back(lines[curLine++]);
//featureFunction.reset(new FeatureFunction(restOfFile));
auto restOfFile = std::vector<std::string_view>(lines.begin()+curLine, lines.end());
} catch(std::exception & e) {util::myThrow(fmt::format("during reading of '{}' : {}", path.string(), e.what()));}
}
ReadingMachine::ReadingMachine(const std::string & filename, const std::vector<std::string> & models, const std::vector<std::string> & dicts)
{
Franck Dary
committed
}
TransitionSet & ReadingMachine::getTransitionSet()
{
return classifier->getTransitionSet();
}
Strategy & ReadingMachine::getStrategy()
{
return *strategy;
}
Dict & ReadingMachine::getDict(const std::string & state)
{
auto found = dicts.find(state);
if (found == dicts.end())
return dicts.at("");
return found->second;
}
Classifier * ReadingMachine::getClassifier()
{
return classifier.get();
}