|
@@ -1,6 +1,8 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
3
|
3
|
import java.util.Scanner;
|
|
4
|
+import java.util.regex.Matcher;
|
|
5
|
+import java.util.regex.Pattern;
|
4
|
6
|
|
5
|
7
|
/**
|
6
|
8
|
* Created by thook on 10/7/15.
|
|
@@ -8,9 +10,12 @@ import java.util.Scanner;
|
8
|
10
|
public class HamletParser {
|
9
|
11
|
|
10
|
12
|
private String hamletData;
|
|
13
|
+ private Pattern pattern;
|
|
14
|
+ private Matcher matcher;
|
11
|
15
|
|
12
|
16
|
public HamletParser(){
|
13
|
17
|
this.hamletData = loadFile();
|
|
18
|
+
|
14
|
19
|
}
|
15
|
20
|
|
16
|
21
|
private String loadFile(){
|
|
@@ -36,4 +41,66 @@ public class HamletParser {
|
36
|
41
|
return hamletData;
|
37
|
42
|
}
|
38
|
43
|
|
|
44
|
+
|
|
45
|
+ public void changeHoratioToTariq(){
|
|
46
|
+
|
|
47
|
+ String horatio = "(Horatio|HORATIO)";
|
|
48
|
+
|
|
49
|
+ pattern = Pattern.compile(horatio);
|
|
50
|
+
|
|
51
|
+ matcher = pattern.matcher(hamletData);
|
|
52
|
+ hamletData = matcher.replaceAll("Tariq");
|
|
53
|
+
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+ public void changeHamletToLeon() {
|
|
58
|
+ String hamlet = "(Hamlet| HAMLET)";
|
|
59
|
+
|
|
60
|
+ pattern = Pattern.compile(hamlet);
|
|
61
|
+ matcher = pattern.matcher(hamletData);
|
|
62
|
+
|
|
63
|
+ hamletData = matcher.replaceAll("Leon");
|
|
64
|
+
|
|
65
|
+ }
|
|
66
|
+ public String printOut(){
|
|
67
|
+ System.out.println(this.hamletData);
|
|
68
|
+ return this.hamletData;
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+ public static void main(String[] args) {
|
|
73
|
+ HamletParser hamletParser = new HamletParser();
|
|
74
|
+ hamletParser.changeHamletToLeon();
|
|
75
|
+ hamletParser.printOut();
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ public boolean findHoratio() {
|
|
79
|
+ String horatio = "(Horatio|HORATIO)";
|
|
80
|
+
|
|
81
|
+ pattern = Pattern.compile(horatio);
|
|
82
|
+
|
|
83
|
+ matcher = pattern.matcher(hamletData);
|
|
84
|
+
|
|
85
|
+ if(hamletData.contains("(Horatio|HORATIO)")){
|
|
86
|
+ return true;
|
|
87
|
+ }
|
|
88
|
+ return false;
|
|
89
|
+
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+ public boolean findHamlet() {
|
|
94
|
+ String hamlet = "(Hamlet| HAMLET)";
|
|
95
|
+
|
|
96
|
+ pattern = Pattern.compile(hamlet);
|
|
97
|
+ matcher = pattern.matcher(hamletData);
|
|
98
|
+
|
|
99
|
+ if (hamletData.contains("(Hamlet| HAMLET)")) {
|
|
100
|
+ return true;
|
|
101
|
+ }
|
|
102
|
+ return false;
|
|
103
|
+
|
|
104
|
+ }
|
|
105
|
+
|
39
|
106
|
}
|