|
@@ -1,6 +1,10 @@
|
1
|
1
|
import java.io.File;
|
2
|
2
|
import java.io.IOException;
|
|
3
|
+import java.nio.file.Files;
|
|
4
|
+import java.nio.file.Paths;
|
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.
|
|
@@ -33,7 +37,61 @@ public class HamletParser {
|
33
|
37
|
}
|
34
|
38
|
|
35
|
39
|
public String getHamletData(){
|
|
40
|
+
|
36
|
41
|
return hamletData;
|
37
|
42
|
}
|
38
|
43
|
|
|
44
|
+ public void changeFromHamletToLeon() {
|
|
45
|
+
|
|
46
|
+ String patternString1 = ("HAMLET");
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+ System.out.println(Pattern.compile(patternString1,Pattern.
|
|
50
|
+ CASE_INSENSITIVE).matcher(hamletData).replaceAll("LEON"));
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+ }
|
|
54
|
+ public void changeFromHoratioToTariq(){
|
|
55
|
+
|
|
56
|
+ String patternString2 = ("HORATIO");
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+ System.out.println(Pattern.compile(patternString2,Pattern.
|
|
60
|
+ CASE_INSENSITIVE).matcher(hamletData).replaceAll("TARIQ"));
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+ public int findHamlet(){
|
|
67
|
+ String patternHam = ("HAMLET");
|
|
68
|
+ Pattern pattern = Pattern.compile(patternHam,Pattern.CASE_INSENSITIVE);
|
|
69
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
70
|
+ int counter = 0;
|
|
71
|
+
|
|
72
|
+ while (matcher.find()){
|
|
73
|
+ counter++;
|
|
74
|
+
|
|
75
|
+ }
|
|
76
|
+ System.out.println(counter);
|
|
77
|
+ return counter;
|
|
78
|
+ }
|
|
79
|
+ public int findHoratio(){
|
|
80
|
+ //Trying both methods out
|
|
81
|
+ String REGEX_FIND_WORD="(?i).*?\\b%s\\b.*?";
|
|
82
|
+
|
|
83
|
+ String patternHam = ("HORATIO");
|
|
84
|
+ String regex = String.format(REGEX_FIND_WORD, Pattern.quote(patternHam));
|
|
85
|
+ Pattern pattern = Pattern.compile(regex);
|
|
86
|
+ Matcher matcher = pattern.matcher(hamletData);
|
|
87
|
+ int counter = 0;
|
|
88
|
+
|
|
89
|
+ while (matcher.find()){
|
|
90
|
+ counter++;
|
|
91
|
+
|
|
92
|
+ }
|
|
93
|
+ System.out.println(counter);
|
|
94
|
+ return counter;
|
|
95
|
+ }
|
|
96
|
+
|
39
|
97
|
}
|