コード例 #1
0
  public final @NonNull AbstractTokensTaskTaggerSnapshot<TState> translateTo(
      @NonNull DocumentSnapshot targetSnapshot) {
    Parameters.notNull("targetSnapshot", targetSnapshot);
    if (targetSnapshot.equals(snapshot)) {
      return this;
    }

    if (!targetSnapshot.getVersionedDocument().equals(snapshot.getVersionedDocument())) {
      throw new IllegalArgumentException("The target snapshot is not from the same document.");
    }

    if (targetSnapshot.getVersion().getVersionNumber() < snapshot.getVersion().getVersionNumber()) {
      throw new UnsupportedOperationException(
          "The target snapshot is from an earlier version of the document.");
    }

    return translateToImpl(targetSnapshot);
  }
コード例 #2
0
  @Override
  public Iterable<TaggedPositionRegion<TokenTag<Token>>> getTags(
      NormalizedSnapshotPositionRegionCollection regions) {
    Parameters.notNull("regions", regions);
    if (regions.isEmpty()) {
      return Collections.emptyList();
    }

    DocumentSnapshot requestedSnapshot = regions.get(0).getSnapshot();
    if (!requestedSnapshot.equals(snapshot)) {
      throw new UnsupportedOperationException(
          "This tagger snapshot only supports requests from the same document.");
    }

    int startOffset = regions.get(0).getStart().getOffset();
    int endOffset = regions.get(regions.size() - 1).getEnd().getOffset();

    return getHighlights(startOffset, endOffset);
  }