Package edu.cmu.sphinx.linguist

Examples of edu.cmu.sphinx.linguist.WordSequence


                for (String pathWord : path.split(" ")) {
                    wordList.add(new Word(pathWord, null, false));
                }
                wordList.add(edge.getToNode().getWord());

                WordSequence seq = new WordSequence(wordList);
                float prob = model.getProbability(seq) * languageWeigth;
                if (minProb < prob)
                    minProb = prob;
            }
            edge.setLMScore(minProb);
View Full Code Here


    private float getWordUnigramProbability(Word word) {
        float prob = LogMath.LOG_ONE;
        if (!word.isFiller()) {
            Word[] wordArray = new Word[1];
            wordArray[0] = word;
            prob = lm.getProbability((new WordSequence(wordArray)));
            // System.out.println("gwup: " + word + " " + prob);
            prob *= languageWeight;
        }
        return prob;
    }
View Full Code Here

                return new LexTreeWordState(wordNode, lastUnit,
                        wordSequence,
                        smearTerm, logOne, languageProbability, collapsed);
            }

            WordSequence nextWordSequence = wordSequence.addWord(nextWord, maxDepth);
            ProbDepth probDepth = languageModel.getProbDepth(nextWordSequence);
            smearTerm = getSmearTermFromLanguageModel(nextWordSequence);
            // System.out.println("LP " + nextWordSequence + " " +
            // logProbability);
            float probability = probDepth.probability * languageWeight;
            // subtract off the previously applied smear probability
            languageProbability = probability - previous.getSmearProb();

            boolean collapse = (probDepth.depth < maxDepth - 1) || !fullWordHistories;

            if (nextWord == sentenceEndWord) {
                return new LexTreeEndWordState(wordNode, lastUnit,
                        nextWordSequence.trim(maxDepth - 1),
                        smearTerm, logOne, languageProbability, collapse);
            }

            return new LexTreeWordState(wordNode, lastUnit,
                        nextWordSequence.trim(maxDepth - 1),
                        smearTerm, logOne, languageProbability, collapse);
        }
View Full Code Here

        assertThat(model.getMaxDepth(), equalTo(3));

        Word[] words = {
            new Word("huggins", null, false),
            new Word("daines", null, false)};
        assertThat((double) model.getProbability(new WordSequence(words)),
                   closeTo(-830.862, .001));

        Word[] words1 = {
            new Word("huggins", null, false),
            new Word("daines", null, false),
            new Word("david", null, false)};
        assertThat((double) model.getProbability(new WordSequence(words1)),
                   closeTo(-67625.77, .01));
    }
View Full Code Here

     */
    private NGramProbability findNGram(WordSequence wordSequence) {
        int numberWords = wordSequence.size();
        NGramProbability nGram = null;

        WordSequence oldest = wordSequence.getOldest();
        NGramBuffer nGramBuffer =
            loadedNGramBuffers[numberWords - 1].get(oldest);
        if (nGramBuffer == null) {
            nGramBuffer = getNGramBuffer(oldest);
            if (nGramBuffer != null)
View Full Code Here

     * @return the bigrams of the word
     */
    private NGramBuffer getBigramBuffer(int firstWordID) {
        Word[] wd = new Word[1];
        wd[0] = dictionary.getWord(loader.getWords()[firstWordID]);
        WordSequence ws = new WordSequence(wd);

        return loadNGramBuffer(ws);
    }
View Full Code Here

     */
    private NGramBuffer loadTrigramBuffer(int firstWordID, int secondWordID) {
        Word[] wd = new Word[2];
        wd[0] = dictionary.getWord(loader.getWords()[firstWordID]);
        wd[1] = dictionary.getWord(loader.getWords()[secondWordID]);
        WordSequence ws = new WordSequence(wd);

        return loadNGramBuffer(ws);
    }
View Full Code Here

    public void unigramModel() throws IOException {
        DynamicTrigramModel model = new DynamicTrigramModel(dictionary);
        model.setText(asList("one"));
        model.allocate();
        assertThat(model.getVocabulary(), contains("one"));
        assertThat(model.getProbability(new WordSequence(dictionary
                .getWord("one"))), equalTo(getLogMath().linearToLog(1)));
    }
View Full Code Here

        InitialWordNode node = hmmTree.getInitialNode();

        if (node == null)
          throw new RuntimeException("Language model has no entry for initial word <s>");

        return new LexTreeWordState(node, node.getParent(), (new WordSequence(sentenceStartWordArray)).trim(
                maxDepth - 1), 0f, logOne, logOne, false);
    }
View Full Code Here

                String prevWord = prevNode.getWord().getSpelling();
                String nextWord = nextNode.getWord().getSpelling();
                Word[] wordArray = {getDictionary().getWord(prevWord),
                        getDictionary().getWord(nextWord)};
                float logProbability = languageModel
                        .getProbability((new WordSequence(wordArray)));
                prevNode.add(nextNode, logProbability);
            }
        }
        TimerPool.getTimer(this,"LMGrammar.create").stop();
        languageModel.deallocate();
View Full Code Here

TOP

Related Classes of edu.cmu.sphinx.linguist.WordSequence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.