### Question:
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);  }### Answer:
@Test public void testLookup() throws IOException { UserDictionary dictionary = new UserDictionary(getResource("deeplearning4j-nlp-japanese/userdict.txt"), 9, 7, 0); List<UserDictionary.UserDictionaryMatch> matches = dictionary.findUserDictionaryMatches("関西国際空港に行った"); assertEquals(3, matches.size()); assertEquals(0, matches.get(0).getMatchStartIndex()); assertEquals(2, matches.get(1).getMatchStartIndex()); assertEquals(4, matches.get(2).getMatchStartIndex()); assertEquals(2, matches.get(0).getMatchLength()); assertEquals(2, matches.get(1).getMatchLength()); assertEquals(2, matches.get(2).getMatchLength()); List<UserDictionary.UserDictionaryMatch> matches2 = dictionary.findUserDictionaryMatches("関西国際空港と関西国際空港に行った"); assertEquals(6, matches2.size()); }
@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()); }
@Test public void testOverlappingUserDictionaryEntries() throws IOException { String userDictionaryEntries = "" + "クロ,クロ,クロ,カスタム名詞\n" + "アクロ,アクロ,アクロ,カスタム名詞"; UserDictionary dictionary = new UserDictionary( new ByteArrayInputStream(userDictionaryEntries.getBytes(StandardCharsets.UTF_8)), 9, 7, 0); List<UserDictionary.UserDictionaryMatch> positions = dictionary.findUserDictionaryMatches("この丘はアクロポリスと呼ばれている"); assertEquals(4, positions.get(0).getMatchStartIndex()); assertEquals(2, positions.size()); }