Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
41eb362
wip
daohoangson Oct 22, 2019
4366342
Update coding convention
daohoangson Oct 22, 2019
960a4a8
Adjust test expectation
daohoangson Oct 22, 2019
64a4ced
Keep track of unit level
daohoangson Oct 22, 2019
6fe5c94
Perform deep search to find all possible matches
daohoangson Oct 22, 2019
d79b3c4
Re-organize
daohoangson Oct 23, 2019
8c5e71d
Remove phone number before parsing
daohoangson Oct 23, 2019
4d01619
Fix expected match verification
daohoangson Oct 23, 2019
c0e2e09
Update coding convention
daohoangson Oct 23, 2019
425376c
Do not resolveSkipping too far
daohoangson Oct 23, 2019
af72d30
Split code into smaller files
daohoangson Oct 23, 2019
1272d78
Refactor vietnamese.ts
daohoangson Oct 23, 2019
f1f5205
`npm remove unidecode`
daohoangson Oct 23, 2019
4550160
Refactor
daohoangson Oct 23, 2019
c601d1e
wip
daohoangson Oct 24, 2019
93ab2cf
wip
daohoangson Oct 24, 2019
49e7cad
Refactor parser alternate resolves
daohoangson Oct 24, 2019
8cfea46
wip
daohoangson Oct 24, 2019
49276b9
Special case: one parent has more than one entity
daohoangson Oct 24, 2019
ac1f2d2
wip
daohoangson Oct 24, 2019
276b5b3
Fix bugs
daohoangson Oct 24, 2019
246cb6a
wip
daohoangson Oct 24, 2019
06d9001
Adjust bulk output
daohoangson Oct 24, 2019
0ba3983
Merge branch 'master' of github.com:daohoangson/dvhcvn into demo/parser
daohoangson Oct 25, 2019
3ba0734
Use historical tree for matching
daohoangson Oct 26, 2019
75a4c40
Create `bin/cli.ts`
daohoangson Oct 26, 2019
cf03f0c
Add now.sh support
daohoangson Oct 26, 2019
e09e0df
Add `now-build` to populate `tree.json` file
daohoangson Oct 26, 2019
20fc2ee
Add demo/parser.html page
daohoangson Oct 26, 2019
3e24738
Refactor parser.html
daohoangson Oct 26, 2019
2669934
Fix response json handling
daohoangson Oct 26, 2019
f1dbdd6
Fix typo
daohoangson Oct 26, 2019
a4a9390
Add support for `--json` option in cli.ts
daohoangson Oct 27, 2019
563887d
Add logic to handle entity status (moved / deleted)
daohoangson Oct 28, 2019
9fb98b7
wip
daohoangson Oct 28, 2019
6d665e1
wip
daohoangson Oct 28, 2019
ddf9dd3
Merge remote-tracking branch 'origin/master' into demo/parser
daohoangson Feb 3, 2020
36a43a6
Merge remote-tracking branch 'origin/master' into demo/parser
daohoangson May 10, 2020
39404de
Re-run historical data downloader
daohoangson May 11, 2020
69a004a
Add support for common typos:
daohoangson May 11, 2020
1fd0e5f
Add support for roman numbers
daohoangson May 11, 2020
574ab12
Simplify entity pattern logic
daohoangson May 11, 2020
c71c0d2
Fix tree.json download
daohoangson May 11, 2020
5ebfd45
Fix typo match without accent
daohoangson May 11, 2020
84008f7
Add typo: ch / tr
daohoangson May 12, 2020
cc754f0
Use fuzzy match instead of manually managing typos
daohoangson May 13, 2020
36ec8c5
Include entity type in fuzzy match
daohoangson May 13, 2020
9e711df
Replace deleted / moved entity with identical name
daohoangson May 13, 2020
5b06a97
Include same level types for pattern matching
daohoangson May 14, 2020
8103e35
Give bonus for up to date type in matches
daohoangson May 14, 2020
5a21051
Also perform fuzzy match if name is lengthy
daohoangson May 15, 2020
e1a5a3e
Allow fuzzy match to contain dash (`-`)
daohoangson May 15, 2020
eb4fab7
Allow fuzzy match to contain single quote (`'`)
daohoangson May 15, 2020
b975f4b
Move name2 match above initial match
daohoangson May 15, 2020
06d5359
Fix missing name in `tree.json` generation
daohoangson May 16, 2020
5e05a35
Merge remote-tracking branch 'origin/master' into demo/parser
daohoangson Sep 6, 2020
7edf5d5
Update README with demo links
daohoangson Sep 6, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ Ví dụ:

