◇ OpenCyber Academy
Technical · Chapter 8 · English

Chapter 8 — Names, codes and standards

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Chapter 8 — Names, codes and standards

Lesson map

Lesson 08 published. Map, example, EX029.

flowchart TD
  N0["Learning outcomes"]
  N1["8.1 Inconsistent stop names"]
  N2["Lab — Normalising synthetic bus stop names"]
  N3["8.2 Normalising"]
  N4["8.4 A standard list"]
  N0 --> N1 --> N2 --> N3 --> N4
  N4 --> EX["Worked example"]
  EX --> Q["Exercise EX029"]

Logical drawing

flowchart LR
  N0["Learning outcomes"]
  N1["8.1 Inconsistent stop names"]
  N2["Lab — Normalising synthetic bus stop names"]
  N3["8.2 Normalising"]
  N4["8.4 A standard list"]
  N0 --> N1 --> N2 --> N3 --> N4 --> Q["EX029"]
[Learning outcomes]
    |
    v
[8.1 Inconsistent stop names]
    |
    v
[Lab — Normalising synthetic bus stop names]
    |
    v
[8.2 Normalising]
    |
    v
[8.4 A standard list]
    |
    v
[Worked example] --> [Exercise EX029]

Learning outcomes

You will (1) spot inconsistent names; (2) normalise text with simple rules; (3) agree a standard list with an owner.

8.1 Inconsistent stop names

Passengers complain that the website shows different names for the same stop. Marta collects stop names from the timetable, the website and the complaints system and finds variations such as High St, High Street and high street with a trailing space. Each system was set up separately, and staff typed names in their own way. She explains that inconsistent names confuse passengers and split reports, because one stop appears as several in counts. Marta counts the variations for each stop in a short table.

Lab — Normalising synthetic bus stop names

"""Normalise synthetic bus stop names and count distinct stops before and after (stdlib only)."""
import re
raw = ["High St", "High Street", "high street ", "Station Rd", "Station Road", "STATION ROAD",
       "Market Sq", "Market Square", "Park Ave", "Park Avenue", "Church Lane", "Church Ln"]
abbr = {"st": "street", "rd": "road", "sq": "square", "ave": "avenue", "ln": "lane"}
def norm(s):
    w = re.sub(r"\s+", " ", s.strip().lower()).split(" ")
    return " ".join(abbr.get(x, x) for x in w)
print(f"names {len(raw)}; distinct raw {len(set(raw))}; distinct after normalising {len({norm(s) for s in raw})}")
print(sorted({norm(s) for s in raw}))

Run with python3 lab_stops.py. Verified output:

names 12; distinct raw 12; distinct after normalising 5
['church lane', 'high street', 'market square', 'park avenue', 'station road']

8.2 Normalising

The lab normalises twelve synthetic stop names. It removes extra spaces, converts to lowercase and expands common abbreviations such as st to street and rd to road. All twelve raw names are distinct as written, but after normalising only five distinct stops remain: church lane, high street, market square, park avenue and station road. Marta notes that simple rules can reveal how many real stops lie behind many different spellings. She runs the script on the full list of stop names from all three systems, and shares the results with Mr. Hughes.

8.3 Limits of rules

Marta warns that automatic rules can make mistakes. St can mean street or saint, as in St Mary's Church. She checks the normalised list with Mr. Hughes before using it. He confirms the five stops and adds that one stop near the church should keep the word saint. Marta adds an exception list to her script. She learns that normalising is a helpful first step, but a person who knows the data must check the result. The exception list is kept beside the script.

8.4 A standard list

Mr. Hughes becomes owner of an official stop list with a code for each stop, an official name and its location. All systems should use the code and official name. Marta helps update the website and complaints system from the list. Mr. Osei explains that a single owned list prevents names drifting apart again, and that new stops must be added to the list before they appear anywhere else. Marta checks the website a month later and finds that every stop now shows its official name, and passenger complaints about names stop.

Worked example

Marta finds stop name variations across systems, normalises twelve names to five stops, adds an exception for saint after checking with Mr. Hughes and helps adopt an owned official stop list.

Synthetic case. Names are synthetic; outputs come from lab_stops.py.

Errors and limits

Automatic normalising without review can merge different things.

Exercises

Continue studying — lesson 08 (chapter 08 of 18)

← Chapter 07 · Course chapter index · Chapter 09 →

Continue to the next authored lesson.