Skip to content

Commit

Permalink
v1.0.0. Added sample web app.
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sagara committed Dec 10, 2021
1 parent 69a2a62 commit 20583ef
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ python -m unittest
Please use the dictionary coverter
[jageocoder-converter](https://github.com/t-sagara/jageocoder-converter).

## Sample Web Application

A sample of a simple web app using Flask is available under
`flask-demo`.

Perform the following steps. Then, access port 5000.

```
cd flask-demo
pip install flask
bash run.sh
```

## ToDos

- Supporting address changes
Expand Down
12 changes: 12 additions & 0 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ python -m unittest

[jageocoder-converter](https://github.com/t-sagara/jageocoder-converter).

## サンプルウェブアプリ

Flask を利用したシンプルなウェブアプリのサンプルが
`flask-demo` の下にあります。

次の手順を実行し、ポート 5000 にアクセスしてください。

```
cd flask-demo
pip install flask
bash run.sh
```

## ToDo

Expand Down
22 changes: 22 additions & 0 deletions flask-demo/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from flask import Flask, request, render_template

import jageocoder
jageocoder.init()

app = Flask(__name__)


@app.route("/")
def index():
return render_template('index.html', q='', result=None)


@app.route("/search", methods=['POST', 'GET'])
def search():
query = request.args.get('q') or None
if query:
results = jageocoder.searchNode(query, best_only=True)
else:
results = None

return render_template('index.html', q=query, results=results)
4 changes: 4 additions & 0 deletions flask-demo/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!bash
export FLASK_APP=app
export FLASK_ENV=development
flask run --host=0.0.0.0
74 changes: 74 additions & 0 deletions flask-demo/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>Jageocoder Flask Demonstration</title>
</head>
<body>
<h1>Jageocoder のデモンストレーション</h1>
<form action="/search" method="GET">
検索したい住所を入力:<br />
<input size="80" value="{{ q }}" name="q" />
<input type="submit" value="検索" />
</form>

{% if results %}
<p>結果一覧 <a href="/">住所の例に戻る</a></p>
<ul id="results">
{% for result in results %}
<li class="node">
{% for name in result.node.get_fullname() %}
{{ name }}<nbsp;>
{% endfor %}
<ul>
<li>一致した文字列: {{ result.matched }}</li>
<li>座標:
経度 {{ result.node.x }}, 緯度 {{ result.node.y }}
<a href="{{ result.node.get_gsimap_link() }}" target="_gsimap">地理院地図</a></li>
</ul>
</li>
{% endfor %}
</ul>
{% else %}
<p>住所の例</p>
<ul>
<li><dl>
<dt>多摩市落合1-15多摩センタートーセイビル</dt>
<dd>「番」「番地」をハイフンや「の」などで省略しても解析できます。ビル・マンション名には対応していません。</dd>
</dl></li>
<li><dl>
<dt>茨城県竜ヶ崎市字米町3903</dt>
<dd>「竜」と「龍」などの異体字に対応しています。</dd>
</dl></li>
<li><dl>
<dt>中央区中央1</dt>
<dd>都道府県名や市区町村名の省略に対応しています。候補が複数見つかった場合は複数の結果を返します。</dd>
</dl></li>
<li><dl>
<dt>東京都西多摩郡瑞穂町箱根ケ崎2335番地</dt>
<dd>大字名の「大字」の省略に対応しています。</dd>
</dl></li>
<li><dl>
<dt>埼玉県大里郡寄居町大字鷹巣</dt>
<dd>「鷹ノ巣」の「ノ」などの省略に対応しています。</dd>
</dl></li>
<li><dl>
<dt>札幌市中央区北3西1-7</dt>
<dd>札幌市の「北三条西一丁目」を「北3西1」のように省略する表記に対応しています。</dd>
</dl></li>
<li><dl>
<dt>京都市上京区下立売通新町西入薮ノ内町</dt>
<dd>京都市の通り名には部分的に対応していて、通り名部分をスキップして町名から処理します。</dd>
</dl></li>
<li><dl>
<dt>長野県千曲市礒部字下河原1137</dt>
<dd>辞書にない字名が含まれていても、対応する地番を検索します。</dd>
</dl></li>
<li><dl>
<dt>福島県いわき市平上高久塚田97乙</dt>
<dd>地番の脱落地に対応しています。</dd>
</dl></li>
</ul>
{% endif %}
</body>
</html>
2 changes: 1 addition & 1 deletion jageocoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
>>> jageocoder.searchNode('<Japanese-address>')
"""

__version__ = '1.0.0rc2' # The package version
__version__ = '1.0.0' # The package version
__dictionary_version__ = '20211209' # Compatible dictionary version
__author__ = 'Takeshi Sagara <[email protected]>'

Expand Down
10 changes: 10 additions & 0 deletions jageocoder/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,13 @@ def _local_authority_code(self, orig_code: str) -> str:
checkdigit = str(11 - remainder)[-1]

return orig_code + checkdigit

def get_gsimap_link(self) -> str:
"""
Returns the URL for GSI Map with parameters.
ex. https://maps.gsi.go.jp/#13/35.713556/139.750385/
"""
url = 'https://maps.gsi.go.jp/#{level:d}/{lat:.6f}/{lon:.6f}/'
return url.format(
level=9 + self.level,
lat=self.y, lon=self.x)
8 changes: 8 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ def test_select_best(self):
match="佐賀県鹿島市納富分字藤津甲",
fullname=["佐賀県", "鹿島市", "大字納富分", "藤津甲"])

def test_datsurakuchi(self):
"""
"""
self._check(
query="福島県いわき市平上高久塚田97乙",
fullname=["福島県", "いわき市", "平上高久",
"塚田", "97番", "乙地"])


if __name__ == "__main__":
unittest.main()

0 comments on commit 20583ef

Please sign in to comment.