Navya Sanal 6 years ago
parent
commit
ae0bc90f64
4 changed files with 27 additions and 10774 deletions
  1. 19
    10
      src/main/java/HamletParser.java
  2. 0
    5382
      src/main/resources/hamlet.txt
  3. 8
    0
      src/test/java/HamletParserTest.java
  4. 0
    5382
      target/classes/hamlet.txt

+ 19
- 10
src/main/java/HamletParser.java View File

@@ -28,13 +28,22 @@ public class HamletParser {
28 28
         try
29 29
         {
30 30
             Scanner scanner = new Scanner(file);
31
+            Pattern p = Pattern.compile(("Hamlet"));
32
+            Pattern p2 = Pattern.compile("Horatio");
33
+
31 34
             while(scanner.hasNextLine()){
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;
35
+
36
+                String line = scanner.nextLine();
37
+                Matcher m = p.matcher(line);
38
+                String s  = m.replaceAll("Leon");
39
+
40
+                Matcher m1 = p.matcher(s);
41
+                s = m1.replaceAll("Tariq");
42
+
43
+                result.append(s);
44
+
37 45
             }
46
+
38 47
             scanner.close();
39 48
         }
40 49
         catch(IOException e)
@@ -54,17 +63,17 @@ public class HamletParser {
54 63
         Pattern p = Pattern.compile("hamlet", Pattern.CASE_INSENSITIVE);
55 64
         Matcher m = p.matcher(inputLine);
56 65
 
57
-        StringBuilder s = result.append(m.replaceAll("Leon"));
66
+        String  s = m.replaceAll("Leon");
58 67
         System.out.println(s);
59
-        return s.toString();
68
+        return s;
60 69
 
61 70
     }
62
-    public StringBuilder ChangeHoratioToTariq(String inputLine)
71
+    public String ChangeHoratioToTariq(String inputLine)
63 72
     {
64 73
         //String line ;
65
-        Pattern p = Pattern.compile("\\Horatio\\b", Pattern.CASE_INSENSITIVE);
74
+        Pattern p = Pattern.compile("Horatio", Pattern.CASE_INSENSITIVE);
66 75
         Matcher m = p.matcher(inputLine);
67
-        StringBuilder s = result.append(m.replaceAll("<h1>Tariq</h1>"));
76
+        String s = m.replaceAll("Tariq");
68 77
         return s;
69 78
 
70 79
     }

+ 0
- 5382
src/main/resources/hamlet.txt
File diff suppressed because it is too large
View File


+ 8
- 0
src/test/java/HamletParserTest.java View File

@@ -52,4 +52,12 @@ public class HamletParserTest {
52 52
         assertEquals(actual,expected);
53 53
 
54 54
     }
55
+    @Test
56
+    public void getHamletData()
57
+    {
58
+        String expected = "The Tragedy of Leon, Prince of Denmark";
59
+
60
+        String actual = hp.getHamletData();
61
+        Assert.assertEquals(expected,actual);
62
+    }
55 63
 }

+ 0
- 5382
target/classes/hamlet.txt
File diff suppressed because it is too large
View File