#ifndef CONFIG__H #define CONFIG__H #include <memory> #include <string> #include <vector> #include <boost/flyweight.hpp> #include <boost/circular_buffer.hpp> #include "util.hpp" #include "Dict.hpp" class Config { public : static constexpr const char * EOSColName = "EOS"; static constexpr const char * EOSSymbol1 = "1"; static constexpr const char * EOSSymbol0 = "0"; static constexpr const char * headColName = "HEAD"; static constexpr const char * deprelColName = "DEPREL"; static constexpr const char * idColName = "ID"; static constexpr int nbHypothesesMax = 1; public : using String = boost::flyweight<std::string>; using Utf8String = util::utf8string; using ValueIterator = std::vector<String>::iterator; using ConstValueIterator = std::vector<String>::const_iterator; private : std::vector<String> lines; std::set<std::string> predicted; int lastPoppedStack{-1}; int currentWordId{0}; protected : const Utf8String & rawInput; std::size_t wordIndex{0}; std::size_t characterIndex{0}; String state{"NONE"}; boost::circular_buffer<String> history{10}; boost::circular_buffer<std::size_t> stack{50}; protected : Config(const Utf8String & rawInput); public : virtual std::size_t getNbColumns() const = 0; virtual std::size_t getColIndex(const std::string & colName) const = 0; virtual bool hasColIndex(const std::string & colName) const = 0; virtual std::size_t getFirstLineIndex() const = 0; virtual const std::string & getColName(int colIndex) const = 0; std::size_t getIndexOfLine(int lineIndex) const; std::size_t getIndexOfCol(int colIndex) const; std::size_t getNbLines() const; 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; ValueIterator getIterator(int colIndex, int lineIndex, int hypothesisIndex); ConstValueIterator getConstIterator(int colIndex, int lineIndex, int hypothesisIndex) const; public : virtual ~Config() {} void print(FILE * dest) 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); bool hasCharacter(int letterIndex) const; util::utf8char getLetter(int letterIndex) const; void addToHistory(const std::string & transition); void addToStack(std::size_t index); void popStack(); bool isComment(std::size_t lineIndex) const; bool isCommentPredicted(std::size_t lineIndex) const; bool isMultiword(std::size_t lineIndex) const; bool isMultiwordPredicted(std::size_t lineIndex) const; int getMultiwordSize(std::size_t lineIndex) const; int getMultiwordSizePredicted(std::size_t lineIndex) const; bool isEmptyNode(std::size_t lineIndex) const; bool isEmptyNodePredicted(std::size_t lineIndex) const; bool isToken(std::size_t lineIndex) const; bool isTokenPredicted(std::size_t lineIndex) const; bool moveWordIndex(int relativeMovement); bool canMoveWordIndex(int relativeMovement) const; bool moveCharacterIndex(int relativeMovement); bool canMoveCharacterIndex(int relativeMovement) const; bool rawInputOnlySeparatorsLeft() const; std::size_t getWordIndex() const; std::size_t getCharacterIndex() const; const String & getHistory(int relativeIndex) const; std::size_t getStack(int relativeIndex) const; bool hasHistory(int relativeIndex) const; bool hasStack(int relativeIndex) const; String getState() const; void setState(const std::string state); bool stateIsDone() const; void addPredicted(const std::set<std::string> & predicted); bool isPredicted(const std::string & colName) const; int getLastPoppedStack() const; int getCurrentWordId() const; void setCurrentWordId(int currentWordId); void addMissingColumns(); void addComment(); }; #endif