Skip to content

Commit

Permalink
Ignore some words probably not part of place names
Browse files Browse the repository at this point in the history
Refs #31
  • Loading branch information
thewilkybarkid committed Jul 11, 2024
1 parent fc0f070 commit 53fb87a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/lib/Iso3166.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const guessCountry: (location: string) => Option.Option<Alpha2Code> = flo
String.replaceAll(/\((.+?)\)/g, ', $1'),
String.replaceAll(/ [0-9]+/g, ' '),
String.replaceAll(/( and | - )/gi, ', '),
String.replaceAll(/(^| )(the|near) /gi, ''),
location => Array.prepend(Array.map(location.split(',').reverse(), String.trim), location),
Array.findFirst(location =>
Option.fromNullable(iso3166.getAlpha2Code(location, 'en')).pipe(
Expand Down
13 changes: 6 additions & 7 deletions test/Iso3166.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('guessCountry', () => {
['Czech Republic', 'CZ'],
['Czechia', 'CZ'],
['Düsseldorf', 'DE'],
['Fayetteville GA (near Atlanta)', 'US'],
['GHANA', 'GH'],
['London', 'GB'],
['London, Ontario', 'CA'],
Expand All @@ -22,6 +23,7 @@ describe('guessCountry', () => {
['Québec', 'CA'],
['Rio de Janeiro, Brazil.', 'BR'],
['Sunnyvale, California', 'US'],
['The UK', 'GB'],
['UK', 'GB'],
['U.K.', 'GB'],
['United Kingdom', 'GB'],
Expand All @@ -33,12 +35,9 @@ describe('guessCountry', () => {
expect(actual).toStrictEqual(Option.some(expected))
})

test.for(['Babol iran', 'Fayetteville GA (near Atlanta)', 'Mars', 'Southeast Asia', 'The UK', 'Yale university'])(
"doesn't guess %s",
input => {
const actual = _.guessCountry(input)
test.for(['Babol iran', 'Mars', 'Southeast Asia', 'Yale university'])("doesn't guess %s", input => {
const actual = _.guessCountry(input)

expect(actual).toStrictEqual(Option.none())
},
)
expect(actual).toStrictEqual(Option.none())
})
})

0 comments on commit 53fb87a

Please sign in to comment.