Example usage for opennlp.tools.languagemodel LanguageModelTestUtils generateRandomSentence

List of usage examples for opennlp.tools.languagemodel LanguageModelTestUtils generateRandomSentence

Introduction

In this page you can find the example usage for opennlp.tools.languagemodel LanguageModelTestUtils generateRandomSentence.

Prototype

public static String[] generateRandomSentence() 

Source Link

Usage

From source file:opennlp.tools.languagemodel.NgramLanguageModelTest.java

@Test
public void testRandomVocabularyAndSentence() throws Exception {
    NGramLanguageModel model = new NGramLanguageModel();
    for (StringList sentence : LanguageModelTestUtils.generateRandomVocabulary(10)) {
        model.add(sentence, 2, 3);//from w  w w .j a  v  a  2  s  .c o  m
    }
    double probability = model.calculateProbability(LanguageModelTestUtils.generateRandomSentence());
    Assert.assertTrue("a probability measure should be between 0 and 1 [was " + probability + "]",
            probability >= 0 && probability <= 1);
}