net.automatalib.words.Word.subWord()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中net.automatalib.words.Word.subWord()方法的一些代码示例,展示了Word.subWord()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Word.subWord()方法的具体详情如下:
包路径:net.automatalib.words.Word
类名称:Word
方法名:subWord

Word.subWord介绍

[英]Retrieves the subword of this word starting at the given index and extending until the end of this word. Calling this method is equivalent to calling

w.subWord(fromIndex, w.length())

[中]检索这个词的子词,从给定的索引开始,一直延伸到这个词的结尾。调用此方法相当于调用

w.subWord(fromIndex, w.length())

代码示例

代码示例来源:origin: de.learnlib/learnlib-ttt

@Override
protected Word<O> succEffect(Word<O> effect) {
  return effect.subWord(1);
}

代码示例来源:origin: net.automatalib/automata-api

/**
 * Retrieves a prefix of the given length. If <code>length</code> is negative, then a prefix consisting of all but
 * the last <code>-length</code> symbols is returned.
 *
 * @param prefixLen
 *         the length of the prefix (may be negative, see above).
 *
 * @return the prefix of the given length.
 */
@Nonnull
public final Word<I> prefix(int prefixLen) {
  final int length = prefixLen < 0 ? length() + prefixLen : prefixLen;
  return subWord(0, length);
}

代码示例来源:origin: LearnLib/automatalib

/**
 * Retrieves a prefix of the given length. If <code>length</code> is negative, then a prefix consisting of all but
 * the last <code>-length</code> symbols is returned.
 *
 * @param prefixLen
 *         the length of the prefix (may be negative, see above).
 *
 * @return the prefix of the given length.
 */
@Nonnull
public final Word<I> prefix(int prefixLen) {
  final int length = prefixLen < 0 ? length() + prefixLen : prefixLen;
  return subWord(0, length);
}

代码示例来源:origin: net.automatalib/automata-api

/**
 * Retrieves a suffix of the given length. If <code>length</code> is negative, then a suffix consisting of all but
 * the first <code>-length</code> symbols is returned.
 *
 * @param suffixLen
 *         the length of the suffix (may be negative, see above).
 *
 * @return the suffix of the given length.
 */
@Nonnull
public final Word<I> suffix(int suffixLen) {
  int wordLen = length();
  int startIdx = (suffixLen < 0) ? -suffixLen : (wordLen - suffixLen);
  return subWord(startIdx, wordLen);
}

代码示例来源:origin: LearnLib/automatalib

/**
 * Retrieves a suffix of the given length. If <code>length</code> is negative, then a suffix consisting of all but
 * the first <code>-length</code> symbols is returned.
 *
 * @param suffixLen
 *         the length of the suffix (may be negative, see above).
 *
 * @return the suffix of the given length.
 */
@Nonnull
public final Word<I> suffix(int suffixLen) {
  int wordLen = length();
  int startIdx = (suffixLen < 0) ? -suffixLen : (wordLen - suffixLen);
  return subWord(startIdx, wordLen);
}

代码示例来源:origin: de.learnlib/learnlib-counterexamples

@Override
protected D computeEffect(int index) {
  Word<I> prefix = this.suffix.prefix(index);
  Word<I> suffix = this.suffix.subWord(index);
  Word<I> asPrefix = asTransform.apply(prefix);
  return oracle.answerQuery(asPrefix, suffix);
}

代码示例来源:origin: de.learnlib/learnlib-counterexamples

@Override
protected Boolean computeEffect(int index) {
  Word<I> prefix = this.suffix.prefix(index);
  Word<I> suffix = this.suffix.subWord(index);
  Word<I> asPrefix = asTransform.apply(prefix);
  return Objects.equals(hypOut.computeSuffixOutput(asPrefix, suffix), oracle.answerQuery(asPrefix, suffix));
}

代码示例来源:origin: net.automatalib/automata-core

@Override
protected Word<I> subWordInternal(int fromIndex, int toIndex) {
  int wLen = word.length();
  if (fromIndex < wLen) {
    if (toIndex <= wLen) {
      return word.subWord(fromIndex, toIndex);
    }
    return new ExtensionWord<>(word.subWord(fromIndex, wLen), letter);
  } else if (fromIndex == wLen) {
    return Word.fromLetter(letter);
  }
  return Word.epsilon();
}

代码示例来源:origin: de.learnlib/learnlib-counterexamples

/**
 * Transforms a suffix index returned by a {@link LocalSuffixFinder} into a list of distinguishing suffixes. This
 * list always contains the corresponding local suffix. Since local suffix finders only return a single suffix,
 * suffix-closedness of the set of distinguishing suffixes might not be preserved. Note that for correctly
 * implemented local suffix finders, this does not impair correctness of the learning algorithm. However, without
 * suffix closedness, intermediate hypothesis models might be non-canonical, if no additional precautions are taken.
 * For that reasons, the <tt>allSuffixes</tt> parameter can be specified to control whether or not the list returned
 * by {@link GlobalSuffixFinder#findSuffixes(Query, AccessSequenceTransformer, SuffixOutput, MembershipOracle)} of
 * the returned global suffix finder should not only contain the single suffix, but also all of its suffixes,
 * ensuring suffix-closedness.
 */
