ooad1-4 Exercise 1: Candidates From the Bike Shop Text ========================================================= bikeshop.txt: Customers bring bikes to the shop for repair. A customer can own several bikes. Each repair job is for one bike and is done by one mechanic. A job lists the parts used and the hours worked. The shop charges for the parts and the labour, and gives the customer an invoice when the job is finished. A bike can have only one job in progress at a time. Mechanics are paid weekly. ex1.py (save beside bikeshop.txt): import collections, pathlib, re STOP = set("a an the of to in on at by for with and or is are be it its this that can has have each one when only time bring done job's weekly paid".split()) text = pathlib.Path("bikeshop.txt").read_text(encoding="utf8") counts = collections.Counter(w.lower() for w in re.findall(r"[A-Za-z]+", text) if w.lower() not in STOP and len(w) > 2) print("words by frequency (candidates only):") print(", ".join(f"{w} ({n})" for w, n in counts.most_common())) Output: words by frequency (candidates only): job (4), bikes (2), shop (2), repair (2), customer (2), bike (2), parts (2), customers (1), own (1), several (1), mechanic (1), lists (1), used (1), hours (1), worked (1), charges (1), labour (1), gives (1), invoice (1), finished (1), progress (1), mechanics (1) CLASSIFICATION concept Customer, Bike, RepairJob, Mechanic, Part, Invoice (and JobPart: "a job lists the parts used" hides a thing with its own fact, the quantity, found from the verb "lists", not from a noun) attribute hours (hoursWorked on a job), labour and charge amounts (totalPence on an Invoice), part price status progress ("in progress" / "finished"); "finished" is when the invoice is given rule "a bike can have only one job in progress at a time"; "charges for the parts and the labour" actor Mechanic is both: a concept if the shop records who did a job (it does: "done by one mechanic"), and an actor if the system has a mechanic login. Decide with the owner. noise shop (the scope), several, used, finished, lists, gives not in scope "Mechanics are paid weekly": a payroll concept the repair-job system does not need. It is in the text as a distractor; counting cannot tell. WHAT THE COUNT GOT WRONG OR MISSED - bike (2) and bikes (2), customer (1) and customers (1), mechanic (1) and mechanics (1), part and parts: plurals split the counts. - JobPart (the parts on a job) has no noun of its own in the text. It appears only when you ask "what is a job's list of parts made of?". - Invoice appears once, so it ranks no higher than "several". - "Job" is the most frequent word and is the central concept, but frequency alone cannot say that. WHY THIS WORKS AS AN ANSWER --------------------------- Counting orders the words; it does not classify them. Every decision above was a judgement about what the word refers to, and the most important concept (JobPart) came from reading a verb phrase, not from the frequencies.