You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2012/01/08 19:00:08 UTC
svn commit: r1228901 -
/lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/Viterbi.java
Author: mikemccand
Date: Sun Jan 8 18:00:08 2012
New Revision: 1228901
URL: http://svn.apache.org/viewvc?rev=1228901&view=rev
Log:
LUCENE-3305: small cleanups to FST traversal
Modified:
lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/Viterbi.java
Modified: lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/Viterbi.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/Viterbi.java?rev=1228901&r1=1228900&r2=1228901&view=diff
==============================================================================
--- lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/Viterbi.java (original)
+++ lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/viterbi/Viterbi.java Sun Jan 8 18:00:08 2012
@@ -207,7 +207,6 @@ public class Viterbi {
FST.Arc<Long> arc = new FST.Arc<Long>();
FST.Arc<Long> endArc = new FST.Arc<Long>();
final Long NO_OUTPUT = fst.NO_OUTPUT;
- Long output;
ViterbiNode bosNode = new ViterbiNode(0, BOS, 0, BOS.length, 0, 0, 0, -1, Type.KNOWN);
addToArrays(bosNode, 0, 1, startIndexArr, endIndexArr, startSizeArr, endSizeArr);
@@ -229,23 +228,20 @@ public class Viterbi {
boolean found = false;
arc = fst.getFirstArc(arc);
- output = NO_OUTPUT;
+ int output = 0;
for (int endIndex = 1; endIndex < suffixLength + 1; endIndex++) {
int ch = text[suffixStart + endIndex - 1];
if (fst.findTargetArc(ch, arc, arc, endIndex == 1) == null) {
break; // continue to next position
- } else if (arc.output != NO_OUTPUT) {
- output = fst.addOutput(output, arc.output);
}
-
- if (fst.findTargetArc(FST.END_LABEL, arc, endArc, false) != null) { // Found match in FST
- int result = endArc.output == NO_OUTPUT
- ? output.intValue()
- : fst.addOutput(output, endArc.output).intValue();
+ output += arc.output.intValue();
+
+ if (arc.isFinal()) {
+ output += arc.nextFinalOutput.intValue();
found = true; // Don't produce unknown word starting from this index
- for (int wordId : dictionary.lookupWordIds(result)) {
+ for (int wordId : dictionary.lookupWordIds(output)) {
ViterbiNode node = new ViterbiNode(wordId, text, suffixStart, endIndex, dictionary.getLeftId(wordId), dictionary.getRightId(wordId), dictionary.getWordCost(wordId), startIndex, Type.KNOWN);
addToArrays(node, startIndex + 1, startIndex + 1 + endIndex, startIndexArr, endIndexArr, startSizeArr, endSizeArr);
}