Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sagara committed Dec 10, 2021
2 parents 6690254 + 20583ef commit 6c31cd7
Show file tree
Hide file tree
Showing 16 changed files with 1,113 additions and 425 deletions.
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>
18 changes: 13 additions & 5 deletions itaiji_dic/itaiji_src.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"が": "ケヶガ",
"っ": "ツッ",
"の": "ノ乃之",
"エ": "",
"エ": "ヱェ",
"亜": "",
"秋": "穐龝",
"悪": "",
Expand Down Expand Up @@ -37,6 +37,7 @@
"煙": "",
"艶": "",
"塩": "",
"園": "",
"奥": "",
"往": "",
"応": "",
Expand Down Expand Up @@ -102,6 +103,7 @@
"帰": "歸皈",
"気": "氣气",
"亀": "",
"磯": "",
"偽": "",
"戯": "",
"犠": "",
Expand Down Expand Up @@ -166,12 +168,13 @@
"轟": "",
"国": "國圀",
"嵯": "",
"左": "",
"済": "",
"砕": "",
"斎": "",
"剤": "",
"坂": "",
"崎": "嵜埼碕",
"崎": "嵜埼碕﨑",
"作": "",
"桜": "",
"冊": "",
Expand Down Expand Up @@ -202,6 +205,7 @@
"釈": "",
"呪": "",
"寿": "",
"州": "",
"収": "",
"讐": "",
"従": "從从",
Expand Down Expand Up @@ -261,7 +265,7 @@
"棲": "",
"声": "",
"静": "",
"斉": "斎齊",
"斉": "斎齋齊齊済齋齊斎斎薺濟斎斉薺齎濟齊齏霽",
"跡": "迹蹟",
"摂": "",
"窃": "",
Expand All @@ -271,7 +275,7 @@
"潜": "潛濳",
"線": "",
"繊": "纖纎",
"船": "",
"船": "舩舟",
"賎": "",
"践": "",
"銭": "",
Expand All @@ -295,6 +299,7 @@
"装": "",
"走": "",
"騒": "",
"桑": "",
"臓": "",
"蔵": "",
"属": "",
Expand Down Expand Up @@ -376,9 +381,11 @@
"悩": "",
"脳": "",
"覇": "",
"波": "",
"廃": "",
"拝": "",
"杯": "",
"稗": "",
"梅": "",
"売": "",
"蝿": "",
Expand All @@ -393,7 +400,7 @@
"秘": "",
"桧": "",
"氷": "",
"浜": "",
"浜": "濱濵",
"富": "",
"淵": "渕渊",
"払": "",
Expand Down Expand Up @@ -458,6 +465,7 @@
"溜": "",
"留": "",
"竜": "",
"柳": "",
"両": "",
"涼": "",
"猟": "",
Expand Down
4 changes: 2 additions & 2 deletions jageocoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
>>> jageocoder.searchNode('<Japanese-address>')
"""

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

__all__ = [
Expand Down
35 changes: 27 additions & 8 deletions jageocoder/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
from typing import Optional

Expand All @@ -10,19 +11,25 @@
Usage:
{p} -h
{p} get-db-dir
{p} download-dictionary [--gaiku] [<url>]
{p} install-dictionary [--gaiku] [--db-dir=<dir>] [<url_or_path>]
{p} uninstall-dictionary [--db-dir=<dir>]
{p} upgrade-dictionary [--db-dir=<dir>]
{p} search [-d] <address>
{p} get-db-dir [-d]
{p} download-dictionary [-d] [--gaiku] [<url>]
{p} install-dictionary [-d] [--gaiku] [--db-dir=<dir>] [<url_or_path>]
{p} uninstall-dictionary [-d] [--db-dir=<dir>]
{p} upgrade-dictionary [-d] [--db-dir=<dir>]
Options:
-h --help Show this help.
-d --debug Show debug messages.
--gaiku Use block-level (default: building-level)
--db-dir=<dir> Specify dictionary directory.
Examples:
- Search address
python -m {p} search 多摩市落合1-15
- Show dictionary directory
python -m {p} get-db-dir
Expand Down Expand Up @@ -76,13 +83,25 @@ def get_download_url(level: Optional[str] = None,
if __name__ == '__main__':
args = docopt(HELP)

if args['--debug']:
log_level = logging.DEBUG
else:
log_level = logging.INFO

if args['get-db-dir']:
print(jageocoder.get_db_dir(mode='r'))
exit(0)

logging.basicConfig(format='%(levelname)s:%(message)s',
level=logging.INFO)
if args['download-dictionary']:
logging.basicConfig(format='%(levelname)s:%(name)s:%(lineno)s:%(message)s',
level=log_level)

if args['search']:
jageocoder.init(db_dir=args['--db-dir'], mode='r')
print(json.dumps(
jageocoder.search(args['<address>']),
ensure_ascii=False))

elif args['download-dictionary']:
level = 'gaiku' if args['--gaiku'] else 'jusho'
url = args['<url>'] or get_download_url(level)
try:
Expand Down
Loading

0 comments on commit 6c31cd7

Please sign in to comment.