示例#1
0
  protected boolean kindMatchesPattern(ChunkTypeRequest pattern, Object kind) {
    for (IConditionalSlot slot : pattern.getConditionalSlots())
      if (slot.getName().equalsIgnoreCase(IAuralModule.KIND_SLOT))
        if (!slot.matchesCondition(kind)) return false;

    return true;
  }
示例#2
0
  @Override
  protected void getCandidates(ChunkTypeRequest request, Set<IIdentifier> results) {
    boolean firstInsertion = true;
    FastSet<IIdentifier> tmp = FastSet.newInstance();

    for (IConditionalSlot slot : request.getConditionalSlots())
      if (slot.getName().equals(IAuralModule.KIND_SLOT)) {
        tmp.clear();
        String kind = transformKind(slot.getValue());
        switch (slot.getCondition()) {
          case IConditionalSlot.NOT_EQUALS:
            not(kind, tmp);
            break;
          default:
            equals(kind, tmp);
            break;
        }

        if (firstInsertion) {
          results.addAll(tmp);
          firstInsertion = false;
        } else results.retainAll(tmp);
      }

    FastSet.recycle(tmp);
  }
示例#3
0
  @Override
  public void fillSlotValues(
      ChunkTypeRequest mutableRequest,
      IIdentifier identifier,
      IChunk encodedChunk,
      ChunkTypeRequest originalSearchRequest) {
    String[] kinds = _currentKindMap.get(identifier);

    if (kinds != null)
      for (String kind : kinds)
        try {
          // attempt to resolve it..
          IChunkType chunkType =
              encodedChunk.getModel().getDeclarativeModule().getChunkType(kind).get();

          Object kindValue = kind;
          if (chunkType != null) {
            if (LOGGER.isDebugEnabled())
              LOGGER.debug("Got chunktype " + chunkType + " for " + kind);
            kindValue = chunkType;
          } else if (LOGGER.isDebugEnabled())
            LOGGER.debug("No chunktype matching " + kind + " could be found, using string value");

          if (kindMatchesPattern(originalSearchRequest, kindValue)) {
            mutableRequest.addSlot(new BasicSlot(IAuralModule.KIND_SLOT, kindValue));
            return;
          }
        } catch (Exception e) {
          throw new RuntimeException("Failed to get kind ", e);
        }
  }