|
@@ -2,10 +2,10 @@ package io.zipcoder;
|
2
|
2
|
|
3
|
3
|
import java.io.FileNotFoundException;
|
4
|
4
|
import java.io.FileReader;
|
5
|
|
-import java.util.Iterator;
|
6
|
|
-import java.util.Scanner;
|
|
5
|
+import java.util.*;
|
7
|
6
|
|
8
|
7
|
public class WC {
|
|
8
|
+ private final List<String> list;
|
9
|
9
|
private Iterator<String> si;
|
10
|
10
|
|
11
|
11
|
public WC(String fileName) {
|
|
@@ -19,5 +19,34 @@ public class WC {
|
19
|
19
|
|
20
|
20
|
public WC(Iterator<String> si) {
|
21
|
21
|
this.si = si;
|
|
22
|
+
|
|
23
|
+ while(si.hasNext()) {
|
|
24
|
+ list.add(si.next());
|
|
25
|
+ }
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+ public HashMap<String, Integer> countTheWords (String input) {
|
|
30
|
+ input.toLowerCase();
|
|
31
|
+ String[] words = input.split("[\\p{Punct}\\s]+");
|
|
32
|
+ System.out.println(words);
|
|
33
|
+ HashMap<String, Integer> wordCount = new HashMap<String, Integer>();
|
|
34
|
+
|
|
35
|
+ for(String word: words) {
|
|
36
|
+ if(wordCount.get(word) == null) {
|
|
37
|
+ wordCount.put(word, 1);
|
|
38
|
+ } else {
|
|
39
|
+ int value = wordCount.get(word);
|
|
40
|
+ value++;
|
|
41
|
+ wordCount.put(word, value);
|
|
42
|
+ }
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ return wordCount;
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ public Iterator<String> getSi() {
|
|
49
|
+
|
|
50
|
+ return si;
|
22
|
51
|
}
|
23
|
52
|
}
|