當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。