Skip to content

Commit

Permalink
Merge pull request #13 from t-sagara/v2_dev
Browse files Browse the repository at this point in the history
Merge v2_dev
  • Loading branch information
t-sagara authored Jul 12, 2023
2 parents 019c2a2 + cb467e0 commit 0e6820e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 114 deletions.
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Install dictionary",
"type": "python",
"request": "launch",
"module": "jageocoder",
"args": [
"install-dictionary",
"jukyo_all_v20.zip",
"-y"
]
},
{
"name": "Python: Reverse test",
"type": "python",
Expand Down
116 changes: 40 additions & 76 deletions flask-demo/templates/aza.html
Original file line number Diff line number Diff line change
@@ -1,80 +1,44 @@
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width-device-width, initial-scale=1.0">
<title>Jageocoder Demonstration</title>
<style type="text/css">
body {
margin: 1em;
}
input#query {
width: 50%;
}
textarea#result_text {
width: 100%;
}
</style>
</head>
<body>
<h1>
<a href="https://github.com/t-sagara/jageocoder/blob/main/README_ja.md">Jageocoder</a>
のデモンストレーション</h1>
<form action="{{ url_for('search') }}" method="GET">
<input id="query" value="{{ q }}" name="q" placeholder="検索したい住所を入力" />
<input id="area" value="{{ area }}" name="area"
placeholder="検索対象(都道府県・市区町村)" />
<input type="submit" value="検索" /><br />
小字の省略:
<input type="radio" name="skip_aza" value="auto"
{% if skip_aza == 'auto' %}checked="checked"{% endif %}
/>自動判定&nbsp;
<input type="radio" name="skip_aza" value="on"
{% if skip_aza == 'on' %}checked="checked"{% endif %}
/>省略する&nbsp;
<input type="radio" name="skip_aza" value="off"
{% if skip_aza == 'off' %}checked="checked"{% endif %}
/>省略しない&nbsp;
</form>
{% extends 'base.html' %}

<p><a href="{{ url_for('index', q=q, skip_aza=skip_aza) }}">
住所の例に戻る</a></p>
{% block title %}ノード一覧 | Jageocoder{% endblock %}

<h2>アドレス・ベース・レジストリ マスター属性</h2>
{% block content %}
{% include "addressform.html" %}

