net.automatalib.words.Word类的使用及代码示例

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

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

Word介绍

[英]A word is an ordered sequence of symbols. Words are generally immutable, i.e., a single Word object will never change (unless symbol objects are modified, which is however highly discouraged).

This class provides the following static methods for creating words in the most common scenarios:

  • #epsilon() returns the empty word of length 0
  • #fromLetter(Object) turns a single letter into a word of length 1
  • #fromSymbols(Object...) creates a word from an array of symbols
  • #fromArray(Object[],int,int) creates a word from a subrange of a symbols array
  • #fromList(List)creates a word from a List of symbols

Modification operations like #append(Object) or #concat(Word...) create new objects, subsequently invoking these operations on the respective objects returned is therefore highly inefficient. If words need to be dynamically created, a WordBuilder should be used.

This is an abstract base class for word representations. Implementing classes only need to implement

  • #getSymbol(int)
  • #length()

However, for the sake of efficiency it is highly encouraged to overwrite the other methods as well, providing specialized realizations.
[中]单词是一系列有序的符号。单词通常是不变的,也就是说,单个单词对象永远不会改变(除非符号对象被修改,这是非常不鼓励的)。
此类提供了以下静态方法,用于在最常见的场景中创建单词:
*#epsilon()返回长度为0的空单词
*#fromLetter(Object)将单个字母转换为长度为1的单词
*#来自符号(对象…)从一系列符号中创建一个单词
*#fromArray(Object[],int,int)从符号数组的子范围创建一个单词
*#fromList(List)从符号列表中创建一个单词
修改操作,如#append(Object)或#concat(Word…)因此,创建新对象,然后对返回的相应对象调用这些操作是非常低效的。如果需要动态创建单词,应该使用WordBuilder。
这是用于单词表示的抽象基类。实现类只需要实现
*#getSymbol(int)
*#长度()
然而,为了提高效率,我们强烈建议覆盖其他方法,提供专门的实现。

代码示例

代码示例来源: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: net.automatalib/automata-core

@Override
public I getSymbol(int index) {
  if (index == word.length()) {
    return letter;
  }
  return word.getSymbol(index);
}

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

@Override
@Nonnull
public Word<I> get(int index) {
  if (index < 0 || index > word.length()) {
    throw new IndexOutOfBoundsException();
  }
  if (prefix) {
    return word.prefix(index);
  }
  if (reverse) {
    return word.suffix(word.length() - index);
  }
  return word.suffix(index);
}

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

@Override
public boolean isPrefixOf(Word<?> other) {
  int wordLen = word.length();
  if (wordLen >= other.length()) {
    return false;
  }
  if (!word.isPrefixOf(other)) {
    return false;
  }
  return Objects.equals(other.getSymbol(wordLen), letter);
}

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

Record<S, I> initRec = new Record<>(init, Word.epsilon(), Sets.newHashSetWithExpectedSize(inputs.size()));
bfsQueue.add(initRec);
reach.put(init, initRec);
  if (oldStateAs.isEmpty()) {
    continue;
  Word<I> asPrefix = oldStateAs.prefix(oldStateAs.length() - 1);
  S pred = automaton.getState(asPrefix);
  assert pred != null;
        "State cover was not prefix-closed: prefix of " + oldStateAs + " not in set");
  I lastSym = oldStateAs.lastSymbol();
  predRec.coveredInputs.add(lastSym);
  newStateCover.accept(Word.epsilon());
      S succ = automaton.getSuccessor(curr.state, input);
      Word<I> newAs = curr.accessSequence.append(input);

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

@Nullable
public static <I, O> DefaultQuery<I, O> reduceCounterExample(MealyMachine<?, I, ?, O> hypothesis,
                               DefaultQuery<I, Word<O>> ceQuery) {
  Word<I> cePrefix = ceQuery.getPrefix(), ceSuffix = ceQuery.getSuffix();
  Word<O> hypOut = hypothesis.computeSuffixOutput(cePrefix, ceSuffix);
  Word<O> ceOut = ceQuery.getOutput();
  assert ceOut.length() == hypOut.length();
  int mismatchIdx = findMismatch(hypOut, ceOut);
  if (mismatchIdx == NO_MISMATCH) {
    return null;
  }
  return new DefaultQuery<>(cePrefix, ceSuffix.prefix(mismatchIdx + 1), ceOut.getSymbol(mismatchIdx));
}

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

