Пример #1
0
static
bool isExclusive(const NGHolder &h,
                 const u32 num, unordered_set<u32> &tailId,
                 map<u32, unordered_set<u32>> &skipList,
                 const RoleInfo<role_id> &role1,
                 const RoleInfo<role_id> &role2) {
    const u32 id1 = role1.id;
    const u32 id2 = role2.id;

    if (contains(skipList, id1) && contains(skipList[id1], id2)) {
        return false;
    }

    const auto &triggers1 = role1.literals;
    const auto &triggers2 = role2.literals;
    if (isSuffix(triggers1, triggers2)) {
        skipList[id2].insert(id1);
        return false;
    }

    DEBUG_PRINTF("role id2:%u\n", id2);
    const auto &cr1 = role1.cr;
    if (overlaps(cr1, role2.last_cr)) {
        CharReach cr = cr1 | role1.prefix_cr;
        flat_set<NFAVertex> states;
        for (const auto &lit : triggers2) {
            auto lit1 = findStartPos(cr, lit);
            if (lit1.empty()) {
                continue;
            }

            states.clear();

            if (lit1.size() < lit.size()) {
                // Only starts.
                states.insert(h.start);
                states.insert(h.startDs);
            } else {
                // All vertices.
                insert(&states, vertices(h));
            }

            auto activeStates = execute_graph(h, lit1, states);
            // Check if only literal states are on
            for (const auto &s : activeStates) {
                if ((!is_any_start(s, h) && h[s].index <= num) ||
                    contains(tailId, h[s].index)) {
                    skipList[id2].insert(id1);
                    return false;
                }
            }
        }
    }

    return true;
}
Пример #2
0
bool EntryEdict::matchesWordType( const DictQuery &query ) const
{
  if( ! query.isEmpty() )
  {
    if( query.getMatchWordType() == DictQuery::Verb
        && isVerb() )
    {
      return true;
    }
    if( query.getMatchWordType() == DictQuery::Noun
        && isNoun() )
    {
      return true;
    }
    if( query.getMatchWordType() == DictQuery::Adjective
        && isAdjective() )
    {
      return true;
    }
    if( query.getMatchWordType() == DictQuery::Adverb
        && isAdverb() )
    {
      return true;
    }
    if( query.getMatchWordType() == DictQuery::Expression
        && isExpression() )
    {
      return true;
    }
    if( query.getMatchWordType() == DictQuery::Prefix
        && isPrefix() )
    {
      return true;
    }
    if( query.getMatchWordType() == DictQuery::Suffix
        && isSuffix() )
    {
      return true;
    }
    if( query.getMatchWordType() == DictQuery::Any )
    {
      return true;
    }
  }

  return false;
}