public static <I, D> List<Word<I>> suffixesForLocalOutput(Query<I, D> ceQuery,
                             int localSuffixIdx,
                             boolean allSuffixes) {
  if (localSuffixIdx == -1) {
    return Collections.emptyList();
  }
  Word<I> suffix = ceQuery.getInput().subWord(localSuffixIdx);
  if (!allSuffixes) {
    return Collections.singletonList(suffix);
  }
  return suffix.suffixes(false);
}

代码示例来源:origin: de.learnlib/learnlib-ttt

protected TTTState<I, D> getDeterministicState(TTTState<I, D> start, Word<I> word) {
  TTTState<I, D> lastSingleton = start;
  int lastSingletonIndex = 0;
  Set<TTTState<I, D>> states = Collections.singleton(start);
  int i = 1;
  for (I sym : word) {
    Set<TTTState<I, D>> nextStates = getNondetSuccessors(states, sym);
    if (nextStates.size() == 1) {
      lastSingleton = nextStates.iterator().next();
      lastSingletonIndex = i;
    }
    states = nextStates;
    i++;
  }
  if (lastSingletonIndex == word.length()) {
    return lastSingleton;
  }
  TTTState<I, D> curr = lastSingleton;
  for (I sym : word.subWord(lastSingletonIndex)) {
    TTTTransition<I, D> trans = curr.getTransition(alphabet.getSymbolIndex(sym));
    curr = requireSuccessor(trans);
  }
  return curr;
}

代码示例来源:origin: net.automatalib/automata-api

default Word<I> longestWellMatchedSuffix(Word<I> word) {
  int idx = word.length();
  int crb = 0;
  int lastZero = idx;
  outer:
  while (idx > 0) {
    final I sym = word.getSymbol(--idx);
    switch (getSymbolType(sym)) {
      case CALL:
        crb++;
        if (crb > 0) {
          break outer;
        }
        break;
      case RETURN:
        crb--;
        break;
      default:
    }
    if (crb == 0) {
      lastZero = idx;
    }
  }
  return word.subWord(lastZero);
}

代码示例来源:origin: LearnLib/automatalib

default Word<I> longestWellMatchedSuffix(Word<I> word) {
  int idx = word.length();
  int crb = 0;
  int lastZero = idx;
  outer:
  while (idx > 0) {
    final I sym = word.getSymbol(--idx);
    switch (getSymbolType(sym)) {
      case CALL:
        crb++;
        if (crb > 0) {
          break outer;
        }
        break;
      case RETURN:
        crb--;
        break;
      default:
    }
    if (crb == 0) {
      lastZero = idx;
    }
  }
  return word.subWord(lastZero);
}

代码示例来源:origin: de.learnlib/learnlib-cache

private void answerSlave(Query<I, Word<O>> slave) {
  int start = slave.getPrefix().length();
  int end = start + slave.getSuffix().length();
  slave.answer(answer.subWord(start, end));
}

代码示例来源:origin: LearnLib/automatalib

Word<? extends I> suffix = word.subWord(prefixLen);
Word<? extends O> suffixOut = outputWord.subWord(prefixLen);
O suffTransOut = suffixOut.firstSymbol();
State<O> suffixState = createSuffix(suffix.subWord(1), suffixOut.subWord(1));

代码示例来源:origin: LearnLib/automatalib

Word<? extends I> suffix = word.subWord(prefixLen);
I sym = suffix.firstSymbol();
int suffTransIdx = inputAlphabet.getSymbolIndex(sym);
State suffixState = createSuffix(suffix.subWord(1), acc);

代码示例来源:origin: de.learnlib/learnlib-counterexamples

/**
 * Returns all suffixes of the counterexample word as distinguishing suffixes, after stripping a maximal one-letter
 * extension of an access sequence, as suggested by Shahbaz.
 *
 * @param ceQuery
 *         the counterexample query
 * @param asTransformer
 *         the access sequence transformer
 *
 * @return all suffixes from the counterexample after stripping a maximal one-letter extension of an access
 * sequence.
 */
public static <I, D> List<Word<I>> findShahbaz(Query<I, D> ceQuery, AccessSequenceTransformer<I> asTransformer) {
  Word<I> queryWord = ceQuery.getInput();
  int queryLen = queryWord.length();
  Word<I> prefix = ceQuery.getPrefix();
  int i = prefix.length();
  while (i <= queryLen) {
    Word<I> nextPrefix = queryWord.prefix(i);
    if (!asTransformer.isAccessSequence(nextPrefix)) {
      break;
    }
    i++;
  }
  return queryWord.subWord(i).suffixes(false);
}

代码示例来源:origin: de.learnlib/learnlib-adt

final Word<I> ua = ceInput.prefix(suffixIdx);
final I a = ceInput.getSymbol(suffixIdx - 1);
final Word<I> v = ceInput.subWord(suffixIdx);

