|
@@ -1,6 +1,10 @@
|
|
1
|
+import jdk.nashorn.internal.runtime.regexp.RegExp;
|
|
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.
|
|
@@ -8,6 +12,7 @@ import java.util.Scanner;
|
8
|
12
|
public class HamletParser {
|
9
|
13
|
|
10
|
14
|
private String hamletData;
|
|
15
|
+ private String hamletDataTemp = hamletData;
|
11
|
16
|
|
12
|
17
|
public HamletParser(){
|
13
|
18
|
this.hamletData = loadFile();
|
|
@@ -36,4 +41,50 @@ public class HamletParser {
|
36
|
41
|
return hamletData;
|
37
|
42
|
}
|
38
|
43
|
|
|
44
|
+ public boolean findHoratio(String hamletDataTemp){
|
|
45
|
+ return hamletDataTemp.contains("Horatio");
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+// int hamletCount =regexChecker("[Hh][Oo][Ra][Aa][Tt][Ii][Oo]",hamletDataTemp);
|
|
49
|
+//
|
|
50
|
+// if(hamletCount>0){
|
|
51
|
+// return true;
|
|
52
|
+// }
|
|
53
|
+// return false;
|
|
54
|
+ }
|
|
55
|
+ public boolean findHamlet(String hamletDataTemp){
|
|
56
|
+ return hamletDataTemp.contains("Horatio");
|
|
57
|
+ }
|
|
58
|
+ public String changeHoratioToTariq(String hamletDataTemp){
|
|
59
|
+
|
|
60
|
+ Pattern replaceHoratio1 = Pattern.compile("[H|h][O|o][R|r][A|a][T|t][I|i][O|o]");
|
|
61
|
+ Matcher regexMatcher1 = replaceHoratio1.matcher(hamletDataTemp);
|
|
62
|
+ String replaced1 = regexMatcher1.replaceAll("Tariq");
|
|
63
|
+
|
|
64
|
+ return replaced1;
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ public String changeHamletToLeon(String hamletDataTemp){
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+ Pattern replaceHamlet1 = Pattern.compile("[H|h][A|a][M|m][L|l][E|e][T|t]");
|
|
71
|
+ Matcher regexMatcher1 = replaceHamlet1.matcher(hamletDataTemp);
|
|
72
|
+ String replaced1 = regexMatcher1.replaceAll("Leon");
|
|
73
|
+
|
|
74
|
+ return replaced1;
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ public int regexChecker(String input, String hamletDataTemp){
|
|
78
|
+
|
|
79
|
+ Pattern checkRegex = Pattern.compile(input);
|
|
80
|
+ Matcher regexMatcher = checkRegex.matcher(hamletDataTemp);
|
|
81
|
+
|
|
82
|
+ int count = 0;
|
|
83
|
+ while(regexMatcher.find()){
|
|
84
|
+ count++;
|
|
85
|
+ }
|
|
86
|
+ return count;
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+
|
39
|
90
|
}
|