Example usage for opennlp.tools.ngram NGramModel NGramModel

List of usage examples for opennlp.tools.ngram NGramModel NGramModel

Introduction

In this page you can find the example usage for opennlp.tools.ngram NGramModel NGramModel.

Prototype

public NGramModel() 

Source Link

Document

Initializes an empty instance.

Usage

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testZeroGetCount() throws Exception {
    NGramModel ngramModel = new NGramModel();
    int count = ngramModel.getCount(new StringList(""));
    Assert.assertEquals(0, count);/*from w w w  .j ava 2  s .  c  om*/
    Assert.assertEquals(0, ngramModel.size());
}

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testZeroGetCount2() throws Exception {
    NGramModel ngramModel = new NGramModel();
    ngramModel.add(new StringList("the", "bro", "wn"));
    int count = ngramModel.getCount(new StringList("fox"));
    Assert.assertEquals(0, count);/*  ww w. j  a va2 s .  c o  m*/
    Assert.assertEquals(1, ngramModel.size());
}

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testAdd() throws Exception {
    NGramModel ngramModel = new NGramModel();
    ngramModel.add(new StringList("the", "bro", "wn"));
    int count = ngramModel.getCount(new StringList("the"));
    Assert.assertEquals(0, count);/*  www .  jav  a2 s.co m*/
    Assert.assertEquals(1, ngramModel.size());
}

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testAdd1() throws Exception {
    NGramModel ngramModel = new NGramModel();
    ngramModel.add(new StringList("the", "bro", "wn"));
    int count = ngramModel.getCount(new StringList("the", "bro", "wn"));
    Assert.assertEquals(1, count);/*from  w w w  .  j  av  a2s  . co m*/
    Assert.assertEquals(1, ngramModel.size());
}

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testAdd2() throws Exception {
    NGramModel ngramModel = new NGramModel();
    ngramModel.add(new StringList("the", "bro", "wn"), 2, 3);
    int count = ngramModel.getCount(new StringList("the", "bro", "wn"));
    Assert.assertEquals(1, count);/* w ww .ja  va2  s .  c  o  m*/
    Assert.assertEquals(3, ngramModel.size());
}

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testAdd3() throws Exception {
    NGramModel ngramModel = new NGramModel();
    ngramModel.add(new StringList("the", "brown", "fox"), 2, 3);
    int count = ngramModel.getCount(new StringList("the", "brown", "fox"));
    Assert.assertEquals(1, count);/*from w ww  .java 2  s . c o  m*/
    count = ngramModel.getCount(new StringList("the", "brown"));
    Assert.assertEquals(1, count);
    count = ngramModel.getCount(new StringList("brown", "fox"));
    Assert.assertEquals(1, count);
    Assert.assertEquals(3, ngramModel.size());
}

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testRemove() throws Exception {
    NGramModel ngramModel = new NGramModel();
    StringList tokens = new StringList("the", "bro", "wn");
    ngramModel.add(tokens);/*from ww w  .  ja v a 2s. co  m*/
    ngramModel.remove(tokens);
    Assert.assertEquals(0, ngramModel.size());
}

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testContains() throws Exception {
    NGramModel ngramModel = new NGramModel();
    StringList tokens = new StringList("the", "bro", "wn");
    ngramModel.add(tokens);/*from www.  j  av a 2  s . c  om*/
    Assert.assertFalse(ngramModel.contains(new StringList("the")));
}

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testContains2() throws Exception {
    NGramModel ngramModel = new NGramModel();
    StringList tokens = new StringList("the", "bro", "wn");
    ngramModel.add(tokens, 1, 3);/*from   ww  w  .  j ava  2  s  . c  o  m*/
    Assert.assertTrue(ngramModel.contains(new StringList("the")));
}

From source file:opennlp.tools.ngram.NGramModelTest.java

@Test
public void testNumberOfGrams() throws Exception {
    NGramModel ngramModel = new NGramModel();
    StringList tokens = new StringList("the", "bro", "wn");
    ngramModel.add(tokens, 1, 3);// www .  jav  a  2  s  .  co m
    Assert.assertEquals(6, ngramModel.numberOfGrams());
}