|
@@ -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,6 +10,7 @@ import java.util.Scanner;
|
8
|
10
|
public class HamletParser {
|
9
|
11
|
|
10
|
12
|
private String hamletData;
|
|
13
|
+ private int counter = 0;
|
11
|
14
|
|
12
|
15
|
public HamletParser(){
|
13
|
16
|
this.hamletData = loadFile();
|
|
@@ -33,7 +36,65 @@ public class HamletParser {
|
33
|
36
|
}
|
34
|
37
|
|
35
|
38
|
public String getHamletData(){
|
|
39
|
+
|
36
|
40
|
return hamletData;
|
37
|
41
|
}
|
38
|
42
|
|
|
43
|
+ public boolean findHoratio(){
|
|
44
|
+ return findMatch("[Hh][Oo][Rr][Aa][Tt][Ii][Oo]", hamletData);
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+ public boolean findHamlet(){
|
|
49
|
+ return findMatch("[Hh][Aa][Mm][Ll][Ee][Tt]", hamletData);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ public String changeHamletToLeon(String stringBook){
|
|
53
|
+
|
|
54
|
+ Pattern patternReplace = Pattern.compile("[Hh][a][m][l][e][t]");
|
|
55
|
+ Matcher matcher = patternReplace.matcher(stringBook);
|
|
56
|
+ String finalReplace = matcher.replaceAll("Leon");
|
|
57
|
+
|
|
58
|
+ Pattern patternReplaceCaps = Pattern.compile("HAMLET");
|
|
59
|
+ Matcher matcherCaps = patternReplaceCaps.matcher(finalReplace);
|
|
60
|
+ String finalReplaceCaps = matcherCaps.replaceAll("LEON");
|
|
61
|
+
|
|
62
|
+ return finalReplaceCaps;
|
|
63
|
+
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+ public String changeHoratioToTariq(String stringBook){
|
|
67
|
+
|
|
68
|
+ Pattern patternReplace = Pattern.compile("[Hh][o][r][a][t][i][o]");
|
|
69
|
+ Matcher matcher = patternReplace.matcher(stringBook);
|
|
70
|
+ String finalReplace = matcher.replaceAll("Tariq");
|
|
71
|
+
|
|
72
|
+ Pattern patternReplaceCaps = Pattern.compile("HORATIO");
|
|
73
|
+ Matcher matcherCaps = patternReplaceCaps.matcher(finalReplace);
|
|
74
|
+ String finalReplaceCaps = matcherCaps.replaceAll("TARIQ");
|
|
75
|
+
|
|
76
|
+ return finalReplaceCaps;
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ public int getCounterTimeSeen(){
|
|
80
|
+ return counter;
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+ public boolean findMatch(String regexSearch, String hamletData){
|
|
85
|
+
|
|
86
|
+ Pattern checkRegex = Pattern.compile(regexSearch);
|
|
87
|
+
|
|
88
|
+ Matcher regexMatcher = checkRegex.matcher(hamletData);
|
|
89
|
+
|
|
90
|
+ boolean findMatch = false;
|
|
91
|
+
|
|
92
|
+ while(regexMatcher.find()){
|
|
93
|
+ findMatch = true;
|
|
94
|
+ counter++;
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ return findMatch;
|
|
98
|
+ }
|
|
99
|
+
|
39
|
100
|
}
|