An efficient implementation of Double Array Trie data structure in Java.
<dependency>
<groupId>io.github.lkk214</groupId>
<artifactId>double-array-trie</artifactId>
<version>1.1.1</version>
</dependency>implementation 'io.github.lkk214:double-array-trie:1.1.1'// Build a trie
TreeMap<String, String> map = new TreeMap<>();
map.put("apple", "fruit");
map.put("banana", "fruit");
map.put("carrot", "vegetable");
DoubleArrayTrie<String> trie = DoubleArrayTrie.builder().build(map);
// Analyze text - find all matches
trie.analyze("I like apple and banana", (begin, end, value) -> {
System.out.println("Found: " + value + " at [" + begin + "," + end + ")");
});
// Analyze text - stop after first match
trie.analyze("I like apple and banana", (begin, end, value) -> {
System.out.println("First match: " + value + " at [" + begin + "," + end + ")");
return true; // stop early by returning true
});This project is licensed under the MIT License - see the LICENSE file for details.