List<Interval> res = new ArrayList<Interval>();
Set<Integer> currStates = new HashSet<Integer>();
currStates.addAll(startStates);
if(currStates.contains(numOfStates-1))
res.add(new Interval(startIndex, startIndex));
for(int i = startIndex; i < utterance.numTokens(); ++i) {
Set<Integer> newStates = new HashSet<Integer>();
for(Integer currState: currStates) {
Map<LanguageExpToken,Set<Integer>> out = outgoingEdges[currState]; //could be NULL - allowed for efficiency
if(out!=null) {
for(LanguageExpToken langExpToken: out.keySet()) {
if(matchLangExpTokenToLangInfo(langExpToken, utterance, i)) {
newStates.addAll(out.get(langExpToken));
}
}
}
}
currStates = newStates;
if(currStates.contains(numOfStates-1)) //match
res.add(new Interval(startIndex, i+1));
}
return res;
}