|
@@ -1,6 +1,9 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
|
3
|
+import java.util.ArrayList;
|
3
|
4
|
import java.util.Scanner;
|
|
5
|
+import java.util.regex.Matcher;
|
|
6
|
+import java.util.regex.Pattern;
|
4
|
7
|
|
5
|
8
|
/**
|
6
|
9
|
* Created by thook on 10/7/15.
|
|
@@ -36,4 +39,50 @@ public class HamletParser {
|
36
|
39
|
return hamletData;
|
37
|
40
|
}
|
38
|
41
|
|
|
42
|
+ public int findHamlet() {
|
|
43
|
+ int hamletCount = 0;
|
|
44
|
+ Pattern findHamlet = Pattern.compile("\\bHamlet\\b|\\bHAMLET\\b");
|
|
45
|
+ Matcher hamlet = findHamlet.matcher(hamletData);
|
|
46
|
+ while(hamlet.find()){
|
|
47
|
+ hamletCount++;
|
|
48
|
+ }
|
|
49
|
+ return hamletCount;
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ public int findHoratio() {
|
|
53
|
+ int horatioCount = 0;
|
|
54
|
+ Pattern findHoratio = Pattern.compile("\\bHoratio\\b|\\bHORATIO\\b");
|
|
55
|
+ Matcher horatio = findHoratio.matcher(hamletData);
|
|
56
|
+ while(horatio.find()){
|
|
57
|
+ horatioCount++;
|
|
58
|
+ }
|
|
59
|
+ return horatioCount;
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ public String changeHoratioToTariq() {
|
|
63
|
+ Pattern findHoratio = Pattern.compile("\\bHoratio\\b");
|
|
64
|
+ Matcher horatio = findHoratio.matcher(hamletData);
|
|
65
|
+ horatio.find();
|
|
66
|
+ this.hamletData= horatio.replaceAll("Tariq");
|
|
67
|
+ Pattern findHoratio2 = Pattern.compile("\\bHORATIO\\b");
|
|
68
|
+ Matcher horatio2 = findHoratio2.matcher(hamletData);
|
|
69
|
+ horatio2.find();
|
|
70
|
+ this.hamletData= horatio2.replaceAll("TARIQ");
|
|
71
|
+
|
|
72
|
+ return hamletData;
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ public String changeHamletToLeon() {
|
|
76
|
+ Pattern findHamlet = Pattern.compile("\\Hamlet\\b");
|
|
77
|
+ Matcher hamlet = findHamlet.matcher(hamletData);
|
|
78
|
+ hamlet.find();
|
|
79
|
+ this.hamletData= hamlet.replaceAll("Leon");
|
|
80
|
+ Pattern findHamlet2 = Pattern.compile("\\HAMLET\\b");
|
|
81
|
+ Matcher hamlet2 = findHamlet2.matcher(hamletData);
|
|
82
|
+ hamlet2.find();
|
|
83
|
+ this.hamletData= hamlet2.replaceAll("Leon");
|
|
84
|
+
|
|
85
|
+ return hamletData;
|
|
86
|
+ }
|
39
|
87
|
}
|
|
88
|
+
|