THINK FIRST·CODE LATER

← All labs

Requirement linter with EARS detection

Problem

Write a linter for requirement sentences. Read lines until the end of input; each line is ID: text. For each requirement print its EARS pattern and its problems.

Pattern (case-insensitive, on the text after ID: ):

  • starts with when → EVENT
  • starts with while → STATE
  • starts with where → OPTIONAL
  • starts with if and contains then → UNWANTED
  • starts with if without then → UNWANTED? (incomplete)
  • otherwise → UBIQUITOUS

Problems (in this order):

  1. no shall in the text → no 'shall'
  2. each weak word from this list that appears (substring, list order): appropriate, user-friendly, fast, easy, efficient, as much as possible, etc, and/or, flexible → weak word: <w>
  3. the text contains the word it or they as a whole word (ignore punctuation) → pronoun: check who it refers to

Output: ID [PATTERN] OK or ID [PATTERN] problems: p1; p2; .... At the end: Checked n requirements, k with problems.

Input:

R1: When a post receives 3 reports from different students, the system shall hide the post.
R2: The app shall be fast and user-friendly.
R3: If login fails 5 times, the system shall lock it.

Output:

R1 [EVENT] OK
R2 [UBIQUITOUS] problems: weak word: user-friendly; weak word: fast
R3 [UNWANTED?] problems: pronoun: check who it refers to
Checked 3 requirements, 2 with problems

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

s4-1-data-1.txt

R1: When a post receives 3 reports from different students, the system shall hide the post.
R2: The app shall be fast and user-friendly.
R3: If login fails 5 times, the system shall lock it.
What your program must print for s4-1-data-1.txt
R1 [EVENT] OK
R2 [UBIQUITOUS] problems: weak word: user-friendly; weak word: fast
R3 [UNWANTED?] problems: pronoun: check who it refers to
Checked 3 requirements, 2 with problems

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < s4-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content s4-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.