|
@@ -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.
|
|
@@ -32,8 +34,99 @@ public class HamletParser {
|
32
|
34
|
return result.toString();
|
33
|
35
|
}
|
34
|
36
|
|
35
|
|
- public String getHamletData(){
|
|
37
|
+ public static int changeHamletToLeon(String line){
|
|
38
|
+
|
|
39
|
+ int count=0;
|
|
40
|
+ Pattern patternHamlet =Pattern. compile("\\bHamlet\\b",Pattern.CASE_INSENSITIVE);
|
|
41
|
+ Matcher m1=patternHamlet.matcher(line);
|
|
42
|
+
|
|
43
|
+ String str1=((Matcher) m1).replaceAll("Leon");
|
|
44
|
+
|
|
45
|
+ Matcher m11=patternHamlet.matcher(str1);
|
|
46
|
+
|
|
47
|
+ while(m11.find())
|
|
48
|
+
|
|
49
|
+ {
|
|
50
|
+ count++;
|
|
51
|
+ }
|
|
52
|
+ return count;
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ public static int changeHoratioToTariq(String line) {
|
|
56
|
+
|
|
57
|
+ int count=0;
|
|
58
|
+
|
|
59
|
+ Pattern patternHoratio =Pattern.compile("\\bHoratio\\b",Pattern.CASE_INSENSITIVE);
|
|
60
|
+
|
|
61
|
+ Matcher m2=patternHoratio.matcher(line);
|
|
62
|
+
|
|
63
|
+ String str2=((Matcher) m2).replaceAll("Tariq");
|
|
64
|
+
|
|
65
|
+ Matcher m22=patternHoratio.matcher(str2);
|
|
66
|
+
|
|
67
|
+ while(m22.find())
|
|
68
|
+
|
|
69
|
+ {
|
|
70
|
+ count++;
|
|
71
|
+
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ return count;
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+ public String getHamletData()
|
|
79
|
+
|
|
80
|
+ {
|
36
|
81
|
return hamletData;
|
|
82
|
+
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ public int FindHoratio()
|
|
86
|
+
|
|
87
|
+ {
|
|
88
|
+ int count=0;
|
|
89
|
+
|
|
90
|
+ Pattern patternHoratio =Pattern.compile("\\bHoratio\\b",Pattern.CASE_INSENSITIVE);
|
|
91
|
+
|
|
92
|
+ Matcher m2=patternHoratio.matcher(hamletData);
|
|
93
|
+
|
|
94
|
+ while(m2.find())
|
|
95
|
+
|
|
96
|
+ {
|
|
97
|
+ count++;
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ return count;
|
|
101
|
+
|
37
|
102
|
}
|
38
|
103
|
|
|
104
|
+ public int FindHamlet()
|
|
105
|
+
|
|
106
|
+ {
|
|
107
|
+ int count=0;
|
|
108
|
+
|
|
109
|
+ Pattern patternHamlet =Pattern.compile("\\bHamlet\\b",Pattern.CASE_INSENSITIVE);
|
|
110
|
+
|
|
111
|
+ Matcher m2=patternHamlet.matcher(hamletData);
|
|
112
|
+
|
|
113
|
+ while(m2.find())
|
|
114
|
+
|
|
115
|
+ {
|
|
116
|
+ count++;
|
|
117
|
+
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ return count;
|
|
121
|
+
|
|
122
|
+ }
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+ public static void main(String[] args) {
|
|
127
|
+
|
|
128
|
+ HamletParser hamletParser=new HamletParser();
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+
|
39
|
132
|
}
|