src/main/java/pt/it/av/tnav/ml/tm/TM.java
public static List<NGram> extractNGrams(String[] tokens, int begin, int end, int n) {
        List<NGram> rv = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            for (int j = begin; j < end - i + 1; j++) {
                String buffer[] = new String[i];
                for (int k = 0; k < i; k++)
                    buffer[k] = tokens[j + k];
                rv.add(new NGram(buffer));
            }
        }
        return rv;
    }
/**
     * Returns the possible ngrams (until n) from the tokens.
     *
     * @param tokens array of tokens
     * @param begin  the index of the first element (inclusive)
     * @param end    the index of the last element (exclusive)
     * @param n      maximum number of tokens in a ngram
     * @return list of ngrams extracted from the tokens
     */
Returns the possible ngrams (until n) from the tokens.
Returns the possible ngrams ( until n ) from the tokens .
public static List<NGram> extractNGrams(String[] tokens, int begin, int end, int n) {
        List<NGram> rv = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            for (int j = begin; j < end - i + 1; j++) {
                String buffer[] = new String[i];
                for (int k = 0; k < i; k++)
                    buffer[k] = tokens[j + k];
                rv.add(new NGram(buffer));
            }
        }
        return rv;
    }
public static List < NGram > extractNGrams ( String [ ] tokens , int begin , int end , int n ) { List < NGram > rv = new ArrayList < > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = begin ; j < end - i + 1 ; j ++ ) { String buffer [ ] = new String [ i ] ; for ( int k = 0 ; k < i ; k ++ ) buffer [ k ] = tokens [ j + k ] ; rv . add ( new NGram ( buffer ) ) ; } } return rv ; }
Returns the possible ngrams (until n) from the tokens.
Returns the possible ngrams ( until n ) from the tokens .