- java.lang.Object
-
- com.pervasive.datarush.analytics.text.NGram
-
- All Implemented Interfaces:
Comparable<NGram>
public class NGram extends Object implements Comparable<NGram>
Implementation of an n-gram. An n-gram is a contiguous sequence of n items from a given sequence of text or speech. An item can consist of characters, words, or strings, although typically they model word relationships.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(NGram o)
boolean
equals(Object obj)
int
getN()
Gets the N used by this NGram.String
getWordN(int index)
Get the Nth word in this NGram.List<String>
getWords()
Gets the words in this NGram.int
hashCode()
ListIterator<String>
iterator()
Get an iterator over the words of the NGram.String
toString()
-
-
-
Constructor Detail
-
NGram
public NGram()
Default constructor for empty NGram
-
NGram
public NGram(int n, String... words)
Creates an NGram of degree n consisting of a list of words.- Parameters:
n
- The degree of the NGramwords
- The words of the NGram
-
-
Method Detail
-
getN
public int getN()
Gets the N used by this NGram.- Returns:
- the N used by this NGram
-
getWords
public List<String> getWords()
Gets the words in this NGram.- Returns:
- the words in this NGram
-
getWordN
public String getWordN(int index)
Get the Nth word in this NGram. Uses 0 for the starting index.- Parameters:
index
- the index of the word in the NGram- Returns:
- the word at index in this NGram
-
iterator
public ListIterator<String> iterator()
Get an iterator over the words of the NGram.- Returns:
- iterator over the words of the NGram
-
compareTo
public int compareTo(NGram o)
- Specified by:
compareTo
in interfaceComparable<NGram>
-
-