Word<I> predAs = oldTransAs.prefix(oldTransAs.length() - 1);
S pred = automaton.getState(predAs);
if (pred == null) {
      "Invalid transition: prefix of transition " + oldTransAs + " not covered by state cover");
I lastSym = oldTransAs.lastSymbol();
Record<S, I> predRec = reach.get(pred);

代码示例来源: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: net.automatalib/automata-api

@Override
public Word<I> subWordInternal(int fromIndex, int toIndex) {
  if (fromIndex > 0 || toIndex == 0) {
    return Word.epsilon();
  }
  return this;
}

代码示例来源: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-util

@Nullable
public static <I, O> DefaultQuery<I, Word<O>> shortenCounterExample(MealyMachine<?, I, ?, O> hypothesis,
                                  DefaultQuery<I, Word<O>> ceQuery) {
  Word<I> cePrefix = ceQuery.getPrefix(), ceSuffix = ceQuery.getSuffix();
  Word<O> hypOut = hypothesis.computeSuffixOutput(cePrefix, ceSuffix);
  Word<O> ceOut = ceQuery.getOutput();
  assert ceOut.length() == hypOut.length();
  int mismatchIdx = findMismatch(hypOut, ceOut);
  if (mismatchIdx == NO_MISMATCH) {
    return null;
  }
  return new DefaultQuery<>(cePrefix, ceSuffix.prefix(mismatchIdx + 1), ceOut.prefix(mismatchIdx + 1));
}

代码示例来源: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: net.automatalib/automata-api

@Override
public Spliterator<I> spliterator() {
  return Spliterators.spliterator(iterator(),
                  length(),
                  Spliterator.IMMUTABLE | Spliterator.ORDERED | Spliterator.SUBSIZED);
}

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

@Override
public boolean isSuffixOf(Word<?> other) {
  return !other.isEmpty() && Objects.equals(letter, other.lastSymbol());
}

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

public static <I> List<Word<I>> ensureSuffixCompliancy(List<Word<I>> suffixes, Alphabet<I> alphabet,
    boolean needsConsistencyCheck) {
  List<Word<I>> compSuffixes = new ArrayList<Word<I>>();
  if(needsConsistencyCheck) {
    for(int i = 0; i < alphabet.size(); i++)
      compSuffixes.add(Word.fromLetter(alphabet.getSymbol(i)));
  }
  
  for(Word<I> w : suffixes) {
    if(w.isEmpty())
      continue;
    if(needsConsistencyCheck && w.length() == 1)
      continue;
    compSuffixes.add(w);
  }
  
  return compSuffixes;
}

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

@Override
public void writeToArray(int offset, Object[] array, int tgtOffset, int length) {
  int idx = offset, arrayIdx = tgtOffset;
  for (int i = length; i > 0; i--) {
    array[arrayIdx++] = getSymbol(idx++);
  }
}

代码示例来源: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: net.automatalib/automata-api

/**
 * Creates a word from a list of symbols.
 *
 * @param symbolList
 *         the list of symbols
 *
 * @return the resulting word
 */
@Nonnull
public static <I> Word<I> fromList(List<? extends I> symbolList) {
  int siz = symbolList.size();
  if (siz == 0) {
    return epsilon();
  }
  if (siz == 1) {
    return Word.fromLetter(symbolList.get(0));
  }
  return new SharedWord<>(symbolList);
}

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

public static <I> List<Word<I>> ensureSuffixCompliancy(List<Word<I>> suffixes) {
    List<Word<I>> compSuffixes = new ArrayList<>();
    compSuffixes.add(Word.epsilon());
    for (Word<I> suff : suffixes) {
      if (!suff.isEmpty()) {
        compSuffixes.add(suff);
      }
    }

    return compSuffixes;
  }
}

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

@Override
public boolean isPrefixOf(Word<?> other) {
  return !other.isEmpty() && Objects.equals(letter, other.getSymbol(0));
}

相关文章