代码示例来源:origin: de.learnlib/learnlib-discrimination-tree

protected boolean refineHypothesisSingle(DefaultQuery<I, D> ceQuery) {
  if (!MQUtil.isCounterexample(ceQuery, getHypothesisModel())) {
    return false;
  }
  int suffixIdx = suffixFinder.findSuffixIndex(ceQuery, hypothesis, getHypothesisModel(), oracle);
  if (suffixIdx == -1) {
    throw new AssertionError("Suffix finder does not work correctly, found no suffix for valid counterexample");
  }
  Word<I> input = ceQuery.getInput();
  Word<I> oldStateAs = input.prefix(suffixIdx);
  HState<I, D, SP, TP> oldState = hypothesis.getState(oldStateAs);
  AbstractWordBasedDTNode<I, D, HState<I, D, SP, TP>> oldDt = oldState.getDTLeaf();
  Word<I> newPredAs = input.prefix(suffixIdx - 1);
  HState<I, D, SP, TP> newPred = hypothesis.getState(newPredAs);
  I transSym = input.getSymbol(suffixIdx - 1);
  int transIdx = alphabet.getSymbolIndex(transSym);
  HTransition<I, D, SP, TP> trans = newPred.getTransition(transIdx);
  HState<I, D, SP, TP> newState = createState(trans);
  Word<I> suffix = input.subWord(suffixIdx);
  D oldOut = oracle.answerQuery(oldState.getAccessSequence(), suffix);
  D newOut = oracle.answerQuery(newState.getAccessSequence(), suffix);
  AbstractWordBasedDTNode<I, D, HState<I, D, SP, TP>>.SplitResult sr =
      oldDt.split(suffix, oldOut, newOut, newState);
  oldState.fetchNonTreeIncoming(openTransitions);
  oldState.setDTLeaf(sr.nodeOld);
  newState.setDTLeaf(sr.nodeNew);
  updateHypothesis();
  return true;
}

代码示例来源:origin: de.learnlib/learnlib-ttt

private void splitState(OutputInconsistency<I, D> outIncons) {
  OutInconsPrefixTransformAcex<I, D> acex = deriveAcex(outIncons);
  try {
    int breakpoint = analyzer.analyzeAbstractCounterexample(acex);
    assert !acex.testEffects(breakpoint, breakpoint + 1);
    Word<I> suffix = outIncons.suffix;
    TTTState<I, D> predState = getDeterministicState(outIncons.srcState, suffix.prefix(breakpoint));
    TTTState<I, D> succState = getDeterministicState(outIncons.srcState, suffix.prefix(breakpoint + 1));
    assert getDeterministicState(predState, Word.fromLetter(suffix.getSymbol(breakpoint))) == succState;
    I sym = suffix.getSymbol(breakpoint);
    Word<I> splitSuffix = suffix.subWord(breakpoint + 1);
    TTTTransition<I, D> trans = predState.getTransition(alphabet.getSymbolIndex(sym));
    assert !trans.isTree();
    D oldOut = acex.effect(breakpoint + 1);
    D newOut = succEffect(acex.effect(breakpoint));
    splitState(trans, splitSuffix, oldOut, newOut);
  } catch (HypothesisChangedException ignored) {
  }
}

代码示例来源:origin: de.learnlib/learnlib-discrimination-tree-vpda

@Override
protected boolean refineHypothesisSingle(DefaultQuery<I, Boolean> ceQuery) {
  Word<I> ceWord = ceQuery.getInput();
  boolean hypOut = hypothesis.computeOutput(ceWord);
  if (hypOut == ceQuery.getOutput()) {
    return false;
  }
  PrefixTransformAcex acex = new PrefixTransformAcex(Word.epsilon(), new ContextPair<>(Word.epsilon(), ceWord));
  acex.setEffect(0, !hypOut);
  acex.setEffect(acex.getLength() - 1, hypOut);
  int breakpoint = analyzer.analyzeAbstractCounterexample(acex);
  Word<I> prefix = ceWord.prefix(breakpoint);
  I act = ceWord.getSymbol(breakpoint);
  Word<I> suffix = ceWord.subWord(breakpoint + 1);
  State<HypLoc<I>> state = hypothesis.getState(prefix);
  State<HypLoc<I>> succState = hypothesis.getSuccessor(state, act);
  ContextPair<I> context = new ContextPair<>(transformAccessSequence(succState.getStackContents()), suffix);
  AbstractHypTrans<I> trans = hypothesis.getInternalTransition(state, act);
  HypLoc<I> newLoc = makeTree(trans);
  DTNode<I> oldDtNode = succState.getLocation().getLeaf();
  openTransitions.addAll(oldDtNode.getIncoming());
  DTNode<I>.SplitResult children = oldDtNode.split(context, acex.effect(breakpoint), acex.effect(breakpoint + 1));
  link(children.nodeOld, newLoc);
  link(children.nodeNew, succState.getLocation());
  initializeLocation(trans.getTreeTarget());
  closeTransitions();
  return true;
}

相关文章