diff options
author | 2012-01-10 09:03:59 -0800 | |
---|---|---|
committer | 2012-01-10 09:03:59 -0800 | |
commit | 41dbae9ea671a02b0e88e1387828200dd66fd1c2 (patch) | |
tree | ed27c00b75930aa283c731e4d96804e4c970c8ea /tools/makedict/src/com/android/inputmethod/latin/XmlDictInputOutput.java | |
parent | 606206cfd7517cafe78849d18ef2bd2baeea5d42 (diff) | |
parent | 342d5d5dd095a5f73413a630b5de9db334ca45e4 (diff) | |
download | latinime-41dbae9ea671a02b0e88e1387828200dd66fd1c2.tar.gz latinime-41dbae9ea671a02b0e88e1387828200dd66fd1c2.tar.xz latinime-41dbae9ea671a02b0e88e1387828200dd66fd1c2.zip |
am 342d5d5d: Wire the Xml-read shortcuts into the dict creation code (B6)
* commit '342d5d5dd095a5f73413a630b5de9db334ca45e4':
Wire the Xml-read shortcuts into the dict creation code (B6)
Diffstat (limited to 'tools/makedict/src/com/android/inputmethod/latin/XmlDictInputOutput.java')
-rw-r--r-- | tools/makedict/src/com/android/inputmethod/latin/XmlDictInputOutput.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/tools/makedict/src/com/android/inputmethod/latin/XmlDictInputOutput.java b/tools/makedict/src/com/android/inputmethod/latin/XmlDictInputOutput.java index 19ed9d8d2..1562b693b 100644 --- a/tools/makedict/src/com/android/inputmethod/latin/XmlDictInputOutput.java +++ b/tools/makedict/src/com/android/inputmethod/latin/XmlDictInputOutput.java @@ -61,6 +61,7 @@ public class XmlDictInputOutput { int mState; // the state of the parser int mFreq; // the currently read freq String mWord; // the current word + final HashMap<String, ArrayList<WeightedString>> mShortcutsMap; final HashMap<String, ArrayList<WeightedString>> mBigramsMap; /** @@ -69,9 +70,11 @@ public class XmlDictInputOutput { * @param dict the dictionary to construct. * @param bigrams the bigrams as a map. This may be empty, but may not be null. */ - public UnigramHandler(FusionDictionary dict, - HashMap<String, ArrayList<WeightedString>> bigrams) { + public UnigramHandler(final FusionDictionary dict, + final HashMap<String, ArrayList<WeightedString>> shortcuts, + final HashMap<String, ArrayList<WeightedString>> bigrams) { mDictionary = dict; + mShortcutsMap = shortcuts; mBigramsMap = bigrams; mWord = ""; mState = START; @@ -107,8 +110,7 @@ public class XmlDictInputOutput { @Override public void endElement(String uri, String localName, String qName) { if (WORD == mState) { - // TODO: pass the shortcut targets - mDictionary.add(mWord, mFreq, null, mBigramsMap.get(mWord)); + mDictionary.add(mWord, mFreq, mShortcutsMap.get(mWord), mBigramsMap.get(mWord)); mState = START; } } @@ -208,9 +210,12 @@ public class XmlDictInputOutput { * representation. * * @param unigrams the file to read the data from. + * @param shortcuts the file to read the shortcuts from, or null. + * @param bigrams the file to read the bigrams from, or null. * @return the in-memory representation of the dictionary. */ - public static FusionDictionary readDictionaryXml(InputStream unigrams, InputStream bigrams) + public static FusionDictionary readDictionaryXml(final InputStream unigrams, + final InputStream shortcuts, final InputStream bigrams) throws SAXException, IOException, ParserConfigurationException { final SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); @@ -218,9 +223,13 @@ public class XmlDictInputOutput { final BigramHandler bigramHandler = new BigramHandler(); if (null != bigrams) parser.parse(bigrams, bigramHandler); + final ShortcutHandler shortcutHandler = new ShortcutHandler(); + if (null != shortcuts) parser.parse(shortcuts, shortcutHandler); + final FusionDictionary dict = new FusionDictionary(); final UnigramHandler unigramHandler = - new UnigramHandler(dict, bigramHandler.getBigramMap()); + new UnigramHandler(dict, shortcutHandler.getShortcutMap(), + bigramHandler.getBigramMap()); parser.parse(unigrams, unigramHandler); return dict; } |