THINK FIRST·CODE LATER

← All labs

A task-vocabulary checker

Problem

Write a checker that accepts only well-formed tasks. Standard input: a line columns: date district pm25 … (the data abstraction), then one task per line: ACTION TARGET ATTRIBUTE [ATTRIBUTE…].

Vocabulary — actions and their branch: discover, present, enjoy → analyze/consume; annotate, record, derive → analyze/produce; lookup, locate, browse, explore → search; identify, compare, summarize → query. Targets and their scope: trends, outliers, features → all data; distribution, extremes → one attribute; dependency, correlation, similarity → many attributes; topology, paths → network; shape → spatial.

For each task print OK <task> [<branch> | <scope>] (OK followed by 5 spaces) or REJECT <task>: followed by all problems joined with ; , in this order: unknown action, unknown target, unknown attribute(s), no attribute named, and (for many-attribute targets) fewer than two attributes. Messages: 'show' is not an action in the vocabulary, 'everything' is not a target in the vocabulary, unknown attribute(s): ozone, no attribute named, 'dependency' needs at least two attributes. Finish with 4 task(s) well formed.

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.

v3-1-data-1.txt

columns: date district pm25 temperature trips
discover outliers pm25
compare distribution pm25
show everything about pm25
identify correlation temperature pm25
locate extremes trips
summarize dependency trips
lookup trends ozone
What your program must print for v3-1-data-1.txt
OK     discover outliers pm25 [analyze/consume | all data]
OK     compare distribution pm25 [query | one attribute]
REJECT show everything about pm25: 'show' is not an action in the vocabulary; 'everything' is not a target in the vocabulary; unknown attribute(s): about
OK     identify correlation temperature pm25 [query | many attributes]
OK     locate extremes trips [search | one attribute]
REJECT summarize dependency trips: 'dependency' needs at least two attributes
REJECT lookup trends ozone: unknown attribute(s): ozone
4 task(s) well formed

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), in the folder that holds both files:

python my_lab.py < v3-1-data-1.txt

Windows PowerShell (the default terminal of VS Code on Windows) does not understand <:

Get-Content v3-1-data-1.txt | python my_lab.py

PyCharm: Run → Edit Configurations → tick Redirect input from and choose the file.

Jupyter: put this at the top of the cell that holds your program:

import sys
sys.stdin = open("v3-1-data-1.txt", encoding="utf-8")

Write it here, in Jupyter or in your IDE, then paste it. Run it on the sample input yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.