- Dart [pub.dev](https://pub.dev/packages/dvhcvn)

## Demo

- [geolocation](https://dvhcvn.daohoangson.now.sh/demo/geolocation.html): xác định dvhc từ kinh độ, vĩ độ
- [map](https://dvhcvn.daohoangson.now.sh/demo/map.html): hiển thị dvhc trên bản đồ
- [parser](https://dvhcvn.daohoangson.now.sh/demo/parser.html): xác định dvhc từ địa chỉ (xem parser API bên dưới)
- [parser API](https://dvhcvn.daohoangson.now.sh/demo/parser/api):
- Cách 1: `curl https://dvhcvn.daohoangson.now.sh/demo/parser/api -d input=hanoi` -> chỉ trả về tên các dvhc "**Thành phố Hà Nội**"
- Cách 2: `curl https://dvhcvn.daohoangson.now.sh/demo/parser/api -H 'Content-Type: text/plain' -d hanoi` -> trả về thông tin chi tiết
- Ví dụ: `curl https://dvhcvn.daohoangson.now.sh/demo/parser/api -H 'Content-Type: text/plain' -d 'trung tu, dong da, ha noi'` trả về `[{"id":"00226","name":"Trung Tự","type":"Phường"},{"id":"006","name":"Đống Đa","type":"Quận"},{"id":"01","name":"Hà Nội","type":"Thành phố"}]`

## Nhưng... tại sao?!

Bộ dữ liệu này được tạo ra vì các dự án tương tự trên mạng Internet cung cấp thông tin không đầy đủ hoặc không được cập nhật thường xuyên.
Expand Down
51 changes: 51 additions & 0 deletions demo/parser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<script src="/demo/demo.js"></script>
</head>
<body>
<form action="/demo/parser/api" method="POST">
<label>
Input
<input id="input" type="address" name="input" />
</label>

<pre id="output"></pre>

<input type="submit" value="Parse" />
</form>

<script>
const input = document.getElementById("input");
const output = document.getElementById("output");

const parse = value =>
fetch("/demo/parser/api", {
method: "POST",
headers: { "Content-Type": "text/plain" },
body: value
})
.then(r => r.json())
.then(
parsed => {
console.log("parse(%s)", value, parsed);
if (value !== input.value) return;

output.innerHTML = JSON.stringify(parsed, null, " ");
},
reason => {
console.log("parse(%s)", value, reason);
if (value !== input.value) return;

output.innerHTML = `${reason}`;
}
);

let timeout = null;
input.onkeyup = e => {
clearTimeout(timeout);
timeout = setTimeout(() => parse(input.value), 200);
};
</script>
</body>
</html>
12 changes: 12 additions & 0 deletions demo/parser/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
parser: "@typescript-eslint/parser",
extends: [
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
parserOptions: {
ecmaVersion: 2018,
sourceType: "module"
}
};
1 change: 1 addition & 0 deletions demo/parser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
18 changes: 18 additions & 0 deletions demo/parser/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NowRequest, NowResponse } from "@now/node";

import Parser from "../src/parser";

const parser = new Parser();

export default function (req: NowRequest, res: NowResponse) {
if (typeof req.body === "string") {
return res.send(parser.parse(req.body));
}

if (req.body && typeof req.body.input === "string") {
const parsed = parser.parse(req.body.input);
return res.send(parsed.map(r => `${r.type} ${r.name}`).join(", "));
}

return res.status(400).send('No input found.');
}
15 changes: 15 additions & 0 deletions demo/parser/api/now-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -e
cd $( dirname $BASH_SOURCE[0] )

_historyDataPath=../../../history/data
_treeJsonPath=$_historyDataPath/tree.json

mkdir -p $_historyDataPath

if [ ! -f $_treeJsonPath ]; then
curl -Lo $_treeJsonPath https://github.com/daohoangson/dvhcvn-historical-data/raw/demo/parser/tree.json
fi

ls -ald $_treeJsonPath
43 changes: 43 additions & 0 deletions demo/parser/bin/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!npx ts-node

import readline from "readline";
import yargs from "yargs";

import Parser from "../src/parser";

const argv = yargs
.help()
.option("debug", {
boolean: true,
description: "Run with debug output"
})
.option("json", {
boolean: true,
description: "Json decode input before parsing"
})
.alias("h", "help").argv;

const { debug, json } = argv;
const parser = new Parser({ debug });

const parseInput = input => {
if (json) {
const decoded = JSON.parse(input);
if (decoded && typeof decoded.input === "string") {
input = decoded.input;
}
}

process.stdout.write(
JSON.stringify({ input, output: parser.parse(input) }) + "\n"
);
};

const inputs = argv._;
if (inputs.length > 0) {
inputs.forEach(parseInput);
process.exit(0);
}

const rl = readline.createInterface({ input: process.stdin });
rl.on("line", parseInput);
Loading