Skip to content

Commit

Permalink
Finish conversion to JS objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Feb 17, 2025
1 parent 87319fb commit 31e7318
Show file tree
Hide file tree
Showing 7 changed files with 432,508 additions and 852 deletions.
6 changes: 3 additions & 3 deletions classifier/WhosOnFirstClassifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ const normalize = require('../tokenization/normalizer')({ lowercase: true, remov
// note: these should be defined from most granular to least granular
const placetypes = {
'locality': {
files: ['name:*_x_preferred.txt'],
files: ['name:eng_x_preferred.txt', 'name:fra_x_preferred.txt'],
classifications: [AreaClassification, LocalityClassification]
},
'region': {
files: ['abrv:*_x_preferred.txt', 'name:*_x_preferred.txt'],
files: ['abrv:eng_x_preferred.txt', 'name:eng_x_preferred.txt'],
classifications: [AreaClassification, RegionClassification]
},
// 'dependency': {
// files: ['wof:shortcode.txt', 'name:eng_x_preferred.txt'],
// classifications: [AreaClassification, DependencyClassification]
// },
'country': {
files: ['name:*_x_preferred.txt', 'wof:country.txt', 'wof:country_alpha3.txt'],
files: ['name:eng_x_preferred.txt', 'wof:country.txt', 'wof:country_alpha3.txt'],
classifications: [AreaClassification, CountryClassification]
}
}
Expand Down
87,556 changes: 86,733 additions & 823 deletions resources/libpostal/_dictionaries.js

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions resources/libpostal/libpostal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ function load (index, langs, filename, options) {

// Load libpostal/dictionaries
langs.forEach(lang => {
let dict = libpostaldict[lang][key]
if (dict === undefined) { return }
dict.split('\n').forEach(row => {
row.split('|').forEach(add.bind(null, lang))
}, this)
let d = libpostaldict[lang][key]
if (d === undefined) { return }
d.forEach(entry => add(lang, entry))
}, this)

// Load pelias/dictionaries/libostal
Expand Down
7 changes: 5 additions & 2 deletions resources/libpostal/resources-download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ for d in dictionaries/*/; do
dname=$(basename "$d")
files=$(for f in "$d"*.txt; do
fname=$(basename "$f" .txt)
# Read the file and convert its content into a JSON string:
content=$(jq -R -s . "$f")
# Read the file and convert it to the format the library expects:
content=$(jq -c -R -s 'split("\n")
| map(select(length > 0))
| map(split("|"))
| flatten' "$f")
echo "\"$fname\": $content"
done | paste -sd, -)
echo "{\"$dname\": { $files }}"
Expand Down
Loading

0 comments on commit 31e7318

Please sign in to comment.