{% if aza is none %}
(条件に該当するレコードが見つかりません)
{% else %}
<ul id="attributes">
<li>表記
<table>
<thead>
<tr>
<th>レベル</th><th>漢字</th><th>カナ</th><th>英字</th>
</tr>
</thead>
<tbody>
{% for name in names %}
<tr>
<td align="right">{{ name[0] }}</td>
<td>{{ name[1] }}</td>
<td>{{ name[2] }}</td>
<td>{{ name[3] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<li>字コード: <a href="{{ url_for('search_aza_id', aza_id=aza.code) }}">
{{ aza.code }}</a></li>
<li>町字区分コード: {{ aza.aza_class }}
(1:大字・町, 2:丁目, 3:小字)</li>
<li>住居表示フラグ: {{ aza.is_jukyo }}
(True: 住居表示, False: 非住居表示)</li>
<li>起番フラグ: {{ aza.start_count_type }}
(1:起番, 2:非起番, 0:登記情報に存在しない)</li>
<li>郵便番号: {{ aza.postcode }}</li>
</ul>
{% endif %}
<h1>アドレス・ベース・レジストリ マスター属性</h1>

</body>
</html>
{% if aza is none %}
(条件に該当するレコードが見つかりません)
{% else %}
<ul id="attributes">
<li>表記
<table>
<thead>
<tr>
<th>レベル</th><th>漢字</th><th>カナ</th><th>英字</th>
</tr>
</thead>
<tbody>
{% for name in names %}
<tr>
<td align="right">{{ name[0] }}</td>
<td>{{ name[1] }}</td>
<td>{{ name[2] }}</td>
<td>{{ name[3] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<li>字コード: <a href="{{ url_for('search_aza_id', aza_id=aza.code) }}">
{{ aza.code }}</a></li>
<li>町字区分コード: {{ aza.aza_class }}
(1:大字・町, 2:丁目, 3:小字)</li>
<li>住居表示フラグ: {{ aza.is_jukyo }}
(True: 住居表示, False: 非住居表示)</li>
<li>起番フラグ: {{ aza.start_count_type }}
(1:起番, 2:非起番, 0:登記情報に存在しない)</li>
<li>郵便番号: {{ aza.postcode }}</li>
</ul>
{% endif %}

{% endblock %}
5 changes: 2 additions & 3 deletions jageocoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
>>> jageocoder.searchNode('<Japanese-address>')
"""

__version__ = '2.0.2rc1' # The package version
__version__ = '2.0.2' # The package version
__dictionary_version__ = '20230405' # Compatible dictionary version
__author__ = 'Takeshi Sagara <[email protected]>'

Expand All @@ -34,7 +34,6 @@
'download_dictionary',
'install_dictionary',
'uninstall_dictionary',
'migrate_dictionary',
'create_trie_index',
'search',
'searchNode',
Expand All @@ -48,6 +47,6 @@
from jageocoder.module import init, free, is_initialized,\
get_db_dir, set_search_config, get_search_config,\
get_module_tree, download_dictionary, install_dictionary,\
uninstall_dictionary, migrate_dictionary, create_trie_index,\
uninstall_dictionary, create_trie_index,\
search, searchNode, reverse, version, dictionary_version,\
installed_dictionary_version, installed_dictionary_readme # noqa: F401
7 changes: 4 additions & 3 deletions jageocoder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{p} reverse [-d] [--level=<level>] [--db-dir=<dir>] <longitude> <latitude>
{p} get-db-dir [-d]
{p} download-dictionary [-d] <url>
{p} install-dictionary [-d] [--db-dir=<dir>] <path>
{p} install-dictionary [-d] [-y] [--db-dir=<dir>] <path>
{p} uninstall-dictionary [-d] [--db-dir=<dir>]
Options:
Expand Down Expand Up @@ -138,11 +138,12 @@ def main():
try:
jageocoder.install_dictionary(
path=path,
db_dir=args['--db-dir']
db_dir=args['--db-dir'],
skip_confirmation=(args['-y'] is True),
)
except JageocoderError:
logging.warning((
"Could not find the dictionary at '{}'.".format(path)
"辞書データファイルが '{}' にありません。".format(path)
))
exit(1)

Expand Down
33 changes: 8 additions & 25 deletions jageocoder/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def download_dictionary(url: str) -> None:

def install_dictionary(
path: os.PathLike,
db_dir: Optional[os.PathLike] = None) -> None:
db_dir: Optional[os.PathLike] = None,
skip_confirmation: bool = False) -> None:
"""
Install address-dictionary from the specified path.
Expand All @@ -193,6 +194,12 @@ def install_dictionary(
if db_dir is None:
db_dir = get_db_dir(mode='w')

if skip_confirmation is not True and (db_dir / 'address_node').exists():
# Dictionary had been installed.
r = input("他の辞書がインストール済みです。上書きしますか?(Y/n) ")
if r.lower()[0] != 'y':
return

if os.path.exists(path):
path = path
else:
Expand Down Expand Up @@ -235,30 +242,6 @@ def uninstall_dictionary(db_dir: Optional[os.PathLike] = None) -> None:
logger.info('Dictionary has been uninstalled.')


def migrate_dictionary(db_dir: Optional[os.PathLike] = None) -> None:
"""
Migrate address-dictionary.
Parameters
----------
db_dir: os.PathLike, optional
The directory where the database files has been installed.
If omitted, it will be determined by `get_db_dir()`.
"""
# Set default value
if db_dir is None:
db_dir = get_db_dir(mode='a')

# Update the name and trie index
init(db_dir=db_dir, mode='a')
global _tree
# logger.info('Updating name index')
# _tree.update_name_index()
logger.info('Updating TRIE index {}'.format(_tree.trie_path))
_tree.create_trie_index()
logger.info('The dictionary is successfully migrated.')


def installed_dictionary_version(db_dir: Optional[os.PathLike] = None) -> str:
"""
Get the installed dictionary version.
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "jageocoder"
version = "2.0.2rc1"
version = "2.0.2"
description = "A Japanese-address geocoder for Python."
authors = ["Takeshi Sagara <[email protected]>"]
repository = "https://github.com/t-sagara/jageocoder/"
Expand All @@ -27,7 +27,7 @@ docopt = "^0.6.2"
deprecated = "^1.2.13"
Werkzeug = ">=2.2.3"
pycapnp = "^1.3.0"
portabletab = ">=0.3.2"
portabletab = ">=0.3.3"
tqdm = "^4.00.0"
rtree = "^1.0.0"
geographiclib = "^2.0"
Expand Down

0 comments on commit 0e6820e

Please sign in to comment.