Skip to content

Instantly share code, notes, and snippets.

@gAmUssA
Created May 24, 2017 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gAmUssA/e00bb6a77e90f4abe738f192bf549031 to your computer and use it in GitHub Desktop.
Save gAmUssA/e00bb6a77e90f4abe738f192bf549031 to your computer and use it in GitHub Desktop.
package com.nyjavasig.how.hazelcast.demo;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public class WordUtil {
public static final Pattern PATTERN = Pattern.compile("\\W+");
public static final String[] EXCLUDES = {"which", "would", "could", "that", "with", "were", "this", "what", "there", "from", "their", "those", "chorus"};
public static final String SOURCE_SUFFIX = "_source";
public static final String COUNTS_SOURCE = "_counts";
private WordUtil() {
}
public static String cleanWord(String word) {
return word.replaceAll("[^A-Za-zA-Яа-я]", "");
}
public static void fillMapWithData(String fileName, Map<Integer, String> map)
throws Exception {
InputStream is = com.hazelcast.util.WordUtil.class.getClassLoader().getResourceAsStream(fileName);
LineNumberReader reader = new LineNumberReader(new InputStreamReader(is));
String line;
Integer lineNum = 0;
Map<Integer, String> localMap = new HashMap<>();
while ((line = reader.readLine()) != null) {
lineNum++;
localMap.put(lineNum, line);
}
map.putAll(localMap);
is.close();
reader.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment