forked from chunlaw/HKAddressParser
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ffc044
commit d4541f7
Showing
5 changed files
with
476 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const Promise = require('bluebird'); | ||
const request = Promise.promisifyAll(require('request')); | ||
|
||
const addressParser = require('../web/src/lib/address-parser'); | ||
|
||
if (process.argv.length < 2) { | ||
process.exit(1); | ||
} | ||
|
||
const address = process.argv[2]; | ||
const n = 100; | ||
const URL = 'https://www.als.ogcio.gov.hk/lookup'; | ||
|
||
|
||
request.getAsync(URL, { | ||
headers: { | ||
Accept: 'application/json' | ||
}, | ||
qs: { | ||
q: address, | ||
n | ||
}, | ||
json: {} | ||
}).then(res => { | ||
return addressParser.searchResult(address, res.body); | ||
}).then( results => { | ||
results.forEach((result, index) => { | ||
if (index < 5) { | ||
console.log("================================================") | ||
console.log(JSON.stringify(result.chi, null ,2)); | ||
console.log(`score: ${result.score}`); | ||
for (const match of result.matches) { | ||
console.log(` -----------------------`); | ||
console.log(` key: ${match.matchedKey}`); | ||
console.log(` matched: ${match.matchedWords}`); | ||
console.log(` score: ${addressParser.calculateScoreFromMatches([match])}`); | ||
|
||
} | ||
console.log("================================================") | ||
console.log("") | ||
console.log("") | ||
} | ||
|
||
}) | ||
|
||
|
||
}).catch(error => { | ||
console.log(error.stack); | ||
}) | ||
|
Oops, something went wrong.