Skip to content

Latest commit

 

History

History
84 lines (67 loc) · 3.65 KB

File metadata and controls

84 lines (67 loc) · 3.65 KB

Exercise 10

Part A

Write a class PatternExamplesImp that implements the interface org.pg4200.ex10.PatternExamples.

Implement a test class PatternExamplesImpTest that extends org.pg4200.ex10.PatternExamplesTestTemplate. If your implementation of PatternExamplesImp is correct, then all tests should pass.

Part B

Study the source code of TextSearchKMP. Once you think you fully understand it, write its implementation on paper (e.g., using a pen), without looking at the source code. Once done, compare what you wrote with the actual implementation.

Part C

Implement a class TextSearchKMPCached that extends TextSearchKMP. You need to override the method findFirst(String text, String target) to be more efficient. Instead of recomputing the needed data structures for each target input, those should be internally "cached", e.g., in a map. This means that each single token would be computed only once. If findFirst is called a second time with the same target input (but possibly different text), then the computation would be speeded up by re-using the data structures from the cache.

Implement a test class TextSearchKMPCachedTest that extends TextSearchTestTemplate. If your implementation of TextSearchKMPCached is "functionally" correct, then all tests should pass.

Part D

Write a regular expression that matches an exercise definition for this exam. An exercise in this exam starts with the following 2 lines:

  • The first line contains “Exercise ”, where is the number of the exercise.
    • The second line contains the name and type of file you are expected to deliver. E.g. Ex for name and .java, .txt as file types. You do not need to check that the numbers match between the file and the exercise, but both instances should be numeric only. Examples. Your expression Should match:

      • “”” Exercise 5:
        File: Ex05.txt “””
      • “”” Exercise 3:
        File: Ex03.java “””
      • “”” Exercise 13:
        File: Ex13.java“””
    • Should not match:

    • “”” Exercise no5:
      File: Ex05.txt“”” – the exercise number is not numeric only

    • “”” Exercise 5: File: Ex05.txt“”” – they are not on separate lines

    • “”” Exercise 5:
      File: Ex05.pdf “”” – not of a supported type.

    • “”” Exercise 5:
      File: Ex05 “”” – no file type

    • “”” Exercise 5:
      File: Ex_something05.txt “”” – file name does not match.

Part E

Write a regular expression that matches all questions asked by user @Bogdan, about the course. For example, this could be a filter on mattermost that allows someone to quickly see all the questions asked by a particular user. In this case, you can assume that each sentence starts with the name of the user that has typed it followed by a colon ( ‘:’ ), and that there is only one sentence per line. Examples: Should match:

  • “@Bogdan: Has everyone completed all the exercises?”
  • “@Bogdan: Are there any additional questions?”
  • “@Bogdan: Where can I find the solutions for this exercise?”

Should not match:

  • “@Sven: Why do we need to do the exercises?” – different user asking the question
  • “@Bogdan: Exercises will be useful in understanding the topic better.” – not a question
  • “@Bogdan – advises that you do all the exercises” – different format than expected (i.e. missing ":")
  • “@Sven: Have you asked @Bogdan about this?” – different user asking the question

Solutions

Solutions to this exercise can be found in the solutions module, under the org.pg4200.sol10 package.