Skip to content
Snippets Groups Projects
NeuralNetwork.cpp 1.13 KiB
#include "NeuralNetwork.hpp"

std::vector<long> NeuralNetworkImpl::extractContext(Config & config, Dict & dict) const
{
  std::stack<int> leftContext;
  for (int index = config.getWordIndex()-1; config.has(0,index,0) && (int)leftContext.size() < leftBorder; --index)
    if (config.isToken(index))
      leftContext.push(dict.getIndexOrInsert(config.getLastNotEmptyConst("FORM", index)));

  std::vector<long> context;

  while ((int)context.size() < leftBorder-(int)leftContext.size())
    context.emplace_back(dict.getIndexOrInsert(Dict::nullValueStr));
  while (!leftContext.empty())
  {
    context.emplace_back(leftContext.top());
    leftContext.pop();
  }

  for (int index = config.getWordIndex(); config.has(0,index,0) && (int)context.size() < leftBorder+rightBorder+1; ++index)
    if (config.isToken(index))
      context.emplace_back(dict.getIndexOrInsert(config.getLastNotEmptyConst("FORM", index)));

  while ((int)context.size() < leftBorder+rightBorder+1)
    context.emplace_back(dict.getIndexOrInsert(Dict::nullValueStr));

  return context;
}

int NeuralNetworkImpl::getContextSize() const
{
  return 1 + leftBorder + rightBorder;
}