Package opennlp.tools.ngram
Class NGramGenerator
- java.lang.Object
-
- opennlp.tools.ngram.NGramGenerator
-
public class NGramGenerator extends Object
Generates an nGram, via an optional separator, and returns the grams as a list of strings
-
-
Constructor Summary
Constructors Constructor Description NGramGenerator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<String>
generate(char[] input, int n, String separator)
Generates nGrams based on achar[]
input.static List<String>
generate(List<String> input, int n, String separator)
Creates nGrams separated by the separator param value i.e.
-
-
-
Method Detail
-
generate
public static List<String> generate(List<String> input, int n, String separator)
Creates nGrams separated by the separator param value i.e.a,b,c,d
withn = 3
and a separator as"-"
would returna-b-c,b-c-d
.- Parameters:
input
- the input tokens the output ngrams will be derived fromn
- the number of tokens as the sliding windowseparator
- each string in each gram will be separated by this value if desired. Pass in empty string if no separator is desired- Returns:
- The generated list of resulting nGrams.
-
generate
public static List<String> generate(char[] input, int n, String separator)
Generates nGrams based on achar[]
input.- Parameters:
input
- the array of chars to convert to nGramn
- The number of grams (chars) that each output gram will consist ofseparator
- each char in each gram will be separated by this value if desired. Pass in empty string if no separator is desired- Returns:
- The generated list of resulting nGrams.
-
-