Example usage for opennlp.tools.languagemodel NGramLanguageModel NGramLanguageModel

List of usage examples for opennlp.tools.languagemodel NGramLanguageModel NGramLanguageModel

Introduction

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

Prototype

public NGramLanguageModel() 

Source Link

Usage

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

@Test
public void testEmptyVocabularyProbability() throws Exception {
    NGramLanguageModel model = new NGramLanguageModel();
    Assert.assertEquals("probability with an empty vocabulary is always 0", 0d,
            model.calculateProbability(new StringList("")), 0d);
    Assert.assertEquals("probability with an empty vocabulary is always 0", 0d,
            model.calculateProbability(new StringList("1", "2", "3")), 0d);
}

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 www . java 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);
}