当前位置: 首页>>代码示例>>Java>>正文


Java IntSequenceOutputs.getSingleton方法代码示例

本文整理汇总了Java中org.apache.lucene.util.fst.IntSequenceOutputs.getSingleton方法的典型用法代码示例。如果您正苦于以下问题:Java IntSequenceOutputs.getSingleton方法的具体用法?Java IntSequenceOutputs.getSingleton怎么用?Java IntSequenceOutputs.getSingleton使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.util.fst.IntSequenceOutputs的用法示例。


在下文中一共展示了IntSequenceOutputs.getSingleton方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: affixFST

import org.apache.lucene.util.fst.IntSequenceOutputs; //导入方法依赖的package包/类
private FST<IntsRef> affixFST(TreeMap<String,List<Integer>> affixes) throws IOException {
  IntSequenceOutputs outputs = IntSequenceOutputs.getSingleton();
  Builder<IntsRef> builder = new Builder<>(FST.INPUT_TYPE.BYTE4, outputs);
  IntsRefBuilder scratch = new IntsRefBuilder();
  for (Map.Entry<String,List<Integer>> entry : affixes.entrySet()) {
    Util.toUTF32(entry.getKey(), scratch);
    List<Integer> entries = entry.getValue();
    IntsRef output = new IntsRef(entries.size());
    for (Integer c : entries) {
      output.ints[output.length++] = c;
    }
    builder.add(scratch.get(), output);
  }
  return builder.finish();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:Dictionary.java

示例2: Dictionary

import org.apache.lucene.util.fst.IntSequenceOutputs; //导入方法依赖的package包/类
/**
 * Creates a new Dictionary containing the information read from the provided InputStreams to hunspell affix
 * and dictionary files.
 * You have to close the provided InputStreams yourself.
 *
 * @param affix InputStream for reading the hunspell affix file (won't be closed).
 * @param dictionaries InputStream for reading the hunspell dictionary files (won't be closed).
 * @throws IOException Can be thrown while reading from the InputStreams
 * @throws ParseException Can be thrown if the content of the files does not meet expected formats
 */
public Dictionary(InputStream affix, List<InputStream> dictionaries, boolean ignoreCase) throws IOException, ParseException {
  this.ignoreCase = ignoreCase;
  this.needsInputCleaning = ignoreCase;
  this.needsOutputCleaning = false; // set if we have an OCONV
  flagLookup.add(new BytesRef()); // no flags -> ord 0

  File aff = File.createTempFile("affix", "aff", tempDir);
  OutputStream out = new BufferedOutputStream(new FileOutputStream(aff));
  InputStream aff1 = null;
  InputStream aff2 = null;
  try {
    // copy contents of affix stream to temp file
    final byte [] buffer = new byte [1024 * 8];
    int len;
    while ((len = affix.read(buffer)) > 0) {
      out.write(buffer, 0, len);
    }
    out.close();
    
    // pass 1: get encoding
    aff1 = new BufferedInputStream(new FileInputStream(aff));
    String encoding = getDictionaryEncoding(aff1);
    
    // pass 2: parse affixes
    CharsetDecoder decoder = getJavaEncoding(encoding);
    aff2 = new BufferedInputStream(new FileInputStream(aff));
    readAffixFile(aff2, decoder);
    
    // read dictionary entries
    IntSequenceOutputs o = IntSequenceOutputs.getSingleton();
    Builder<IntsRef> b = new Builder<>(FST.INPUT_TYPE.BYTE4, o);
    readDictionaryFiles(dictionaries, decoder, b);
    words = b.finish();
    aliases = null; // no longer needed
    morphAliases = null; // no longer needed
  } finally {
    IOUtils.closeWhileHandlingException(out, aff1, aff2);
    aff.delete();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:51,代码来源:Dictionary.java


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