opennlp.tools.util.StringList Java Examples

The following examples show how to use opennlp.tools.util.StringList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NGramTest.java    From Natural-Language-Processing-with-Java-Second-Edition with MIT License 5 votes vote down vote up
public static void main(String args[]){
    String sampletext = "This is n-gram model";
    System.out.println(sampletext);
    
    StringList tokens = new StringList(WhitespaceTokenizer.INSTANCE.tokenize(sampletext));
    System.out.println("Tokens " + tokens);
    
    NGramModel nGramModel = new NGramModel();
    nGramModel.add(tokens,2,4); // minlength and maxlength
    
    System.out.println("Total ngrams: " + nGramModel.numberOfGrams());
    for (StringList ngram : nGramModel) {
        System.out.println(nGramModel.getCount(ngram) + " - " + ngram);
    }
}