|
@@ -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.
|
|
@@ -13,6 +15,54 @@ public class HamletParser {
|
13
|
15
|
this.hamletData = loadFile();
|
14
|
16
|
}
|
15
|
17
|
|
|
18
|
+ public static String findHamlet(String book) {
|
|
19
|
+ Pattern p = Pattern.compile("Hamlet");
|
|
20
|
+ Matcher m = p.matcher(book);
|
|
21
|
+
|
|
22
|
+ String str = null;
|
|
23
|
+ if (m.find()){
|
|
24
|
+ str = m.group();
|
|
25
|
+
|
|
26
|
+ }else{
|
|
27
|
+ return null;
|
|
28
|
+ }
|
|
29
|
+ return str;
|
|
30
|
+
|
|
31
|
+ }
|
|
32
|
+
|
|
33
|
+ public static String findHoratio(String book) {
|
|
34
|
+
|
|
35
|
+ Pattern p = Pattern.compile("[HoratioHORATIO]");
|
|
36
|
+ Matcher m = p.matcher(book);
|
|
37
|
+
|
|
38
|
+ String str;
|
|
39
|
+
|
|
40
|
+ if(m.find()){
|
|
41
|
+ str = m.group();
|
|
42
|
+ } else {
|
|
43
|
+ return null;
|
|
44
|
+ }
|
|
45
|
+ return str;
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ public static String changeToLeon(String book) {
|
|
49
|
+ Pattern p = Pattern.compile(book);
|
|
50
|
+ Matcher m = p.matcher(book.toLowerCase());
|
|
51
|
+
|
|
52
|
+ book = m.replaceAll("leon");
|
|
53
|
+
|
|
54
|
+ return book;
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ public static String changeToTariq(String book) {
|
|
58
|
+ Pattern p = Pattern.compile(book);
|
|
59
|
+ Matcher m = p.matcher(book.toLowerCase());
|
|
60
|
+
|
|
61
|
+ book = m.replaceAll("tariq");
|
|
62
|
+
|
|
63
|
+ return book;
|
|
64
|
+ }
|
|
65
|
+
|
16
|
66
|
private String loadFile(){
|
17
|
67
|
ClassLoader classLoader = getClass().getClassLoader();
|
18
|
68
|
File file = new File(classLoader.getResource("hamlet.txt").getFile());
|