Here you can find the source of extractCharNgram(String content, int n)
Parameter | Description |
---|---|
content | the input String |
n | the size of the character n-gram |
public static List<String> extractCharNgram(String content, int n)
//package com.java2s; /*/*from w w w .j ava 2s . c o m*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.ArrayList; import java.util.List; public class Main { /** * Calculates character n-grams from a String. * * @param content the input String * @param n the size of the character n-gram * @return a list with the character n-grams */ public static List<String> extractCharNgram(String content, int n) { List<String> charNgram = new ArrayList<String>(); if (content.length() >= n) { for (int i = 0; i < content.length() - n; i++) { String cgram = ""; for (int j = i; j < i + n; j++) { cgram += content.charAt(j); } charNgram.add(cgram); } } return charNgram; } }