Ejemplo n.º 1
0
NameScore GetNameScore(std::vector<strings::UniString> const & tokens, Slice const & slice)
{
  if (slice.Empty())
    return NAME_SCORE_ZERO;

  size_t const n = tokens.size();
  size_t const m = slice.Size();

  bool const lastTokenIsPrefix = slice.IsPrefix(m - 1);

  NameScore score = NAME_SCORE_ZERO;
  for (size_t offset = 0; offset + m <= n; ++offset)
  {
    bool match = true;
    for (size_t i = 0; i < m - 1 && match; ++i)
      match = match && impl::FullMatch(slice.Get(i), tokens[offset + i]);
    if (!match)
      continue;

    bool const fullMatch = impl::FullMatch(slice.Get(m - 1), tokens[offset + m - 1]);
    bool const prefixMatch =
        lastTokenIsPrefix && impl::PrefixMatch(slice.Get(m - 1), tokens[offset + m - 1]);
    if (!fullMatch && !prefixMatch)
      continue;

    if (m == n && fullMatch)
      return NAME_SCORE_FULL_MATCH;

    if (offset == 0)
      score = std::max(score, NAME_SCORE_PREFIX);

    score = std::max(score, NAME_SCORE_SUBSTRING);
  }
  return score;
}
Ejemplo n.º 2
0
ErrorsMade GetErrorsMade(std::vector<strings::UniString> const & tokens, Slice const & slice)
{
  ErrorsMade totalErrorsMade;

  for (size_t i = 0; i < slice.Size(); ++i)
  {
    ErrorsMade errorsMade;
    slice.Get(i).ForEach([&](strings::UniString const & s) {
      errorsMade = ErrorsMade::Min(errorsMade, impl::GetMinErrorsMade(tokens, s));
    });

    totalErrorsMade += errorsMade;
  }

  return totalErrorsMade;
}