|
@@ -1,18 +1,29 @@
|
|
1
|
+
|
|
2
|
+
|
1
|
3
|
import java.io.File;
|
2
|
4
|
import java.io.IOException;
|
3
|
5
|
import java.util.Scanner;
|
|
6
|
+import java.util.regex.Matcher;
|
|
7
|
+import java.util.regex.Pattern;
|
4
|
8
|
|
5
|
9
|
/**
|
6
|
10
|
* Created by thook on 10/7/15.
|
7
|
11
|
*/
|
8
|
12
|
public class HamletParser {
|
9
|
13
|
|
|
14
|
+ private String[] words;
|
10
|
15
|
private String hamletData;
|
11
|
16
|
|
12
|
17
|
public HamletParser(){
|
|
18
|
+
|
13
|
19
|
this.hamletData = loadFile();
|
14
|
20
|
}
|
15
|
21
|
|
|
22
|
+ public HamletParser(String input){
|
|
23
|
+ this.hamletData = input;
|
|
24
|
+ this.words = input.split("\\W");
|
|
25
|
+ }
|
|
26
|
+
|
16
|
27
|
private String loadFile(){
|
17
|
28
|
ClassLoader classLoader = getClass().getClassLoader();
|
18
|
29
|
File file = new File(classLoader.getResource("hamlet.txt").getFile());
|
|
@@ -32,8 +43,74 @@ public class HamletParser {
|
32
|
43
|
return result.toString();
|
33
|
44
|
}
|
34
|
45
|
|
|
46
|
+ //I know I need pattern and I know I need matching
|
|
47
|
+// public static void changeHamletToLeon(String hamlet, String file2Check){
|
|
48
|
+//
|
|
49
|
+// Pattern checkHamletRegex = Pattern.compile(hamlet);
|
|
50
|
+// Matcher regexMatcher = checkHamletRegex.matcher(file2Check);
|
|
51
|
+//
|
|
52
|
+// while(regexMatcher.find()){
|
|
53
|
+// if(regexMatcher.group().length()!=0){
|
|
54
|
+//
|
|
55
|
+// }
|
|
56
|
+// }
|
|
57
|
+// }
|
|
58
|
+
|
|
59
|
+
|
35
|
60
|
public String getHamletData(){
|
|
61
|
+
|
36
|
62
|
return hamletData;
|
37
|
63
|
}
|
38
|
64
|
|
|
65
|
+
|
|
66
|
+ public void changeHamletToLeon(){
|
|
67
|
+ String hamletText = "Hamlet";
|
|
68
|
+ String leonText = "Leon";
|
|
69
|
+
|
|
70
|
+ Pattern checkRegex = Pattern.compile(hamletText);
|
|
71
|
+ Matcher m = checkRegex.matcher(hamletData);
|
|
72
|
+
|
|
73
|
+ hamletData = m.replaceAll(leonText);
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+ public void changeHoratioToTariq(){
|
|
77
|
+ String horatioText = "Horatio";
|
|
78
|
+ String tariqText = "Tariq";
|
|
79
|
+
|
|
80
|
+ Pattern checkRegex = Pattern.compile(horatioText);
|
|
81
|
+ Matcher m = checkRegex.matcher(hamletData);
|
|
82
|
+
|
|
83
|
+ hamletData = m.replaceAll(tariqText);
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ public boolean findHamlet(){
|
|
87
|
+ boolean findHamlet = false;
|
|
88
|
+
|
|
89
|
+ String hamletString = "Hamlet";
|
|
90
|
+
|
|
91
|
+ Pattern checkHamletRegex = Pattern.compile(hamletString);
|
|
92
|
+ Matcher regexHamletMatcher = checkHamletRegex.matcher(hamletData);
|
|
93
|
+
|
|
94
|
+ if(regexHamletMatcher.find()){
|
|
95
|
+ findHamlet = true;
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ return findHamlet;
|
|
99
|
+ }
|
|
100
|
+
|
|
101
|
+ public boolean findHoratio(){
|
|
102
|
+ boolean findHoratio = false;
|
|
103
|
+
|
|
104
|
+ String horatioString = "Horatio";
|
|
105
|
+
|
|
106
|
+ Pattern checkHoratioRegex = Pattern.compile(horatioString);
|
|
107
|
+ Matcher regexHoratioMatcher = checkHoratioRegex.matcher(hamletData);
|
|
108
|
+
|
|
109
|
+ if(regexHoratioMatcher.find()){
|
|
110
|
+ findHoratio = true;
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ return findHoratio;
|
|
114
|
+ }
|
|
115
|
+
|
39
|
116
|
}
|