Created
May 24, 2017 23:43
-
-
Save gAmUssA/e00bb6a77e90f4abe738f192bf549031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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