Difference between revisions of "Trellis"
(Created page with ' /** * Builds a Trellis over a sentence, by starting at the state State, and * advancing through all legal extensions of each state already in the …') |
(No difference)
|
Latest revision as of 06:48, 30 April 2010
/** * Builds a Trellis over a sentence, by starting at the state State, and * advancing through all legal extensions of each state already in the * trellis. You should not have to modify this code (or even read it, * really). */ private Trellis<State> buildTrellis(List<String> sentence) { Trellis<State> trellis = new Trellis<State>(); trellis.setStartState(State.getStartState()); State stopState = State.getStopState(sentence.size() + 2); trellis.setStopState(stopState); Set<State> states = Collections.singleton(State.getStartState()); for (int position = 0; position <= sentence.size() + 1; position++) { Set<State> nextStates = new HashSet<State>(); for (State state : states) { if (state.equals(stopState)) continue; LocalTrigramContext localTrigramContext = new LocalTrigramContext(sentence, position, state.getPreviousPreviousTag(), state.getPreviousTag()); Counter<String> tagScores = localTrigramScorer.getLogScoreCounter(localTrigramContext); boolean skipper = false; if (tagScores.totalCount() != 0) skipper = true; for (String tag : tagScores.keySet()) { double score = tagScores.getCount(tag); if (skipper && Math.abs(score) < 1) continue; State nextState = state.getNextState(tag); trellis.setTransitionCount(state, nextState, score); nextStates.add(nextState); } } // System.out.println("States: "+nextStates); states = nextStates; } //System.out.println("trellis size: bt = " + trellis.btsize() + "; ft = " + trellis.ftsize()); return trellis; }