edu.cmu.sphinx.result
Class Result

java.lang.Object
  extended by edu.cmu.sphinx.result.Result

public class Result
extends java.lang.Object

Provides recognition results. Results can be partial or final. A result should not be modified before it is a final result. Note that a result may not contain all possible information.

The following methods are not yet defined but should be:

 public Result getDAG(int compressionLevel);
 


Field Summary
private  ActiveList activeList
           
private  AlternateHypothesisManager alternateHypothesisManager
           
private  int currentFrameNumber
           
private  boolean isFinal
           
private  LogMath logMath
           
private  java.lang.String reference
           
private  java.util.List<Token> resultList
           
 
Constructor Summary
Result(ActiveList activeList, java.util.List<Token> resultList, int frameNumber, boolean isFinal, LogMath logMath)
          Creates a result
Result(AlternateHypothesisManager alternateHypothesisManager, ActiveList activeList, java.util.List<Token> resultList, int frameNumber, boolean isFinal, LogMath logMath)
          Creates a result
 
Method Summary
private  void addWord(java.lang.StringBuilder sb, Word word, FloatData startFeature, FloatData endFeature)
          Adds the given word into the given string builder with the start and end times from the given features.
 java.util.List<Token> findPartialMatchingTokens(java.lang.String text)
          Searches through the n-best list to find the the branch that matches the beginning of the given string
 Token findToken(java.lang.String text)
          Searches through the n-best list to find the the branch that matches the given string
 ActiveList getActiveTokens()
          Returns a list of active tokens for this result.
 AlternateHypothesisManager getAlternateHypothesisManager()
          Returns the AlternateHypothesisManager Used to construct a Lattice
 Token getBestActiveParitalMatchingToken(java.lang.String text)
          Returns the best scoring token that matches the beginning of the given text.
 Token getBestActiveToken()
          Returns the best scoring token in the active set
 java.lang.String getBestFinalResultNoFiller()
          Returns the string of the best final result, removing any filler words.
 Token getBestFinalToken()
          Returns the best scoring final token in the result.
 java.lang.String getBestPronunciationResult()
          The method is used when the application wants the phonemes on the best final path.
 java.lang.String getBestResultNoFiller()
          Returns the string of the best result, removing any filler words.
 Token getBestToken()
          Returns the best scoring token in the result.
 java.util.List<Data> getDataFrames()
          Gets the feature frames associated with this result
 int getEndFrame()
          Gets the ending frame number for the result.
 int getFrameNumber()
          Returns the current frame number
 FrameStatistics[] getFrameStatistics()
          Returns detailed frame statistics for this result
 LogMath getLogMath()
          Returns the log math used for this Result.
 java.lang.String getReferenceText()
          Retrieves the reference text.
 java.util.List<Token> getResultTokens()
          Returns a list of result tokens for this result.
 int getStartFrame()
          Gets the starting frame number for the result.
 java.lang.String getTimedBestResult(boolean wantFiller, boolean wordTokenFirst)
          Returns the string of words (with timestamp) for this token.
private  java.lang.String getTimedWordPath(Token token, boolean wantFiller)
          Returns the string of words (with timestamp) for this token.
private  java.lang.String getTimedWordTokenLastPath(Token token, boolean wantFiller)
          Returns the string of words for this token, each with the starting sample number as the timestamp.
 boolean isFinal()
          Determines if the result is a final result.
(package private)  void setFinal(boolean finalResult)
          Sets the results as a final result
 void setReferenceText(java.lang.String ref)
          Sets the reference text
 java.lang.String toString()
          Returns a string representation of this object
 boolean validate()
          Determines if the Result is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

activeList

private final ActiveList activeList

resultList

private final java.util.List<Token> resultList

alternateHypothesisManager

private AlternateHypothesisManager alternateHypothesisManager

isFinal

private boolean isFinal

currentFrameNumber

private final int currentFrameNumber

reference

private java.lang.String reference

logMath

private final LogMath logMath
Constructor Detail

Result

public Result(AlternateHypothesisManager alternateHypothesisManager,
              ActiveList activeList,
              java.util.List<Token> resultList,
              int frameNumber,
              boolean isFinal,
              LogMath logMath)
Creates a result

Parameters:
activeList - the active list associated with this result
resultList - the result list associated with this result
frameNumber - the frame number for this result.
isFinal - if true, the result is a final result

Result

public Result(ActiveList activeList,
              java.util.List<Token> resultList,
              int frameNumber,
              boolean isFinal,
              LogMath logMath)
Creates a result

Parameters:
activeList - the active list associated with this result
resultList - the result list associated with this result
frameNumber - the frame number for this result.
isFinal - if true, the result is a final result. This means that the last frame in the speech segment has been decoded.
Method Detail

isFinal

public boolean isFinal()
Determines if the result is a final result. A final result is guaranteed to no longer be modified by the SearchManager that generated it. Non-final results can be modifed by a SearchManager.recognize calls.

Returns:
true if the result is a final result

getLogMath

public LogMath getLogMath()
Returns the log math used for this Result.

Returns:
the log math used

getActiveTokens

public ActiveList getActiveTokens()
Returns a list of active tokens for this result. The list contains zero or active Token objects that represents the leaf nodes of all active branches in the result (sometimes referred to as the 'lattice').

The lattice is live and may be modified by a SearchManager during a recognition. Once the Result is final, the lattice is fixed and will no longer be modified by the SearchManager. Applications can modify the lattice (to prepare for a re-recognition, for example) only after isFinal returns true

Returns:
a list containing the active tokens for this result
See Also:
Token

getResultTokens

public java.util.List<Token> getResultTokens()
Returns a list of result tokens for this result. The list contains zero or more result Token objects that represents the leaf nodes of all final branches in the result (sometimes referred to as the 'lattice').

The lattice is live and may be modified by a SearchManager during a recognition. Once the Result is final, the lattice is fixed and will no longer be modified by the SearchManager. Applications can modify the lattice (to prepare for a re-recognition, for example) only after isFinal returns true

Returns:
a list containing the final result tokens for this result
See Also:
Token

getAlternateHypothesisManager

public AlternateHypothesisManager getAlternateHypothesisManager()
Returns the AlternateHypothesisManager Used to construct a Lattice

Returns:
the AlternateHypothesisManager

getFrameNumber

public int getFrameNumber()
Returns the current frame number

Returns:
the frame number

getBestFinalToken

public Token getBestFinalToken()
Returns the best scoring final token in the result. A final token is a token that has reached a final state in the current frame.

Returns:
the best scoring final token or null

getBestToken

public Token getBestToken()
Returns the best scoring token in the result. First, the best final token is retrieved. A final token is one that has reached the final state in the search space. If no final tokens can be found, then the best, non-final token is returned.

Returns:
the best scoring token or null

getBestActiveToken

public Token getBestActiveToken()
Returns the best scoring token in the active set

Returns:
the best scoring token or null

findToken

public Token findToken(java.lang.String text)
Searches through the n-best list to find the the branch that matches the given string

Parameters:
text - the string to search for
Returns:
the token at the head of the branch or null

findPartialMatchingTokens

public java.util.List<Token> findPartialMatchingTokens(java.lang.String text)
Searches through the n-best list to find the the branch that matches the beginning of the given string

Parameters:
text - the string to search for
Returns:
the list token at the head of the branch

getBestActiveParitalMatchingToken

public Token getBestActiveParitalMatchingToken(java.lang.String text)
Returns the best scoring token that matches the beginning of the given text.

Parameters:
text - the text to match

getFrameStatistics

public FrameStatistics[] getFrameStatistics()
Returns detailed frame statistics for this result

Returns:
frame statistics for this result as an array, with one element per frame or null if no frame statistics are available.

getStartFrame

public int getStartFrame()
Gets the starting frame number for the result. Note that this method is currently not implemented, and always returns zero.

Returns:
the starting frame number for the result

getEndFrame

public int getEndFrame()
Gets the ending frame number for the result. Note that this method is currently not implemented, and always returns zero.

Returns:
the ending frame number for the result

getDataFrames

public java.util.List<Data> getDataFrames()
Gets the feature frames associated with this result

Returns:
the set of feature frames associated with this result, or null if the frames are not available.

getBestResultNoFiller

public java.lang.String getBestResultNoFiller()
Returns the string of the best result, removing any filler words. This method first attempts to return the best final result, that is, the result that has reached the final state of the search space. If there are no best final results, then the best non-final result, that is, the one that did not reach the final state, is returned.

Returns:
the string of the best result, removing any filler words

getBestFinalResultNoFiller

public java.lang.String getBestFinalResultNoFiller()
Returns the string of the best final result, removing any filler words. A final result is a path that has reached the final state. A Result object can also contain paths that did not reach the final state, and those paths are not returned by this method.

Returns:
the string of the best result, removing any filler words, or null if there are no best results

getBestPronunciationResult

public java.lang.String getBestPronunciationResult()
The method is used when the application wants the phonemes on the best final path. Note that words may have more than one pronunciation, so this is not equivalent to the word path e.g. one[HH,W,AH,N] to[T,UW] three[TH,R,IY]

Returns:
the String of words and associated phonemes on the best path

getTimedBestResult

public java.lang.String getTimedBestResult(boolean wantFiller,
                                           boolean wordTokenFirst)
Returns the string of words (with timestamp) for this token.

Parameters:
wantFiller - true if we want filler words included, false otherwise
wordTokenFirst - true if the word tokens come before other types of tokens
Returns:
the string of words

getTimedWordPath

private java.lang.String getTimedWordPath(Token token,
                                          boolean wantFiller)
Returns the string of words (with timestamp) for this token. This method assumes that the word tokens come before other types of token.

Parameters:
wantFiller - true if we want filler words, false otherwise
Returns:
the string of words

getTimedWordTokenLastPath

private java.lang.String getTimedWordTokenLastPath(Token token,
                                                   boolean wantFiller)
Returns the string of words for this token, each with the starting sample number as the timestamp. This method assumes that the word tokens come after the unit and hmm tokens.

Returns:
the string of words, each with the starting sample number

addWord

private void addWord(java.lang.StringBuilder sb,
                     Word word,
                     FloatData startFeature,
                     FloatData endFeature)
Adds the given word into the given string builder with the start and end times from the given features.

Parameters:
sb - the StringBuilder into which the word is added
word - the word to add
startFeature - the starting feature
endFeature - tne ending feature

toString

public java.lang.String toString()
Returns a string representation of this object

Overrides:
toString in class java.lang.Object

setFinal

void setFinal(boolean finalResult)
Sets the results as a final result

Parameters:
finalResult - if true, the result should be made final

validate

public boolean validate()
Determines if the Result is valid. This is used for testing and debugging

Returns:
true if the result is properly formed.

setReferenceText

public void setReferenceText(java.lang.String ref)
Sets the reference text

Parameters:
ref - the reference text

getReferenceText

public java.lang.String getReferenceText()
Retrieves the reference text. The reference text is a transcript of the text that was spoken.

Returns:
the reference text or null if no reference text exists.