Add word arguments to the info command (A10)

With this, it's now possible to get all the information about a word from
any dictionary.

Bug: 7388857
Change-Id: Ifc9d539f52f87044a1974d95bf35d87465e84c47
main
Jean Chalard 2012-10-29 12:28:20 +09:00
parent a23e333079
commit 74d66a5513
1 changed files with 46 additions and 2 deletions

View File

@ -18,9 +18,12 @@ package com.android.inputmethod.latin.dicttool;
import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FusionDictionary; import com.android.inputmethod.latin.makedict.FusionDictionary;
import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString; import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
import com.android.inputmethod.latin.makedict.Word; import com.android.inputmethod.latin.makedict.Word;
import java.util.ArrayList;
public class Info extends Dicttool.Command { public class Info extends Dicttool.Command {
public static final String COMMAND = "info"; public static final String COMMAND = "info";
@ -59,14 +62,55 @@ public class Info extends Dicttool.Command {
+ " whitelist entries)"); + " whitelist entries)");
} }
private static void showWordInfo(final FusionDictionary dict, final String word) {
final CharGroup group = dict.findWordInTree(dict.mRoot, word);
if (null == group) {
System.out.println(word + " is not in the dictionary");
return;
}
System.out.println("Word: " + word);
System.out.println(" Freq: " + group.getFrequency());
if (group.getIsNotAWord()) {
System.out.println(" Is not a word");
}
if (group.getIsBlacklistEntry()) {
System.out.println(" Is a blacklist entry");
}
final ArrayList<WeightedString> shortcutTargets = group.getShortcutTargets();
if (null == shortcutTargets || shortcutTargets.isEmpty()) {
System.out.println(" No shortcuts");
} else {
for (final WeightedString shortcutTarget : shortcutTargets) {
System.out.println(" Shortcut target: " + shortcutTarget.mWord + " ("
+ (FormatSpec.SHORTCUT_WHITELIST_FREQUENCY == shortcutTarget.mFrequency
? "whitelist" : shortcutTarget.mFrequency) + ")");
}
}
final ArrayList<WeightedString> bigrams = group.getBigrams();
if (null == bigrams || bigrams.isEmpty()) {
System.out.println(" No bigrams");
} else {
for (final WeightedString bigram : bigrams) {
System.out.println(" Bigram: " + bigram.mWord + " (" + bigram.mFrequency + ")");
}
}
}
@Override @Override
public void run() { public void run() {
if (mArgs.length < 1) { if (mArgs.length < 1) {
throw new RuntimeException("Not enough arguments for command " + COMMAND); throw new RuntimeException("Not enough arguments for command " + COMMAND);
} }
final String filename = mArgs[0]; final String filename = mArgs[0];
final boolean hasWordArguments = (1 == mArgs.length);
final FusionDictionary dict = BinaryDictOffdeviceUtils.getDictionary(filename, final FusionDictionary dict = BinaryDictOffdeviceUtils.getDictionary(filename,
true /* report */); hasWordArguments /* report */);
showInfo(dict); if (hasWordArguments) {
showInfo(dict);
} else {
for (int i = 1; i < mArgs.length; ++i) {
showWordInfo(dict, mArgs[i]);
}
}
} }
} }