|
@@ -1,6 +1,10 @@
|
|
1
|
+import javax.sound.sampled.Line;
|
|
2
|
+import javax.xml.bind.Element;
|
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.
|
|
@@ -9,23 +13,32 @@ public class HamletParser {
|
9
|
13
|
|
10
|
14
|
private String hamletData;
|
11
|
15
|
|
12
|
|
- public HamletParser(){
|
|
16
|
+ StringBuilder result = new StringBuilder("");
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+ public HamletParser()
|
|
20
|
+ {
|
13
|
21
|
this.hamletData = loadFile();
|
14
|
22
|
}
|
15
|
23
|
|
16
|
24
|
private String loadFile(){
|
17
|
25
|
ClassLoader classLoader = getClass().getClassLoader();
|
18
|
26
|
File file = new File(classLoader.getResource("hamlet.txt").getFile());
|
19
|
|
- StringBuilder result = new StringBuilder("");
|
20
|
27
|
|
21
|
|
- try(Scanner scanner = new Scanner(file)){
|
|
28
|
+ try
|
|
29
|
+ {
|
|
30
|
+ Scanner scanner = new Scanner(file);
|
22
|
31
|
while(scanner.hasNextLine()){
|
23
|
|
- String line = scanner.nextLine();
|
24
|
|
- result.append(line).append("\n");
|
|
32
|
+ /*//String line = scanner.nextLine();
|
|
33
|
+ //String updated = line.replaceAll("Hamlet","Leon");
|
|
34
|
+ //line = updated.replaceAll("Horatio","Tariq");
|
|
35
|
+ //result.append(line).append("\n");*/
|
|
36
|
+ break;
|
25
|
37
|
}
|
26
|
|
-
|
27
|
38
|
scanner.close();
|
28
|
|
- }catch(IOException e){
|
|
39
|
+ }
|
|
40
|
+ catch(IOException e)
|
|
41
|
+ {
|
29
|
42
|
e.printStackTrace();
|
30
|
43
|
}
|
31
|
44
|
|
|
@@ -35,5 +48,43 @@ public class HamletParser {
|
35
|
48
|
public String getHamletData(){
|
36
|
49
|
return hamletData;
|
37
|
50
|
}
|
|
51
|
+ public String ChangeHamletToLeon(String inputLine)
|
|
52
|
+ {
|
|
53
|
+ //String line ;
|
|
54
|
+ Pattern p = Pattern.compile("hamlet", Pattern.CASE_INSENSITIVE);
|
|
55
|
+ Matcher m = p.matcher(inputLine);
|
|
56
|
+
|
|
57
|
+ StringBuilder s = result.append(m.replaceAll("Leon"));
|
|
58
|
+ System.out.println(s);
|
|
59
|
+ return s.toString();
|
|
60
|
+
|
|
61
|
+ }
|
|
62
|
+ public StringBuilder ChangeHoratioToTariq(String inputLine)
|
|
63
|
+ {
|
|
64
|
+ //String line ;
|
|
65
|
+ Pattern p = Pattern.compile("\\Horatio\\b", Pattern.CASE_INSENSITIVE);
|
|
66
|
+ Matcher m = p.matcher(inputLine);
|
|
67
|
+ StringBuilder s = result.append(m.replaceAll("<h1>Tariq</h1>"));
|
|
68
|
+ return s;
|
|
69
|
+
|
|
70
|
+ }
|
|
71
|
+ public boolean findHoratio(String inputLine)
|
|
72
|
+ {
|
|
73
|
+
|
|
74
|
+ Pattern p = Pattern.compile("Horatio",Pattern.CASE_INSENSITIVE);
|
|
75
|
+ Matcher m = p.matcher(inputLine);
|
|
76
|
+ return m.find();
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+ }
|
|
80
|
+ public boolean findHamlet(String inputLine)
|
|
81
|
+ {
|
|
82
|
+
|
|
83
|
+ Pattern p = Pattern.compile("Tariq",Pattern.CASE_INSENSITIVE);
|
|
84
|
+ Matcher m = p.matcher(inputLine);
|
|
85
|
+ return m.find();
|
|
86
|
+
|
|
87
|
+ }
|
|
88
|
+
|
38
|
89
|
|
39
|
90
|
}
|