private String getFeature(int wordId, int... fields) { String[] allFeatures = getAllFeaturesArray(wordId); if (allFeatures == null) { return null; } StringBuilder sb = new StringBuilder(); if (fields.length == 0) { // All features for (String feature : allFeatures) { sb.append(CSVUtil.quoteEscape(feature)).append(","); } } else if (fields.length == 1) { // One feature doesn't need to escape value sb.append(allFeatures[fields[0]]).append(","); } else { for (int field : fields){ sb.append(CSVUtil.quoteEscape(allFeatures[field])).append(","); } } return sb.deleteCharAt(sb.length() - 1).toString(); }
@Test public void testPut() { UnknownDictionaryWriter unkDic = new UnknownDictionaryWriter(10 * 1024 * 1024); try{ unkDic.put(CSVUtil.parse("KANJI,1285,11426,名詞,一般,*,*,*,*,*,*,*")); fail(); } catch(Exception e){ } String entry1 = "ALPHA,1285,1285,13398,名詞,一般,*,*,*,*,*,*,*"; String entry2 = "HIRAGANA,1285,1285,13069,名詞,一般,*,*,*,*,*,*,*"; String entry3 = "KANJI,1285,1285,11426,名詞,一般,*,*,*,*,*,*,*"; unkDic.putCharacterCategory(0, "ALPHA"); unkDic.putCharacterCategory(1, "HIRAGANA"); unkDic.putCharacterCategory(2, "KANJI"); unkDic.put(CSVUtil.parse(entry1)); unkDic.put(CSVUtil.parse(entry2)); unkDic.put(CSVUtil.parse(entry3)); }