@Override public void printLattice(DFSA<String, Integer> tagLattice, List<CoreLabel> doc, PrintWriter out) { CoreLabel[] docArray = doc.toArray(new CoreLabel[doc.size()]); // Create answer lattice: MutableInteger nodeId = new MutableInteger(0); DFSA<String, Integer> answerLattice = new DFSA<>(null); DFSAState<String, Integer> aInitState = new DFSAState<>(nodeId.intValue(), answerLattice); answerLattice.setInitialState(aInitState); Map<DFSAState<String, Integer>,DFSAState<String, Integer>> stateLinks = Generics.newHashMap(); // Convert binary lattice into word lattice: tagLatticeToAnswerLattice (tagLattice.initialState(), aInitState, new StringBuilder(""), nodeId, 0, 0.0, stateLinks, answerLattice, docArray); try { answerLattice.printAttFsmFormat(out); } catch(IOException e) { throw new RuntimeException(e); } }
public Set<DFSAState<T, S>> states() { Set<DFSAState<T, S>> visited = Generics.newHashSet(); List<DFSAState<T,S>> toVisit = new ArrayList<>(); toVisit.add(initialState()); exploreStates(toVisit, visited); return visited; }
public static <T, S> void printTrieAsRules(DFSA<T, S> dfsa, Writer w) throws IOException { printTrieAsRulesHelper(dfsa.initialState(), dfsa.dfsaID.toString(), w); }
public static <T, S> void printTrieDFSA(DFSA<T, S> dfsa) { log.info("DFSA: " + dfsa.dfsaID); printTrieDFSAHelper(dfsa.initialState(), 2); }
lattice = new DFSA<>("wordLattice"); for (int i=0; i<=s.length(); ++i) states.add(new DFSAState<>(i, lattice)); lattice.setInitialState(states.get(0)); states.get(len).setAccepting(true);
private DFSA<String, Integer> getViterbiSearchGraph(List<IN> doc, Class<? extends CoreAnnotation<String>> answerField) { if (doc.isEmpty()) { return new DFSA<>(null); } // TODO get rid of ObjectBankWrapper ObjectBankWrapper<IN> obw = new ObjectBankWrapper<>(flags, null, knownLCWords); doc = obw.processDocument(doc); SequenceModel model = getSequenceModel(doc); return ViterbiSearchGraphBuilder.getGraph(model, classIndex); }
private static <T, S> void printTrieDFSAHelper(DFSAState<T, S> state, int level) { if (state.isAccepting()) { return; } Set<T> inputs = state.continuingInputs(); for (T input : inputs) { DFSATransition<T, S> transition = state.transition(input); System.out.print(level); System.out.print(input); for (int i = 0; i < level; i++) { System.out.print(" "); } System.out.print(transition.score()); System.out.print(" "); System.out.println(input); printTrieDFSAHelper(transition.target(), level + 1); } }
private static <T, S> void printTrieAsRulesHelper(DFSAState<T, S> state, String prefix, Writer w) throws IOException { if (state.isAccepting()) { return; } Set<T> inputs = state.continuingInputs(); for (T input : inputs) { DFSATransition<T, S> transition = state.transition(input); DFSAState<T, S> target = transition.target(); Set<T> inputs2 = target.continuingInputs(); boolean allTerminate = true; for (T input2 : inputs2) { DFSATransition<T, S> transition2 = target.transition(input2); DFSAState<T, S> target2 = transition2.target(); if (target2.isAccepting()) { // it's a binary end rule. Print it. w.write(prefix + " --> " + input + " " + input2 + "\n"); } else { allTerminate = false; } } if (!allTerminate) { // there are some longer continuations. Print continuation rule String newPrefix = prefix + "_" + input; w.write(prefix + " --> " + input + " " + newPrefix + "\n"); printTrieAsRulesHelper(transition.target(), newPrefix, w); } } }
((LatticeWriter<IN, String, Integer>) readerAndWriter).printLattice(tagLattice, doc, latticeWriter); tagLattice.printAttFsmFormat(vsgWriter); latticeWriter.close(); vsgWriter.close();
static <T, S> void unweightedMinimizeOld(DFSA<T, S> dfsa) { Set<DFSAState<T, S>> states = dfsa.states(); Map<UnorderedPair<DFSAState<T, S>, DFSAState<T, S>>, List<UnorderedPair<DFSAState<T, S>, DFSAState<T, S>>>> stateUPairToDependentUPairList = Generics.newHashMap(states.size() * states.size() / 2 + 1); Map<UnorderedPair<DFSAState<T, S>, DFSAState<T, S>>, Boolean> stateUPairToDistinguished = Generics.newHashMap(states.size() * states.size() / 2 + 1);
public static DFSA<String, Integer> getGraph(SequenceModel ts, Index<String> classIndex) { DFSA<String, Integer> viterbiSearchGraph = new DFSA<>(null); int stateId = -1; startState = new DFSAState<>(++stateId, viterbiSearchGraph, 0.0); viterbiSearchGraph.setInitialState(startState); graphStates = new DFSAState[length][]; for(int pos = 0; pos<length; ++pos) {
public static <T, S> void printTrieDFSA(DFSA<T, S> dfsa) { System.err.println("DFSA: " + dfsa.dfsaID); printTrieDFSAHelper(dfsa.initialState(), 2); }
private DFSA<String, Integer> getViterbiSearchGraph(List<IN> doc, Class<? extends CoreAnnotation<String>> answerField) { if (doc.isEmpty()) { return new DFSA<>(null); } // TODO get rid of ObjectBankWrapper ObjectBankWrapper<IN> obw = new ObjectBankWrapper<>(flags, null, knownLCWords); doc = obw.processDocument(doc); SequenceModel model = getSequenceModel(doc); return ViterbiSearchGraphBuilder.getGraph(model, classIndex); }
private static <T, S> void printTrieDFSAHelper(DFSAState<T, S> state, int level) { if (state.isAccepting()) { return; } Set<T> inputs = state.continuingInputs(); for (T input : inputs) { DFSATransition<T, S> transition = state.transition(input); System.out.print(level); System.out.print(input); for (int i = 0; i < level; i++) { System.out.print(" "); } System.out.print(transition.score()); System.out.print(" "); System.out.println(input); printTrieDFSAHelper(transition.target(), level + 1); } }
private static <T, S> void printTrieAsRulesHelper(DFSAState<T, S> state, String prefix, Writer w) throws IOException { if (state.isAccepting()) { return; } Set<T> inputs = state.continuingInputs(); for (T input : inputs) { DFSATransition<T, S> transition = state.transition(input); DFSAState<T, S> target = transition.target(); Set<T> inputs2 = target.continuingInputs(); boolean allTerminate = true; for (T input2 : inputs2) { DFSATransition<T, S> transition2 = target.transition(input2); DFSAState<T, S> target2 = transition2.target(); if (target2.isAccepting()) { // it's a binary end rule. Print it. w.write(prefix + " --> " + input + " " + input2 + "\n"); } else { allTerminate = false; } } if (!allTerminate) { // there are some longer continuations. Print continuation rule String newPrefix = prefix + "_" + input; w.write(prefix + " --> " + input + " " + newPrefix + "\n"); printTrieAsRulesHelper(transition.target(), newPrefix, w); } } }
if (readerAndWriter instanceof LatticeWriter) ((LatticeWriter) readerAndWriter).printLattice(tagLattice, doc, latticeWriter); tagLattice.printAttFsmFormat(vsgWriter); latticeWriter.close(); vsgWriter.close();
public static <T, S> void unweightedMinimize(DFSA<T, S> dfsa) { Set<DFSAState<T, S>> states = dfsa.states(); long time = System.currentTimeMillis(); if (debug) {
@Override public void printLattice(DFSA<String, Integer> tagLattice, List<CoreLabel> doc, PrintWriter out) { CoreLabel[] docArray = doc.toArray(new CoreLabel[doc.size()]); // Create answer lattice: MutableInteger nodeId = new MutableInteger(0); DFSA<String, Integer> answerLattice = new DFSA<>(null); DFSAState<String, Integer> aInitState = new DFSAState<>(nodeId.intValue(), answerLattice); answerLattice.setInitialState(aInitState); Map<DFSAState<String, Integer>,DFSAState<String, Integer>> stateLinks = Generics.newHashMap(); // Convert binary lattice into word lattice: tagLatticeToAnswerLattice (tagLattice.initialState(), aInitState, new StringBuilder(""), nodeId, 0, 0.0, stateLinks, answerLattice, docArray); try { answerLattice.printAttFsmFormat(out); } catch(IOException e) { throw new RuntimeException(e); } }
public static DFSA<String, Integer> getGraph(SequenceModel ts, Index<String> classIndex) { DFSA<String, Integer> viterbiSearchGraph = new DFSA<>(null); int stateId = -1; startState = new DFSAState<>(++stateId, viterbiSearchGraph, 0.0); viterbiSearchGraph.setInitialState(startState); graphStates = new DFSAState[length][]; for(int pos = 0; pos<length; ++pos) {
public Set<DFSAState<T, S>> states() { Set<DFSAState<T, S>> visited = new HashSet<DFSAState<T, S>>(); List<DFSAState<T,S>> toVisit = new ArrayList<DFSAState<T,S>>(); toVisit.add(initialState()); exploreStates(toVisit, visited); return visited; }