LUCENE-9089: update FST usage example

This commit is contained in:
Tomoko Uchida 2020-04-29 15:41:18 +09:00
parent 2dd92fc052
commit 59a8e83520
1 changed files with 9 additions and 9 deletions

View File

@ -41,14 +41,14 @@
* long outputValues[] = {5, 7, 12}; * long outputValues[] = {5, 7, 12};
* *
* PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton(); * PositiveIntOutputs outputs = PositiveIntOutputs.getSingleton();
* Builder<Long> builder = new Builder<Long>(INPUT_TYPE.BYTE1, outputs); * FSTCompiler<Long> fstCompiler = new FSTCompiler<Long>(INPUT_TYPE.BYTE1, outputs);
* BytesRef scratchBytes = new BytesRef(); * BytesRefBuilder scratchBytes = new BytesRefBuilder();
* IntsRefBuilder scratchInts = new IntsRefBuilder(); * IntsRefBuilder scratchInts = new IntsRefBuilder();
* for (int i = 0; i < inputValues.length; i++) { * for (int i = 0; i < inputValues.length; i++) {
* scratchBytes.copyChars(inputValues[i]); * scratchBytes.copyChars(inputValues[i]);
* builder.add(Util.toIntsRef(scratchBytes, scratchInts), outputValues[i]); * fstCompiler.add(Util.toIntsRef(scratchBytes.toBytesRef(), scratchInts), outputValues[i]);
* } * }
* FST<Long> fst = builder.finish(); * FST<Long> fst = fstCompiler.compile();
* </pre> * </pre>
* Retrieval by key: * Retrieval by key:
* <pre class="prettyprint"> * <pre class="prettyprint">
@ -79,11 +79,11 @@
* } * }
* }; * };
* Arc&lt;Long&gt; firstArc = fst.getFirstArc(new Arc&lt;Long&gt;()); * Arc&lt;Long&gt; firstArc = fst.getFirstArc(new Arc&lt;Long&gt;());
* MinResult&lt;Long&gt; paths[] = Util.shortestPaths(fst, firstArc, comparator, 2); * Util.TopResults&lt;Long&gt; paths = Util.shortestPaths(fst, firstArc, fst.outputs.getNoOutput(), comparator, 3, true);
* System.out.println(Util.toBytesRef(paths[0].input, scratchBytes).utf8ToString()); // cat * System.out.println(Util.toBytesRef(paths.topN.get(0).input, scratchBytes).utf8ToString()); // cat
* System.out.println(paths[0].output); // 5 * System.out.println(paths.topN.get(0).output); // 5
* System.out.println(Util.toBytesRef(paths[1].input, scratchBytes).utf8ToString()); // dog * System.out.println(Util.toBytesRef(paths.topN.get(1).input, scratchBytes).utf8ToString()); // dog
* System.out.println(paths[1].output); // 7 * System.out.println(paths.topN.get(1).output); // 7
* </pre> * </pre>
*/ */
package org.apache.lucene.util.fst; package org.apache.lucene.util.fst;