|
@@ -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.
|
|
@@ -18,22 +20,83 @@ public class HamletParser {
|
18
|
20
|
File file = new File(classLoader.getResource("hamlet.txt").getFile());
|
19
|
21
|
StringBuilder result = new StringBuilder("");
|
20
|
22
|
|
21
|
|
- try(Scanner scanner = new Scanner(file)){
|
22
|
|
- while(scanner.hasNextLine()){
|
|
23
|
+ try(Scanner scanner = new Scanner(file))
|
|
24
|
+ {
|
|
25
|
+ while(scanner.hasNextLine())
|
|
26
|
+ {
|
23
|
27
|
String line = scanner.nextLine();
|
24
|
28
|
result.append(line).append("\n");
|
|
29
|
+ //String horatioToTariq = changeHoratioToTariq(changeHamletToLeon(line));
|
|
30
|
+ //result= result.append(changeHoratioToTariq(changeHamletToLeon(line)));
|
|
31
|
+ //result.append("\n");
|
|
32
|
+ //System.out.println(result);
|
25
|
33
|
}
|
26
|
|
-
|
27
|
|
- scanner.close();
|
28
|
34
|
}catch(IOException e){
|
29
|
35
|
e.printStackTrace();
|
30
|
36
|
}
|
31
|
|
-
|
32
|
37
|
return result.toString();
|
33
|
38
|
}
|
|
39
|
+ public static int changeHamletToLeon(String line)
|
|
40
|
+ {
|
|
41
|
+ int count=0;
|
|
42
|
+ Pattern patternHamlet =Pattern. compile("\\bHamlet\\b",Pattern.CASE_INSENSITIVE);
|
|
43
|
+ Matcher m1=patternHamlet.matcher(line);
|
|
44
|
+ String str1=((Matcher) m1).replaceAll("Leon");
|
|
45
|
+
|
|
46
|
+ Matcher m11=patternHamlet.matcher(str1);
|
|
47
|
+ while(m11.find())
|
|
48
|
+ {
|
|
49
|
+ count++;
|
|
50
|
+ }
|
|
51
|
+ return count;
|
|
52
|
+ }
|
34
|
53
|
|
35
|
|
- public String getHamletData(){
|
|
54
|
+ public static int changeHoratioToTariq(String line) {
|
|
55
|
+ int count=0;
|
|
56
|
+ Pattern patternHoratio =Pattern.compile("\\bHoratio\\b",Pattern.CASE_INSENSITIVE);
|
|
57
|
+ Matcher m2=patternHoratio.matcher(line);
|
|
58
|
+ String str2=((Matcher) m2).replaceAll("Tariq");
|
|
59
|
+
|
|
60
|
+ Matcher m22=patternHoratio.matcher(str2);
|
|
61
|
+ while(m22.find())
|
|
62
|
+ {
|
|
63
|
+ count++;
|
|
64
|
+ }
|
|
65
|
+ return count;
|
|
66
|
+ }
|
|
67
|
+ public String getHamletData()
|
|
68
|
+ {
|
36
|
69
|
return hamletData;
|
37
|
70
|
}
|
38
|
71
|
|
|
72
|
+ public int FindHoratio()
|
|
73
|
+ {
|
|
74
|
+ int count=0;
|
|
75
|
+ Pattern patternHoratio =Pattern.compile("\\bHoratio\\b",Pattern.CASE_INSENSITIVE);
|
|
76
|
+ Matcher m2=patternHoratio.matcher(hamletData);
|
|
77
|
+
|
|
78
|
+ while(m2.find())
|
|
79
|
+ {
|
|
80
|
+ count++;
|
|
81
|
+ }
|
|
82
|
+ return count;
|
|
83
|
+ }
|
|
84
|
+ public int FindHamlet()
|
|
85
|
+ {
|
|
86
|
+ int count=0;
|
|
87
|
+ Pattern patternHamlet =Pattern.compile("\\bHamlet\\b",Pattern.CASE_INSENSITIVE);
|
|
88
|
+ Matcher m2=patternHamlet.matcher(hamletData);
|
|
89
|
+
|
|
90
|
+ while(m2.find())
|
|
91
|
+ {
|
|
92
|
+ count++;
|
|
93
|
+ }
|
|
94
|
+ return count;
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+ public static void main(String[] args) {
|
|
98
|
+ HamletParser hamletParser=new HamletParser();
|
|
99
|
+
|
|
100
|
+ }
|
|
101
|
+
|
39
|
102
|
}
|