Change the numbering order of terminal IDs.
Change-Id: I85a6b6e948ee0de012eef2f9f841240cbca63947
This commit is contained in:
parent
19b247e79d
commit
9ae7d37108
1 changed files with 23 additions and 1 deletions
|
@ -25,6 +25,7 @@ import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions
|
||||||
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
|
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNode;
|
||||||
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
|
import com.android.inputmethod.latin.makedict.FusionDictionary.PtNodeArray;
|
||||||
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
|
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
|
||||||
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -32,6 +33,8 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,11 +244,30 @@ public class Ver4DictEncoder implements DictEncoder {
|
||||||
MakedictLog.i("Flattening the tree...");
|
MakedictLog.i("Flattening the tree...");
|
||||||
ArrayList<PtNodeArray> flatNodes = BinaryDictEncoderUtils.flattenTree(dict.mRootNodeArray);
|
ArrayList<PtNodeArray> flatNodes = BinaryDictEncoderUtils.flattenTree(dict.mRootNodeArray);
|
||||||
int terminalCount = 0;
|
int terminalCount = 0;
|
||||||
|
final ArrayList<PtNode> nodes = CollectionUtils.newArrayList();
|
||||||
for (final PtNodeArray array : flatNodes) {
|
for (final PtNodeArray array : flatNodes) {
|
||||||
for (final PtNode node : array.mData) {
|
for (final PtNode node : array.mData) {
|
||||||
if (node.isTerminal()) node.mTerminalId = terminalCount++;
|
if (node.isTerminal()) {
|
||||||
|
nodes.add(node);
|
||||||
|
node.mTerminalId = terminalCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(nodes, new Comparator<PtNode>() {
|
||||||
|
@Override
|
||||||
|
public int compare(final PtNode lhs, final PtNode rhs) {
|
||||||
|
if (lhs.mFrequency != rhs.mFrequency) {
|
||||||
|
return lhs.mFrequency < rhs.mFrequency ? -1 : 1;
|
||||||
|
}
|
||||||
|
if (lhs.mTerminalId < rhs.mTerminalId) return -1;
|
||||||
|
if (lhs.mTerminalId > rhs.mTerminalId) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
int count = 0;
|
||||||
|
for (final PtNode node : nodes) {
|
||||||
|
node.mTerminalId = count++;
|
||||||
|
}
|
||||||
|
|
||||||
MakedictLog.i("Computing addresses...");
|
MakedictLog.i("Computing addresses...");
|
||||||
BinaryDictEncoderUtils.computeAddresses(dict, flatNodes, formatOptions);
|
BinaryDictEncoderUtils.computeAddresses(dict, flatNodes, formatOptions);
|
||||||
|
|
Loading…
Reference in a new issue