|
@@ -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.
|
|
@@ -24,7 +26,6 @@ public class HamletParser {
|
24
|
26
|
result.append(line).append("\n");
|
25
|
27
|
}
|
26
|
28
|
|
27
|
|
- scanner.close();
|
28
|
29
|
}catch(IOException e){
|
29
|
30
|
e.printStackTrace();
|
30
|
31
|
}
|
|
@@ -36,4 +37,51 @@ public class HamletParser {
|
36
|
37
|
return hamletData;
|
37
|
38
|
}
|
38
|
39
|
|
|
40
|
+ public String changeHamletToLeon(String test) {
|
|
41
|
+ Pattern pattern = Pattern.compile("\\w+(\\W)?");
|
|
42
|
+ Matcher matcher = pattern.matcher(test);
|
|
43
|
+
|
|
44
|
+ String str ="";
|
|
45
|
+
|
|
46
|
+ while(matcher.find()){
|
|
47
|
+ String word = matcher.group();
|
|
48
|
+ if(word.equals("Hamlet ")){
|
|
49
|
+ str+="Leon ";
|
|
50
|
+ }else{
|
|
51
|
+ str+=word;
|
|
52
|
+ }
|
|
53
|
+ }
|
|
54
|
+ return str;
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ public String changeHoratioToTariq(String test) {
|
|
58
|
+ Pattern pattern = Pattern.compile("\\w+(\\W)?");
|
|
59
|
+ Matcher matcher = pattern.matcher(test);
|
|
60
|
+
|
|
61
|
+ String str = "";
|
|
62
|
+
|
|
63
|
+ while(matcher.find()){
|
|
64
|
+ String word = matcher.group();
|
|
65
|
+ if(word.equals("Horatio ")){
|
|
66
|
+ str+="Tariq ";
|
|
67
|
+ }else{
|
|
68
|
+ str+=word;
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+ return str;
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ public Boolean findHoratio(String name) {
|
|
75
|
+ Pattern pattern =Pattern.compile(name);
|
|
76
|
+ Matcher matcher = pattern.matcher(name);
|
|
77
|
+
|
|
78
|
+ return matcher.find();
|
|
79
|
+ }
|
|
80
|
+
|
|
81
|
+ public Boolean findHamlet(String name) {
|
|
82
|
+ Pattern pattern =Pattern.compile(name);
|
|
83
|
+ Matcher matcher = pattern.matcher(name);
|
|
84
|
+
|
|
85
|
+ return matcher.find();
|
|
86
|
+ }
|
39
|
87
|
}
|