net.amygdalum.util.text.doublearraytrie.DoubleArrayCharFallbackTrieCompiler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compilerutils Show documentation
Show all versions of compilerutils Show documentation
Utility classes needed for search and compiler applications
The newest version!
package net.amygdalum.util.text.doublearraytrie;
import static net.amygdalum.util.text.doublearraytrie.Arrays.expand;
import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import net.amygdalum.util.text.CharFallbackAdaptor;
import net.amygdalum.util.text.CharNode;
import net.amygdalum.util.text.CharTrie;
import net.amygdalum.util.text.CharWordGraphCompiler;
import net.amygdalum.util.text.NodeResolver;
import net.amygdalum.util.text.linkeddawg.CharGenericFallbackNode;
public class DoubleArrayCharFallbackTrieCompiler implements CharWordGraphCompiler> {
@Override
public CharNode create() {
return new CharGenericFallbackNode<>();
}
@Override
public CharTrie build(CharNode node) {
DoubleArrayCharFallbackTrie.Builder builder = new DoubleArrayCharFallbackTrie.Builder();
boolean[] visited = new boolean[1024];
Map, Integer> assignments = new IdentityHashMap<>();
Queue> todo = new LinkedList<>();
todo.add(new Assignment<>(builder.root(), node));
while (!todo.isEmpty()) {
Assignment current = todo.remove();
int currentState = current.state;
CharNode currentNode = current.node;
if (currentState >= visited.length) {
visited = expand(visited, currentState);
}
if (visited[currentState]) {
continue;
}
visited[currentState] = true;
assignments.put(currentNode, currentState);
int alternatives = currentNode.getAlternativesSize();
if (alternatives >= 1) {
branch(builder, currentState, currentNode, todo);
} else {
terminate(builder, currentState, currentNode);
}
}
for (Map.Entry, Integer> current : assignments.entrySet()) {
CharNode currentNode = current.getKey();
int currentState = current.getValue();
CharNode
© 2015 - 2025 Weber Informatics LLC | Privacy Policy