Add shortcut only to xml output.

Change-Id: I23b53826ce30b0ac81962d2f916514cb60bea6ff
main
Jean Chalard 2012-01-16 17:45:53 +09:00
parent d64b8c97fe
commit 6145b73523
3 changed files with 9 additions and 3 deletions

View File

@ -619,7 +619,8 @@ public class FusionDictionary implements Iterable<Word> {
} }
if (currentGroup.mFrequency >= 0) if (currentGroup.mFrequency >= 0)
return new Word(mCurrentString.toString(), currentGroup.mFrequency, return new Word(mCurrentString.toString(), currentGroup.mFrequency,
currentGroup.mShortcutTargets, currentGroup.mBigrams); currentGroup.mShortcutTargets, currentGroup.mBigrams,
currentGroup.mIsShortcutOnly);
} else { } else {
mPositions.removeLast(); mPositions.removeLast();
currentPos = mPositions.getLast(); currentPos = mPositions.getLast();

View File

@ -28,16 +28,18 @@ import java.util.ArrayList;
public class Word implements Comparable<Word> { public class Word implements Comparable<Word> {
final String mWord; final String mWord;
final int mFrequency; final int mFrequency;
final boolean mIsShortcutOnly;
final ArrayList<WeightedString> mShortcutTargets; final ArrayList<WeightedString> mShortcutTargets;
final ArrayList<WeightedString> mBigrams; final ArrayList<WeightedString> mBigrams;
public Word(final String word, final int frequency, public Word(final String word, final int frequency,
final ArrayList<WeightedString> shortcutTargets, final ArrayList<WeightedString> shortcutTargets,
final ArrayList<WeightedString> bigrams) { final ArrayList<WeightedString> bigrams, final boolean isShortcutOnly) {
mWord = word; mWord = word;
mFrequency = frequency; mFrequency = frequency;
mShortcutTargets = shortcutTargets; mShortcutTargets = shortcutTargets;
mBigrams = bigrams; mBigrams = bigrams;
mIsShortcutOnly = isShortcutOnly;
} }
/** /**

View File

@ -45,6 +45,7 @@ public class XmlDictInputOutput {
private static final String SHORTCUT_TAG = "shortcut"; private static final String SHORTCUT_TAG = "shortcut";
private static final String FREQUENCY_ATTR = "f"; private static final String FREQUENCY_ATTR = "f";
private static final String WORD_ATTR = "word"; private static final String WORD_ATTR = "word";
private static final String SHORTCUT_ONLY_ATTR = "shortcutOnly";
/** /**
* SAX handler for a unigram XML file. * SAX handler for a unigram XML file.
@ -264,9 +265,11 @@ public class XmlDictInputOutput {
} }
// TODO: use an XMLSerializer if this gets big // TODO: use an XMLSerializer if this gets big
destination.write("<wordlist format=\"2\">\n"); destination.write("<wordlist format=\"2\">\n");
destination.write("<!-- Warning: there is no code to read this format yet. -->\n");
for (Word word : set) { for (Word word : set) {
destination.write(" <" + WORD_TAG + " " + WORD_ATTR + "=\"" + word.mWord + "\" " destination.write(" <" + WORD_TAG + " " + WORD_ATTR + "=\"" + word.mWord + "\" "
+ FREQUENCY_ATTR + "=\"" + word.mFrequency + "\">"); + FREQUENCY_ATTR + "=\"" + word.mFrequency + "\" " + SHORTCUT_ONLY_ATTR
+ "=\"" + word.mIsShortcutOnly + "\">");
if (null != word.mShortcutTargets) { if (null != word.mShortcutTargets) {
destination.write("\n"); destination.write("\n");
for (WeightedString target : word.mShortcutTargets) { for (WeightedString target : word.mShortcutTargets) {