package org.cocolab.inpro.incremental.util;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import edu.cmu.sphinx.decoder.search.Token;
import edu.cmu.sphinx.linguist.WordSearchState;
import edu.cmu.sphinx.linguist.dictionary.Word;

public class ResultUtil {
	
	public static List<String> getWordSequence(Token token) {
		List<String> returnList = new LinkedList<String>();
		boolean wantFiller = false;
		while (token != null) {
            if (token.isWord()) {
                WordSearchState wordState =
                    (WordSearchState) token.getSearchState();
                Word word = wordState.getPronunciation().getWord();
                if (wantFiller || !word.isFiller()) {
                	returnList.add(0, word.getSpelling());
                }
            }
            token = token.getPredecessor();
        }
		return returnList;
	}
	
	public static int diffWordSequences(List<String> a, List<String> b) {
		int i = 0;
		Iterator<String> aIt = a.iterator();
		Iterator<String> bIt = b.iterator();
		while (aIt.hasNext() && bIt.hasNext() && aIt.next().equals(bIt.next())) {
			i++;
		}
		aIt = a.listIterator(i);
		bIt = b.listIterator(i);
		int diff = 0;
		while (aIt.hasNext()) { aIt.next(); diff++; }
		while (bIt.hasNext()) { bIt.next(); diff++; }
		return diff;
	}
	
}

@@ -346,16 +346,140 @@
 oken) %7B%0A
+%09%09return getWordSequence(token, false);%0A%09%7D%0A%09%0A%09public static List%3CString%3E getWordSequence(Token token, boolean wantFiller) %7B%0A
 %09%09List%3CS
@@ -528,38 +528,8 @@
 ();%0A
-%09%09boolean wantFiller = false;%0A
 %09%09wh

include <sil>