• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Pair类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.lucene.util.fst.PairOutputs.Pair的典型用法代码示例。如果您正苦于以下问题:Java Pair类的具体用法?Java Pair怎么用?Java Pair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Pair类属于org.apache.lucene.util.fst.PairOutputs包,在下文中一共展示了Pair类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getFullPrefixPaths

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
@Override
protected List<FSTUtil.Path<Pair<Long,BytesRef>>> getFullPrefixPaths(List<FSTUtil.Path<Pair<Long,BytesRef>>> prefixPaths,
                                                                     Automaton lookupAutomaton,
                                                                     FST<Pair<Long,BytesRef>> fst)
  throws IOException {

  // TODO: right now there's no penalty for fuzzy/edits,
  // ie a completion whose prefix matched exactly what the
  // user typed gets no boost over completions that
  // required an edit, which get no boost over completions
  // requiring two edits.  I suspect a multiplicative
  // factor is appropriate (eg, say a fuzzy match must be at
  // least 2X better weight than the non-fuzzy match to
  // "compete") ... in which case I think the wFST needs
  // to be log weights or something ...

  Automaton levA = convertAutomaton(toLevenshteinAutomata(lookupAutomaton));
  /*
    Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), StandardCharsets.UTF_8);
    w.write(levA.toDot());
    w.close();
    System.out.println("Wrote LevA to out.dot");
  */
  return FSTUtil.intersectPrefixPaths(levA, fst);
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:FuzzySuggester.java


示例2: pushFrame

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
IDVersionSegmentTermsEnumFrame pushFrame(FST.Arc<Pair<BytesRef,Long>> arc, Pair<BytesRef,Long> frameData, int length) throws IOException {
  scratchReader.reset(frameData.output1.bytes, frameData.output1.offset, frameData.output1.length);
  final long code = scratchReader.readVLong();
  final long fpSeek = code >>> VersionBlockTreeTermsWriter.OUTPUT_FLAGS_NUM_BITS;
  final IDVersionSegmentTermsEnumFrame f = getFrame(1+currentFrame.ord);
  f.maxIDVersion = Long.MAX_VALUE - frameData.output2;
  f.hasTerms = (code & VersionBlockTreeTermsWriter.OUTPUT_FLAG_HAS_TERMS) != 0;
  f.hasTermsOrig = f.hasTerms;
  f.isFloor = (code & VersionBlockTreeTermsWriter.OUTPUT_FLAG_IS_FLOOR) != 0;
  if (f.isFloor) {
    f.setFloorData(scratchReader, frameData.output1);
  }
  pushFrame(arc, fpSeek, length);

  return f;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:IDVersionSegmentTermsEnum.java


示例3: getFullPrefixPaths

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
@Override
protected List<FSTUtil.Path<Pair<Long,BytesRef>>> getFullPrefixPaths(List<FSTUtil.Path<Pair<Long,BytesRef>>> prefixPaths,
                                                                     Automaton lookupAutomaton,
                                                                     FST<Pair<Long,BytesRef>> fst)
  throws IOException {

  // TODO: right now there's no penalty for fuzzy/edits,
  // ie a completion whose prefix matched exactly what the
  // user typed gets no boost over completions that
  // required an edit, which get no boost over completions
  // requiring two edits.  I suspect a multiplicative
  // factor is appropriate (eg, say a fuzzy match must be at
  // least 2X better weight than the non-fuzzy match to
  // "compete") ... in which case I think the wFST needs
  // to be log weights or something ...

  Automaton levA = toLevenshteinAutomata(lookupAutomaton);
  /*
    Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), "UTF-8");
    w.write(levA.toDot());
    w.close();
    System.out.println("Wrote LevA to out.dot");
  */
  return FSTUtil.intersectPrefixPaths(levA, fst);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:26,代码来源:FuzzySuggester.java


示例4: getFullPrefixPaths

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
@Override
protected List<FSTUtil.Path<Pair<Long,BytesRef>>> getFullPrefixPaths(List<FSTUtil.Path<Pair<Long,BytesRef>>> prefixPaths,
                                                                     Automaton lookupAutomaton,
                                                                     FST<Pair<Long,BytesRef>> fst)
  throws IOException {

  // TODO: right now there's no penalty for fuzzy/edits,
  // ie a completion whose prefix matched exactly what the
  // user typed gets no boost over completions that
  // required an edit, which get no boost over completions
  // requiring two edits.  I suspect a multiplicative
  // factor is appropriate (eg, say a fuzzy match must be at
  // least 2X better weight than the non-fuzzy match to
  // "compete") ... in which case I think the wFST needs
  // to be log weights or something ...

  Automaton levA = convertAutomaton(toLevenshteinAutomata(lookupAutomaton));
  /*
    Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"), "UTF-8");
    w.write(levA.toDot());
    w.close();
    System.out.println("Wrote LevA to out.dot");
  */
  return FSTUtil.intersectPrefixPaths(levA, fst);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:26,代码来源:FuzzySuggester.java


示例5: getFullPrefixPaths

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
/** Returns all completion paths to initialize the search. */
protected List<FSTUtil.Path<Pair<Long,BytesRef>>> getFullPrefixPaths(List<FSTUtil.Path<Pair<Long,BytesRef>>> prefixPaths,
                                                                     Automaton lookupAutomaton,
                                                                     FST<Pair<Long,BytesRef>> fst)
  throws IOException {
  return prefixPaths;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:XAnalyzingSuggester.java


示例6: XAnalyzingSuggester

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
/**
 * Creates a new suggester.
 *
 * @param indexAnalyzer Analyzer that will be used for
 *   analyzing suggestions while building the index.
 * @param queryAnalyzer Analyzer that will be used for
 *   analyzing query text during lookup
 * @param options see {@link #EXACT_FIRST}, {@link #PRESERVE_SEP}
 * @param maxSurfaceFormsPerAnalyzedForm Maximum number of
 *   surface forms to keep for a single analyzed form.
 *   When there are too many surface forms we discard the
 *   lowest weighted ones.
 * @param maxGraphExpansions Maximum number of graph paths
 *   to expand from the analyzed form.  Set this to -1 for
 *   no limit.
 */
public XAnalyzingSuggester(Analyzer indexAnalyzer, Automaton queryPrefix, Analyzer queryAnalyzer, int options, int maxSurfaceFormsPerAnalyzedForm, int maxGraphExpansions,
                           boolean preservePositionIncrements, FST<Pair<Long, BytesRef>> fst, boolean hasPayloads, int maxAnalyzedPathsForOneInput,
                           int sepLabel, int payloadSep, int endByte, int holeCharacter) {
    // SIMON EDIT: I added fst, hasPayloads and maxAnalyzedPathsForOneInput
  this.indexAnalyzer = indexAnalyzer;
  this.queryAnalyzer = queryAnalyzer;
  this.fst = fst;
  this.hasPayloads = hasPayloads;
  if ((options & ~(EXACT_FIRST | PRESERVE_SEP)) != 0) {
    throw new IllegalArgumentException("options should only contain EXACT_FIRST and PRESERVE_SEP; got " + options);
  }
  this.exactFirst = (options & EXACT_FIRST) != 0;
  this.preserveSep = (options & PRESERVE_SEP) != 0;

  // FLORIAN EDIT: I added <code>queryPrefix</code> for context dependent suggestions
  this.queryPrefix = queryPrefix;

  // NOTE: this is just an implementation limitation; if
  // somehow this is a problem we could fix it by using
  // more than one byte to disambiguate ... but 256 seems
  // like it should be way more then enough.
  if (maxSurfaceFormsPerAnalyzedForm <= 0 || maxSurfaceFormsPerAnalyzedForm > 256) {
    throw new IllegalArgumentException("maxSurfaceFormsPerAnalyzedForm must be > 0 and < 256 (got: " + maxSurfaceFormsPerAnalyzedForm + ")");
  }
  this.maxSurfaceFormsPerAnalyzedForm = maxSurfaceFormsPerAnalyzedForm;

  if (maxGraphExpansions < 1 && maxGraphExpansions != -1) {
    throw new IllegalArgumentException("maxGraphExpansions must -1 (no limit) or > 0 (got: " + maxGraphExpansions + ")");
  }
  this.maxGraphExpansions = maxGraphExpansions;
  this.maxAnalyzedPathsForOneInput = maxAnalyzedPathsForOneInput;
  this.preservePositionIncrements = preservePositionIncrements;
  this.sepLabel = sepLabel;
  this.payloadSep = payloadSep;
  this.endByte = endByte;
  this.holeCharacter = holeCharacter;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:54,代码来源:XAnalyzingSuggester.java


示例7: AnalyzingSuggestHolder

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
public AnalyzingSuggestHolder(boolean preserveSep, boolean preservePositionIncrements, int maxSurfaceFormsPerAnalyzedForm, int maxGraphExpansions, boolean hasPayloads, int maxAnalyzedPathsForOneInput, FST<Pair<Long, BytesRef>> fst, int sepLabel, int payloadSep, int endByte, int holeCharacter) {
    this.preserveSep = preserveSep;
    this.preservePositionIncrements = preservePositionIncrements;
    this.maxSurfaceFormsPerAnalyzedForm = maxSurfaceFormsPerAnalyzedForm;
    this.maxGraphExpansions = maxGraphExpansions;
    this.hasPayloads = hasPayloads;
    this.maxAnalyzedPathsForOneInput = maxAnalyzedPathsForOneInput;
    this.fst = fst;
    this.sepLabel = sepLabel;
    this.payloadSep = payloadSep;
    this.endByte = endByte;
    this.holeCharacter = holeCharacter;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:14,代码来源:AnalyzingCompletionLookupProvider.java


示例8: getFullPrefixPaths

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
/** Returns all prefix paths to initialize the search. */
protected List<FSTUtil.Path<Pair<Long,BytesRef>>> getFullPrefixPaths(List<FSTUtil.Path<Pair<Long,BytesRef>>> prefixPaths,
                                                                     Automaton lookupAutomaton,
                                                                     FST<Pair<Long,BytesRef>> fst)
  throws IOException {
  return prefixPaths;
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:AnalyzingSuggester.java


示例9: getArc

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
private FST.Arc<Pair<BytesRef,Long>> getArc(int ord) {
  if (ord >= arcs.length) {
    @SuppressWarnings({"rawtypes","unchecked"}) final FST.Arc<Pair<BytesRef,Long>>[] next =
    new FST.Arc[ArrayUtil.oversize(1+ord, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
    System.arraycopy(arcs, 0, next, 0, arcs.length);
    for(int arcOrd=arcs.length;arcOrd<next.length;arcOrd++) {
      next[arcOrd] = new FST.Arc<>();
    }
    arcs = next;
  }
  return arcs[ord];
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:IDVersionSegmentTermsEnum.java


示例10: VersionFieldReader

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
VersionFieldReader(VersionBlockTreeTermsReader parent, FieldInfo fieldInfo, long numTerms, Pair<BytesRef,Long> rootCode, long sumTotalTermFreq, long sumDocFreq, int docCount,
            long indexStartFP, int longsSize, IndexInput indexIn, BytesRef minTerm, BytesRef maxTerm) throws IOException {
  assert numTerms > 0;
  this.fieldInfo = fieldInfo;
  //DEBUG = BlockTreeTermsReader.DEBUG && fieldInfo.name.equals("id");
  this.parent = parent;
  this.numTerms = numTerms;
  this.sumTotalTermFreq = sumTotalTermFreq; 
  this.sumDocFreq = sumDocFreq; 
  this.docCount = docCount;
  this.indexStartFP = indexStartFP;
  this.rootCode = rootCode;
  this.longsSize = longsSize;
  this.minTerm = minTerm;
  this.maxTerm = maxTerm;
  // if (DEBUG) {
  //   System.out.println("BTTR: seg=" + segment + " field=" + fieldInfo.name + " rootBlockCode=" + rootCode + " divisor=" + indexDivisor);
  // }

  rootBlockFP = (new ByteArrayDataInput(rootCode.output1.bytes, rootCode.output1.offset, rootCode.output1.length)).readVLong() >>> VersionBlockTreeTermsWriter.OUTPUT_FLAGS_NUM_BITS;

  if (indexIn != null) {
    final IndexInput clone = indexIn.clone();
    //System.out.println("start=" + indexStartFP + " field=" + fieldInfo.name);
    clone.seek(indexStartFP);
    index = new FST<>(clone, VersionBlockTreeTermsWriter.FST_OUTPUTS);
      
    /*
      if (false) {
      final String dotFileName = segment + "_" + fieldInfo.name + ".dot";
      Writer w = new OutputStreamWriter(new FileOutputStream(dotFileName));
      Util.toDot(index, w, false, false);
      System.out.println("FST INDEX: SAVED to " + dotFileName);
      w.close();
      }
    */
  } else {
    index = null;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:41,代码来源:VersionFieldReader.java


示例11: FieldMetaData

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
public FieldMetaData(FieldInfo fieldInfo, Pair<BytesRef,Long> rootCode, long numTerms, long indexStartFP, int longsSize,
                     BytesRef minTerm, BytesRef maxTerm) {
  assert numTerms > 0;
  this.fieldInfo = fieldInfo;
  assert rootCode != null: "field=" + fieldInfo.name + " numTerms=" + numTerms;
  this.rootCode = rootCode;
  this.indexStartFP = indexStartFP;
  this.numTerms = numTerms;
  this.longsSize = longsSize;
  this.minTerm = minTerm;
  this.maxTerm = maxTerm;
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:VersionBlockTreeTermsWriter.java


示例12: PendingBlock

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
public PendingBlock(BytesRef prefix, long maxVersion, long fp, boolean hasTerms, boolean isFloor, int floorLeadByte, List<FST<Pair<BytesRef,Long>>> subIndices) {
  super(false);
  this.prefix = prefix;
  this.maxVersion = maxVersion;
  this.fp = fp;
  this.hasTerms = hasTerms;
  this.isFloor = isFloor;
  this.floorLeadByte = floorLeadByte;
  this.subIndices = subIndices;
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:VersionBlockTreeTermsWriter.java


示例13: append

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
private void append(Builder<Pair<BytesRef,Long>> builder, FST<Pair<BytesRef,Long>> subIndex, IntsRefBuilder scratchIntsRef) throws IOException {
  final BytesRefFSTEnum<Pair<BytesRef,Long>> subIndexEnum = new BytesRefFSTEnum<>(subIndex);
  BytesRefFSTEnum.InputOutput<Pair<BytesRef,Long>> indexEnt;
  while((indexEnt = subIndexEnum.next()) != null) {
    //if (DEBUG) {
    //  System.out.println("      add sub=" + indexEnt.input + " " + indexEnt.input + " output=" + indexEnt.output);
    //}
    builder.add(Util.toIntsRef(indexEnt.input, scratchIntsRef), indexEnt.output);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:VersionBlockTreeTermsWriter.java


示例14: testShortestPathsWFST

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
/** like testShortestPaths, but uses pairoutputs so we have both a weight and an output */
public void testShortestPathsWFST() throws Exception {

  PairOutputs<Long,Long> outputs = new PairOutputs<>(
      PositiveIntOutputs.getSingleton(), // weight
      PositiveIntOutputs.getSingleton()  // output
  );

  final Builder<Pair<Long,Long>> builder = new Builder<>(FST.INPUT_TYPE.BYTE1, outputs);

  final IntsRefBuilder scratch = new IntsRefBuilder();
  builder.add(Util.toIntsRef(new BytesRef("aab"), scratch), outputs.newPair(22L, 57L));
  builder.add(Util.toIntsRef(new BytesRef("aac"), scratch), outputs.newPair(7L, 36L));
  builder.add(Util.toIntsRef(new BytesRef("ax"), scratch), outputs.newPair(17L, 85L));
  final FST<Pair<Long,Long>> fst = builder.finish();
  //Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"));
  //Util.toDot(fst, w, false, false);
  //w.close();

  Util.TopResults<Pair<Long,Long>> res = Util.shortestPaths(fst,
                                                           fst.getFirstArc(new FST.Arc<Pair<Long,Long>>()),
                                                           outputs.getNoOutput(),
                                                           minPairWeightComparator,
                                                           3,
                                                           true);
  assertTrue(res.isComplete);
  assertEquals(3, res.topN.size());

  assertEquals(Util.toIntsRef(new BytesRef("aac"), scratch), res.topN.get(0).input);
  assertEquals(7L, res.topN.get(0).output.output1.longValue()); // weight
  assertEquals(36L, res.topN.get(0).output.output2.longValue()); // output

  assertEquals(Util.toIntsRef(new BytesRef("ax"), scratch), res.topN.get(1).input);
  assertEquals(17L, res.topN.get(1).output.output1.longValue()); // weight
  assertEquals(85L, res.topN.get(1).output.output2.longValue()); // output

  assertEquals(Util.toIntsRef(new BytesRef("aab"), scratch), res.topN.get(2).input);
  assertEquals(22L, res.topN.get(2).output.output1.longValue()); // weight
  assertEquals(57L, res.topN.get(2).output.output2.longValue()); // output
}
 
开发者ID:europeana,项目名称:search,代码行数:41,代码来源:TestFSTs.java


示例15: load

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
@Override
public boolean load(InputStream input) throws IOException {
  DataInput dataIn = new InputStreamDataInput(input);
  try {
    this.fst = new FST<Pair<Long,BytesRef>>(dataIn, new PairOutputs<Long,BytesRef>(PositiveIntOutputs.getSingleton(true), ByteSequenceOutputs.getSingleton()));
    maxAnalyzedPathsForOneInput = dataIn.readVInt();
  } finally {
    IOUtils.close(input);
  }
  return true;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:12,代码来源:AnalyzingSuggester.java


示例16: testShortestPathsWFST

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
/** like testShortestPaths, but uses pairoutputs so we have both a weight and an output */
public void testShortestPathsWFST() throws Exception {

  PairOutputs<Long,Long> outputs = new PairOutputs<Long,Long>(
      PositiveIntOutputs.getSingleton(true), // weight
      PositiveIntOutputs.getSingleton(true)  // output
  );
  
  final Builder<Pair<Long,Long>> builder = new Builder<Pair<Long,Long>>(FST.INPUT_TYPE.BYTE1, outputs);

  final IntsRef scratch = new IntsRef();
  builder.add(Util.toIntsRef(new BytesRef("aab"), scratch), outputs.newPair(22L, 57L));
  builder.add(Util.toIntsRef(new BytesRef("aac"), scratch), outputs.newPair(7L, 36L));
  builder.add(Util.toIntsRef(new BytesRef("ax"), scratch), outputs.newPair(17L, 85L));
  final FST<Pair<Long,Long>> fst = builder.finish();
  //Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"));
  //Util.toDot(fst, w, false, false);
  //w.close();

  Util.MinResult<Pair<Long,Long>>[] r = Util.shortestPaths(fst,
                                                           fst.getFirstArc(new FST.Arc<Pair<Long,Long>>()),
                                                           outputs.getNoOutput(),
                                                           minPairWeightComparator,
                                                           3,
                                                           true);
  assertEquals(3, r.length);

  assertEquals(Util.toIntsRef(new BytesRef("aac"), scratch), r[0].input);
  assertEquals(7L, r[0].output.output1.longValue()); // weight
  assertEquals(36L, r[0].output.output2.longValue()); // output

  assertEquals(Util.toIntsRef(new BytesRef("ax"), scratch), r[1].input);
  assertEquals(17L, r[1].output.output1.longValue()); // weight
  assertEquals(85L, r[1].output.output2.longValue()); // output

  assertEquals(Util.toIntsRef(new BytesRef("aab"), scratch), r[2].input);
  assertEquals(22L, r[2].output.output1.longValue()); // weight
  assertEquals(57L, r[2].output.output2.longValue()); // output
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:40,代码来源:TestFSTs.java


示例17: load

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
@Override
public boolean load(DataInput input) throws IOException {
  count = input.readVLong();
  this.fst = new FST<Pair<Long,BytesRef>>(input, new PairOutputs<Long,BytesRef>(PositiveIntOutputs.getSingleton(), ByteSequenceOutputs.getSingleton()));
  maxAnalyzedPathsForOneInput = input.readVInt();
  hasPayloads = input.readByte() == 1;
  return true;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:9,代码来源:AnalyzingSuggester.java


示例18: load

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
@Override
public boolean load(InputStream input) throws IOException {
  DataInput dataIn = new InputStreamDataInput(input);
  try {
    this.fst = new FST<Pair<Long,BytesRef>>(dataIn, new PairOutputs<Long,BytesRef>(PositiveIntOutputs.getSingleton(), ByteSequenceOutputs.getSingleton()));
    maxAnalyzedPathsForOneInput = dataIn.readVInt();
    hasPayloads = dataIn.readByte() == 1;
  } finally {
    IOUtils.close(input);
  }
  return true;
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:13,代码来源:AnalyzingSuggester.java


示例19: testShortestPathsWFST

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
/** like testShortestPaths, but uses pairoutputs so we have both a weight and an output */
public void testShortestPathsWFST() throws Exception {

  PairOutputs<Long,Long> outputs = new PairOutputs<Long,Long>(
      PositiveIntOutputs.getSingleton(), // weight
      PositiveIntOutputs.getSingleton()  // output
  );
  
  final Builder<Pair<Long,Long>> builder = new Builder<Pair<Long,Long>>(FST.INPUT_TYPE.BYTE1, outputs);

  final IntsRef scratch = new IntsRef();
  builder.add(Util.toIntsRef(new BytesRef("aab"), scratch), outputs.newPair(22L, 57L));
  builder.add(Util.toIntsRef(new BytesRef("aac"), scratch), outputs.newPair(7L, 36L));
  builder.add(Util.toIntsRef(new BytesRef("ax"), scratch), outputs.newPair(17L, 85L));
  final FST<Pair<Long,Long>> fst = builder.finish();
  //Writer w = new OutputStreamWriter(new FileOutputStream("out.dot"));
  //Util.toDot(fst, w, false, false);
  //w.close();

  Util.MinResult<Pair<Long,Long>>[] r = Util.shortestPaths(fst,
                                                           fst.getFirstArc(new FST.Arc<Pair<Long,Long>>()),
                                                           outputs.getNoOutput(),
                                                           minPairWeightComparator,
                                                           3,
                                                           true);
  assertEquals(3, r.length);

  assertEquals(Util.toIntsRef(new BytesRef("aac"), scratch), r[0].input);
  assertEquals(7L, r[0].output.output1.longValue()); // weight
  assertEquals(36L, r[0].output.output2.longValue()); // output

  assertEquals(Util.toIntsRef(new BytesRef("ax"), scratch), r[1].input);
  assertEquals(17L, r[1].output.output1.longValue()); // weight
  assertEquals(85L, r[1].output.output2.longValue()); // output

  assertEquals(Util.toIntsRef(new BytesRef("aab"), scratch), r[2].input);
  assertEquals(22L, r[2].output.output1.longValue()); // weight
  assertEquals(57L, r[2].output.output2.longValue()); // output
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:40,代码来源:TestFSTs.java


示例20: XAnalyzingSuggester

import org.apache.lucene.util.fst.PairOutputs.Pair; //导入依赖的package包/类
/**
 * Creates a new suggester.
 *
 * @param indexAnalyzer Analyzer that will be used for
 *   analyzing suggestions while building the index.
 * @param queryAnalyzer Analyzer that will be used for
 *   analyzing query text during lookup
 * @param options see {@link #EXACT_FIRST}, {@link #PRESERVE_SEP}
 * @param maxSurfaceFormsPerAnalyzedForm Maximum number of
 *   surface forms to keep for a single analyzed form.
 *   When there are too many surface forms we discard the
 *   lowest weighted ones.
 * @param maxGraphExpansions Maximum number of graph paths
 *   to expand from the analyzed form.  Set this to -1 for
 *   no limit.
 */
public XAnalyzingSuggester(Analyzer indexAnalyzer, Automaton queryPrefix, Analyzer queryAnalyzer,
                           int options, int maxSurfaceFormsPerAnalyzedForm, int maxGraphExpansions,
                           boolean preservePositionIncrements, FST<Pair<Long, BytesRef>> fst,
                           boolean hasPayloads, int maxAnalyzedPathsForOneInput,
                           int sepLabel, int payloadSep, int endByte, int holeCharacter) {
    // SIMON EDIT: I added fst, hasPayloads and maxAnalyzedPathsForOneInput
  this.indexAnalyzer = indexAnalyzer;
  this.queryAnalyzer = queryAnalyzer;
  this.fst = fst;
  this.hasPayloads = hasPayloads;
  if ((options & ~(EXACT_FIRST | PRESERVE_SEP)) != 0) {
    throw new IllegalArgumentException("options should only contain EXACT_FIRST and PRESERVE_SEP; got " + options);
  }
  this.exactFirst = (options & EXACT_FIRST) != 0;
  this.preserveSep = (options & PRESERVE_SEP) != 0;

  // FLORIAN EDIT: I added <code>queryPrefix</code> for context dependent suggestions
  this.queryPrefix = queryPrefix;

  // NOTE: this is just an implementation limitation; if
  // somehow this is a problem we could fix it by using
  // more than one byte to disambiguate ... but 256 seems
  // like it should be way more then enough.
  if (maxSurfaceFormsPerAnalyzedForm <= 0 || maxSurfaceFormsPerAnalyzedForm > 256) {
    throw new IllegalArgumentException(
        "maxSurfaceFormsPerAnalyzedForm must be > 0 and < 256 (got: " + maxSurfaceFormsPerAnalyzedForm + ")");
  }
  this.maxSurfaceFormsPerAnalyzedForm = maxSurfaceFormsPerAnalyzedForm;

  if (maxGraphExpansions < 1 && maxGraphExpansions != -1) {
    throw new IllegalArgumentException(
        "maxGraphExpansions must -1 (no limit) or > 0 (got: " + maxGraphExpansions + ")");
  }
  this.maxGraphExpansions = maxGraphExpansions;
  this.maxAnalyzedPathsForOneInput = maxAnalyzedPathsForOneInput;
  this.preservePositionIncrements = preservePositionIncrements;
  this.sepLabel = sepLabel;
  this.payloadSep = payloadSep;
  this.endByte = endByte;
  this.holeCharacter = holeCharacter;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:58,代码来源:XAnalyzingSuggester.java



注:本文中的org.apache.lucene.util.fst.PairOutputs.Pair类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AdminOperationException类代码示例发布时间:2022-05-22
下一篇:
Java UploadFileRequest类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap