/** * /// Returns the node corresponding to the given word token. * * /// @param token the token which we want a node of * /// @return the node of the given token */ private Node getNode(Token token) { if (token.getWord().isSentenceEndWord()) { return(terminalNode); } Node node = nodes[getNodeID(token)]; if (node == null) { IWordSearchState wordState = (IWordSearchState)token.getSearchState(); int startFrame = -1; int endFrame = -1; if (wordState.isWordStart()) { startFrame = token.getFrameNumber(); } else { endFrame = token.getFrameNumber(); } node = new Node(getNodeID(token), token.getWord(), startFrame, endFrame); addNode(node); } return(node); }
/// <summary> /// Returns the word of this Token, the search state is a WordSearchState. If the search state is not a /// WordSearchState, return null. /// </summary> /// <returns>the word of this Token, or null if this is not a word token</returns> public IWord getWord() { if (isWord()) { IWordSearchState wordState = (IWordSearchState)searchState; return(wordState.getPronunciation().getWord()); } else { return(null); } }
/// <summary> /// Returns the string of words leading up to this token. /// </summary> /// <param name="wantFiller">if true, filler words are added</param> /// <param name="wantPronunciations">if true append [ phoneme phoneme ... ] after each word</param> /// <returns></returns> public String getWordPath(Boolean wantFiller, Boolean wantPronunciations) { StringBuilder sb = new StringBuilder(); Token token = this; while (token != null) { if (token.isWord()) { IWordSearchState wordState = (IWordSearchState)token.getSearchState(); IPronunciation pron = wordState.getPronunciation(); IWord word = wordState.getPronunciation().getWord(); //Console.Out.WriteLine(token.getFrameNumber() + " " + word + " " + token.logLanguageScore + " " + token.logAcousticScore); if (wantFiller || !word.isFiller()) { if (wantPronunciations) { sb.Insert(0, ']'); IUnit[] u = pron.getUnits(); for (int i = u.Length - 1; i >= 0; i--) { if (i < u.Length - 1) { sb.Insert(0, ','); } sb.Insert(0, u[i].getName()); } sb.Insert(0, '['); } sb.Insert(0, word.getSpelling()); sb.Insert(0, ' '); } } token = token.getPredecessor(); } return(sb.ToString().Trim()); }
/// <summary> /// Returns the string of words and units for this token, with embedded silences. /// </summary> /// <returns>the string of words and units</returns>public IWord getWord() public String getWordUnitPath() { StringBuilder sb = new StringBuilder(); Token token = this; while (token != null) { ISearchState searchState = token.getSearchState(); if (searchState is IWordSearchState) { IWordSearchState wordState = (IWordSearchState)searchState; IWord word = wordState.getPronunciation().getWord(); sb.Insert(0, ' ' + word.getSpelling()); } else if (searchState is IUnitSearchState) { IUnitSearchState unitState = (IUnitSearchState)searchState; IUnit unit = unitState.getUnit(); sb.Insert(0, ' ' + unit.getName()); } token = token.getPredecessor(); } return(sb.ToString().Trim()); }