Remove noise and common typographic issues from Deutsche Bahn (DB, german railways) and VBB (Berlin-Brandenburg transportation authority) station names, returned e.g. by the db-hafas and vbb-hafas module. For a list of changes that are applied to names, see the rules section.
npm install db-clean-station-name
const cleanStationName =const noisy = 'S+U Berlin Yorckstr. S2 U7 (S+U)'const cleaned =console // 'Berlin Yorckstraße'
The module applies a specific set of rules, which were test-run against a dataset of ≈250,000 station names. The matches column in the following table specifies how many of those station names a rule could be applied to at least once. Samples for each rule were checked manually for QA.
|Fix typographically incorrect apostrophes||
|Replace non-round braces||
|Fix whitespace for braces||
|Fix whitespace for punctuation and slashes||
|Replace generic abbreviations: Abzw., b., Ri.||
|Replace most common location abbreviations: Thür, Württ, Meckl, … Note that this rule will probably be replaced by a more generic location-parsing rule at some point||
|Replace Str. with Straße||
|Remove defined set of line and product names: U1, (U), (Bus), (S 1), S+U, …||
There are some additional rules which aren't listed here, but those only affect a handful of stations or fix the result of other rules (e.g. removing duplicate whitespace).
Removing location names
This module also offers a method to attempt to remove location names from station names, e.g. the
Amrumer Straße, Berlin or
Köln Messe/Deutz. The module also has a blacklist for particles for which the location is never removed even if it was detected correctly, e.g. for
Frankfurt Süd, where the remaining part wouldn't really make sense on its own.
const cleanStationNameWithLocation =// you must provide a station name as well as a geolocation for that stationconst cleaned =const result =full: 'Berlin Hauptbahnhof' // normal output of db-clean-station-nameshort: 'Hauptbahnhof' // will be `null` if no locations were detectedmatchedLocationIds: '11000000' // some id(s) corresponding to locations that were detected, you can use those to check e.g. if two stations are in the same city. will be empty of no location(s) were detected. note that for cases like `Frankfurt Süd`, where `short` will be null because nothing could be removed because of some blacklisted name, the list of matched location ids can still contain values
If you found a bug or want to propose a feature, feel free to visit the issues page.