@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()); }
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);  }