Java で空白または数字を除くすべての句読点を削除する方法。
"\\p{Punct}|\\d", "" //THIS WORKS BUT IT REMOVES THE NUMBERS AND I DONT WANT IT TO REMOVE THE NUMBERS...
テキストを読んでいて、句読点を削除する必要があります。
String[] internal;
char ch = 'a';
int counter = 1;
int count;
int c;
Map<String, Set> dictionary = new HashMap<String, Set>();
BufferedReader in = new BufferedReader(new FileReader("yu.txt"));
while (in.ready()) {
internal = (((in.readLine()).replaceAll("\\p{Punct}|\\d", "")).toLowerCase()).split(" ");//this does not work in my case cause it removes numbers... and makes them whitespaces but other than that this one works I JUST dont want it to remove numbers and keep whitespaces...
for (count = 0; count < internal.length; count++) {
if (!dictionary.containsKey(internal[count])) {
dictionary.put(internal[count], new HashSet());
}
if (dictionary.get(internal[count]).size()<10)
{
dictionary.get(internal[count]).add(counter);
}
}
counter++;
}
Iterator iterator = dictionary.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next().toString();
String value = dictionary.get(key).toString();
System.out.println(key + ": " + value );
}