org.apache.lucene.util.automaton.Automata.makeString()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(107)

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

Automata.makeString介绍

[英]Returns a new (deterministic) automaton that accepts the single given string.
[中]返回接受单个给定字符串的新(确定性)自动机。

代码示例

代码示例来源:origin: org.apache.lucene/lucene-core

assert prefix != null;
if (n == 0) {
 return Automata.makeString(prefix + UnicodeUtil.newString(word, 0, word.length));

代码示例来源:origin: org.elasticsearch/elasticsearch

/** Return an {@link Automaton} that matches the given pattern. */
public static Automaton simpleMatchToAutomaton(String pattern) {
  List<Automaton> automata = new ArrayList<>();
  int previous = 0;
  for (int i = pattern.indexOf('*'); i != -1; i = pattern.indexOf('*', i + 1)) {
    automata.add(Automata.makeString(pattern.substring(previous, i)));
    automata.add(Automata.makeAnyString());
    previous = i + 1;
  }
  automata.add(Automata.makeString(pattern.substring(previous)));
  return Operations.concatenate(automata);
}

代码示例来源:origin: org.apache.lucene/lucene-core

break;
case REGEXP_STRING:
 a = Automata.makeString(s);
 break;
case REGEXP_ANYSTRING:

代码示例来源:origin: org.elasticsearch/elasticsearch

for (IntsRef string; (string = finiteStrings.next()) != null;) {
 if (string.length <= nonFuzzyPrefix || string.length < minFuzzyLength) {
  subs.add(Automata.makeString(string.ints, string.offset, string.length));
 } else {
  int ints[] = new int[string.length-nonFuzzyPrefix];

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

@Override
public Automaton toAutomaton() {
  Automaton automaton;
  if(precisions == null || precisions.length == 0) {
     automaton = Automata.makeString(location);
  } else {
    automaton = Automata.makeString(
      location.substring(0, Math.max(1, Math.min(location.length(), precisions[0]))));
    for (int i = 1; i < precisions.length; i++) {
      final String cell = location.substring(0, Math.max(1, Math.min(location.length(), precisions[i])));
      automaton = Operations.union(automaton, Automata.makeString(cell));
    }
  }
  return automaton;
}

代码示例来源:origin: org.codelibs/elasticsearch-querybuilders

@Override
public Automaton toAutomaton() {
  Automaton automaton;
  if(precisions == null || precisions.length == 0) {
     automaton = Automata.makeString(location);
  } else {
    automaton = Automata.makeString(
      location.substring(0, Math.max(1, Math.min(location.length(), precisions[0]))));
    for (int i = 1; i < precisions.length; i++) {
      final String cell = location.substring(0, Math.max(1, Math.min(location.length(), precisions[i])));
      automaton = Operations.union(automaton, Automata.makeString(cell));
    }
  }
  return automaton;
}

代码示例来源:origin: harbby/presto-connectors

@Override
public Automaton toAutomaton() {
  Automaton automaton;
  if(precisions == null || precisions.length == 0) {
     automaton = Automata.makeString(location);
  } else {
    automaton = Automata.makeString(location.substring(0, Math.max(1, Math.min(location.length(), precisions[0]))));
    for (int i = 1; i < precisions.length; i++) {
      final String cell = location.substring(0, Math.max(1, Math.min(location.length(), precisions[i])));
      automaton = Operations.union(automaton, Automata.makeString(cell));
    }
  }
  return automaton;
}

代码示例来源:origin: org.codelibs/elasticsearch-querybuilders

@Override
public Automaton toAutomaton() {
  List<Automaton> automatons = new ArrayList<>();
  for (CharSequence value : values) {
    automatons.add(Automata.makeString(value.toString()));
  }
  return Operations.union(automatons);
}

代码示例来源:origin: apache/servicemix-bundles

/** Return an {@link Automaton} that matches the given pattern. */
public static Automaton simpleMatchToAutomaton(String pattern) {
  List<Automaton> automata = new ArrayList<>();
  int previous = 0;
  for (int i = pattern.indexOf('*'); i != -1; i = pattern.indexOf('*', i + 1)) {
    automata.add(Automata.makeString(pattern.substring(previous, i)));
    automata.add(Automata.makeAnyString());
    previous = i + 1;
  }
  automata.add(Automata.makeString(pattern.substring(previous)));
  return Operations.concatenate(automata);
}

代码示例来源:origin: org.codelibs/elasticsearch-querybuilders

/** Return an {Automaton} that matches the given pattern. */
public static Automaton simpleMatchToAutomaton(String pattern) {
  List<Automaton> automata = new ArrayList<>();
  int previous = 0;
  for (int i = pattern.indexOf('*'); i != -1; i = pattern.indexOf('*', i + 1)) {
    automata.add(Automata.makeString(pattern.substring(previous, i)));
    automata.add(Automata.makeAnyString());
    previous = i + 1;
  }
  automata.add(Automata.makeString(pattern.substring(previous)));
  return Operations.concatenate(automata);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

@Override
public Automaton toAutomaton() {
  List<Automaton> automatons = new ArrayList<>();
  for (CharSequence value : values) {
    automatons.add(Automata.makeString(value.toString()));
  }
  return Operations.union(automatons);
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/** Return an {@link Automaton} that matches the given pattern. */
public static Automaton simpleMatchToAutomaton(String pattern) {
  List<Automaton> automata = new ArrayList<>();
  int previous = 0;
  for (int i = pattern.indexOf('*'); i != -1; i = pattern.indexOf('*', i + 1)) {
    automata.add(Automata.makeString(pattern.substring(previous, i)));
    automata.add(Automata.makeAnyString());
    previous = i + 1;
  }
  automata.add(Automata.makeString(pattern.substring(previous)));
  return Operations.concatenate(automata);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

/** Return an {@link Automaton} that matches the given pattern. */
public static Automaton simpleMatchToAutomaton(String pattern) {
  List<Automaton> automata = new ArrayList<>();
  int previous = 0;
  for (int i = pattern.indexOf('*'); i != -1; i = pattern.indexOf('*', i + 1)) {
    automata.add(Automata.makeString(pattern.substring(previous, i)));
    automata.add(Automata.makeAnyString());
    previous = i + 1;
  }
  automata.add(Automata.makeString(pattern.substring(previous)));
  return Operations.concatenate(automata);
}

代码示例来源:origin: harbby/presto-connectors

@Override
public Automaton toAutomaton() {
  List<Automaton> automatons = new ArrayList<>();
  for (CharSequence value : values) {
    automatons.add(Automata.makeString(value.toString()));
  }
  return Operations.union(automatons);
}

代码示例来源:origin: wikimedia/search-highlighter

protected void flattenPrefixQuery(BytesRef bytes, float boost, Object sourceOverride,
    Callback callback) {
  // Should be safe not to copy this because it is fixed...
  if (!sentAutomata.add(bytes)) {
    return;
  }
  Object source = sourceOverride == null ? bytes : sourceOverride;
  Automaton automaton = Automata.makeString(bytes.utf8ToString());
  automaton = Operations.concatenate(automaton, Automata.makeAnyString());
  callback.flattened(automaton, boost, source.hashCode());
}

代码示例来源:origin: harbby/presto-connectors

for (IntsRef string; (string = finiteStrings.next()) != null;) {
 if (string.length <= nonFuzzyPrefix || string.length < minFuzzyLength) {
  subs.add(Automata.makeString(string.ints, string.offset, string.length));
 } else {
  int ints[] = new int[string.length-nonFuzzyPrefix];

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

for (IntsRef string; (string = finiteStrings.next()) != null;) {
 if (string.length <= nonFuzzyPrefix || string.length < minFuzzyLength) {
  subs.add(Automata.makeString(string.ints, string.offset, string.length));
 } else {
  int ints[] = new int[string.length-nonFuzzyPrefix];

代码示例来源:origin: harbby/presto-connectors

private static Automaton toContextAutomaton(final Map<IntsRef, ContextMetaData> contexts, final boolean matchAllContexts) {
 final Automaton matchAllAutomaton = Operations.repeat(Automata.makeAnyString());
 final Automaton sep = Automata.makeChar(ContextSuggestField.CONTEXT_SEPARATOR);
 if (matchAllContexts || contexts.size() == 0) {
  return Operations.concatenate(matchAllAutomaton, sep);
 } else {
  Automaton contextsAutomaton = null;
  for (Map.Entry<IntsRef, ContextMetaData> entry : contexts.entrySet()) {
   final ContextMetaData contextMetaData = entry.getValue();
   final IntsRef ref = entry.getKey();
   Automaton contextAutomaton = Automata.makeString(ref.ints, ref.offset, ref.length);
   if (contextMetaData.exact == false) {
    contextAutomaton = Operations.concatenate(contextAutomaton, matchAllAutomaton);
   }
   contextAutomaton = Operations.concatenate(contextAutomaton, sep);
   if (contextsAutomaton == null) {
    contextsAutomaton = contextAutomaton;
   } else {
    contextsAutomaton = Operations.union(contextsAutomaton, contextAutomaton);
   }
  }
  return contextsAutomaton;
 }
}

代码示例来源:origin: apache/servicemix-bundles

for (IntsRef string; (string = finiteStrings.next()) != null;) {
 if (string.length <= nonFuzzyPrefix || string.length < minFuzzyLength) {
  subs.add(Automata.makeString(string.ints, string.offset, string.length));
 } else {
  int ints[] = new int[string.length-nonFuzzyPrefix];

代码示例来源:origin: wikimedia/search-highlighter

protected void flattenQuery(FuzzyQuery query, float pathBoost, Object sourceOverride,
    IndexReader reader, Callback callback) {
  float boost = pathBoost;
  if (query.getMaxEdits() == 0) {
    callback.flattened(query.getTerm().bytes(), boost, sourceOverride);
  }
  String term = query.getTerm().bytes().utf8ToString();
  if (query.getPrefixLength() >= term.length()) {
    callback.flattened(query.getTerm().bytes(), boost, sourceOverride);
    return;
  }
  FuzzyQueryInfo key = new FuzzyQueryInfo(term, query);
  if (!sentAutomata.add(key)) {
    return;
  }
  // Make an effort to resolve the fuzzy query to an automata
  String fuzzed = term.substring(query.getPrefixLength());
  int editDistance = query.getMaxEdits();
  if (editDistance > LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE) {
    editDistance = LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE;
  }
  LevenshteinAutomata automata = new LevenshteinAutomata(fuzzed, query.getTranspositions());
  Automaton automaton = automata.toAutomaton(editDistance);
  if (query.getPrefixLength() > 0) {
    Automaton prefix = Automata.makeString(term.substring(0, query.getPrefixLength()));
    automaton = Operations.concatenate(prefix, automaton);
  }
  Object source = sourceOverride == null ? key : sourceOverride;
  callback.flattened(automaton, boost, source.hashCode());
}

相关文章