@Test public void testUserDictionaryEntries() throws IOException { String userDictionaryEntry = "クロ,クロ,クロ,カスタム名詞"; UserDictionary dictionary = new UserDictionary( new ByteArrayInputStream(userDictionaryEntry.getBytes(StandardCharsets.UTF_8)), 9, 7, 0); List<UserDictionary.UserDictionaryMatch> matches = dictionary.findUserDictionaryMatches("この丘はアクロポリスと呼ばれている"); assertEquals(1, matches.size()); assertEquals(5, matches.get(0).getMatchStartIndex()); }
public List<UserDictionaryMatch> findUserDictionaryMatches(String text) { List<UserDictionaryMatch> matchInfos = new ArrayList<>(); int startIndex = 0; while (startIndex < text.length()) { int matchLength = 0; while (startIndex + matchLength < text.length() && entries.containsKeyPrefix(text.substring(startIndex, startIndex + matchLength + 1))) { matchLength++; } if (matchLength > 0) { String match = text.substring(startIndex, startIndex + matchLength); int[] details = entries.get(match); if (details != null) { matchInfos.addAll(makeMatchDetails(startIndex, details)); } } startIndex++; } return matchInfos; }
UserDictionary implements Dictionary { public List<UserDictionaryMatch> findUserDictionaryMatches(String text) { List<UserDictionaryMatch> matchInfos = new ArrayList<>(); int startIndex = 0; while (startIndex < text.length()) { int matchLength = 0; while (startIndex + matchLength < text.length() && entries.containsKeyPrefix(text.substring(startIndex, startIndex + matchLength + 1))) { matchLength++; } if (matchLength > 0) { String match = text.substring(startIndex, startIndex + matchLength); int[] details = entries.get(match); if (details != null) { matchInfos.addAll(makeMatchDetails(startIndex, details)); } } startIndex++; } return matchInfos; } }
UserDictionary implements Dictionary { public List<UserDictionaryMatch> findUserDictionaryMatches(String text) { List<UserDictionaryMatch> matchInfos = new ArrayList<>(); int startIndex = 0; while (startIndex < text.length()) { int matchLength = 0; while (startIndex + matchLength < text.length() && entries.containsKeyPrefix(text.substring(startIndex, startIndex + matchLength + 1))) { matchLength++; } if (matchLength > 0) { String match = text.substring(startIndex, startIndex + matchLength); int[] details = entries.get(match); if (details != null) { matchInfos.addAll(makeMatchDetails(startIndex, details)); } } startIndex++; } return matchInfos; } UserDictionary(InputStream inputStream, int totalFeatures, int readingFeature, int partOfSpeechFeature); }
UserDictionary implements Dictionary { public List<UserDictionaryMatch> findUserDictionaryMatches(String text) { List<UserDictionaryMatch> matchInfos = new ArrayList<>(); int startIndex = 0; while (startIndex < text.length()) { int matchLength = 0; while (startIndex + matchLength < text.length() && entries.containsKeyPrefix(text.substring(startIndex, startIndex + matchLength + 1))) { matchLength++; } if (matchLength > 0) { String match = text.substring(startIndex, startIndex + matchLength); int[] details = entries.get(match); if (details != null) { matchInfos.addAll(makeMatchDetails(startIndex, details)); } } startIndex++; } return matchInfos; } UserDictionary(InputStream inputStream, int totalFeatures, int readingFeature, int partOfSpeechFeature); List<UserDictionaryMatch> findUserDictionaryMatches(String text); @Override int getLeftId(int wordId); @Override int getRightId(int wordId); @Override int getWordCost(int wordId); @Override String[] getAllFeaturesArray(int wordId); @Override String getAllFeatures(int wordId); @Override String getFeature(int wordId, int... fields); void read(InputStream input); void addEntry(String entry); }
UserDictionary implements Dictionary { public List<UserDictionaryMatch> findUserDictionaryMatches(String text) { List<UserDictionaryMatch> matchInfos = new ArrayList<>(); int startIndex = 0; while (startIndex < text.length()) { int matchLength = 0; while (startIndex + matchLength < text.length() && entries.containsKeyPrefix(text.substring(startIndex, startIndex + matchLength + 1))) { matchLength++; } if (matchLength > 0) { String match = text.substring(startIndex, startIndex + matchLength); int[] details = entries.get(match); if (details != null) { matchInfos.addAll(makeMatchDetails(startIndex, details)); } } startIndex++; } return matchInfos; } UserDictionary(InputStream inputStream, int totalFeatures, int readingFeature, int partOfSpeechFeature); List<UserDictionaryMatch> findUserDictionaryMatches(String text); @Override int getLeftId(int wordId); @Override int getRightId(int wordId); @Override int getWordCost(int wordId); @Override String[] getAllFeaturesArray(int wordId); @Override String getAllFeatures(int wordId); @Override String getFeature(int wordId, int... fields); void read(InputStream input); void addEntry(String entry);  }