Skip to content

Commit 56e1558

Browse files
authored
Merge pull request #25 from t-sagara/v2_dev
Supporet Python 3.12.
2 parents 8fc4793 + 0a1ce20 commit 56e1558

File tree

8 files changed

+107
-26
lines changed

8 files changed

+107
-26
lines changed

.vscode/launch.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"configurations": [
77
{
88
"name": "Search noname oaza",
9-
"type": "python",
9+
"type": "debugpy",
1010
"request": "launch",
1111
"module": "jageocoder",
1212
"args": [
@@ -17,7 +17,7 @@
1717
},
1818
{
1919
"name": "Install dictionary",
20-
"type": "python",
20+
"type": "debugpy",
2121
"request": "launch",
2222
"module": "jageocoder",
2323
"args": [
@@ -28,7 +28,7 @@
2828
},
2929
{
3030
"name": "Search all results",
31-
"type": "python",
31+
"type": "debugpy",
3232
"request": "launch",
3333
"module": "jageocoder",
3434
"args": [
@@ -43,7 +43,7 @@
4343
},
4444
{
4545
"name": "Python: Reverse test",
46-
"type": "python",
46+
"type": "debugpy",
4747
"request": "launch",
4848
"module": "jageocoder",
4949
"args": [
@@ -57,7 +57,7 @@
5757
},
5858
{
5959
"name": "Python: Flask",
60-
"type": "python",
60+
"type": "debugpy",
6161
"request": "launch",
6262
"module": "flask",
6363
"env": {
@@ -74,7 +74,7 @@
7474
},
7575
{
7676
"name": "Search moved address",
77-
"type": "python",
77+
"type": "debugpy",
7878
"request": "launch",
7979
"module": "jageocoder",
8080
"args": [
@@ -91,7 +91,7 @@
9191
},
9292
{
9393
"name": "Python: Current File",
94-
"type": "python",
94+
"type": "debugpy",
9595
"request": "launch",
9696
"program": "${file}",
9797
"console": "integratedTerminal",

jageocoder/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
>>> jageocoder.searchNode('<Japanese-address>')
2020
"""
2121

22-
__version__ = '2.1.4' # The package version
22+
__version__ = '2.1.5.post1' # The package version
2323
__dictionary_version__ = '20230927' # Compatible dictionary version
2424
__author__ = 'Takeshi Sagara <[email protected]>'
2525

@@ -41,7 +41,7 @@
4141
'version',
4242
'dictionary_version',
4343
'installed_dictionary_version',
44-
'instaleld_dictionary_readme',
44+
'installed_dictionary_readme',
4545
]
4646

4747
from jageocoder.module import init, free, is_initialized, \

jageocoder/module.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,17 +397,43 @@ def searchNode(query: str) -> List[Result]:
397397
return _tree.searchNode(query)
398398

399399

400-
def reverse(x: float, y: float, level: Optional[int] = None) -> dict:
400+
def reverse(
401+
x: float,
402+
y: float,
403+
level: Optional[int] = None,
404+
as_dict: Optional[bool] = True
405+
) -> list:
401406
"""
402407
Reverse geocoding.
408+
409+
Parameters
410+
----------
411+
x: float
412+
Longitude of the point.
413+
y: float
414+
Latitude of the point.
415+
level: int, optional
416+
Target node level.
417+
as_dict: bool, default=True
418+
If True, returns candidates as dict objects.
419+
420+
Returns
421+
-------
422+
list
423+
424+
Notes
425+
-----
426+
- The result list contains up to 3 nodes.
427+
- Each element is a dict type with the following structure:
428+
{"candidate":AddressNode, "dist":float}
403429
"""
404430
if not is_initialized():
405431
raise JageocoderError("Not initialized. Call 'init()' first.")
406432
from jageocoder.rtree import Index
407433

408434
global _tree
409435
idx = Index(tree=_tree)
410-
return idx.nearest(x=x, y=y, level=level)
436+
return idx.nearest(x=x, y=y, level=level, as_dict=as_dict)
411437

412438

413439
def create_trie_index() -> None:

jageocoder/node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def get_name(self, alt: Optional[str] = ''):
201201
def dataset(self):
202202
"""
203203
Get dataset record.
204+
204205
"""
205206
return self.table.datasets.get(id=self.priority)
206207

@@ -395,6 +396,7 @@ def children(self) -> List[AddressNode]:
395396
-------
396397
List[AddressNode]
397398
The list of the child nodes.
399+
398400
"""
399401
return self.get_children()
400402

jageocoder/result.py

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,22 @@ class Result(object):
2424
It is used only for recursive search.
2525
"""
2626

27-
def __init__(self,
28-
node: Optional[AddressNode] = None,
29-
matched: str = '',
30-
nchars: int = 0):
27+
def __init__(
28+
self,
29+
node: Optional[AddressNode] = None,
30+
matched: str = '',
31+
nchars: int = 0
32+
):
3133
self.node = node
3234
self.matched = matched
3335
self.nchars = nchars
3436

35-
def set(self, node: AddressNode,
36-
matched: str, nchars: int = 0) -> 'Result':
37+
def set(
38+
self,
39+
node: AddressNode,
40+
matched: str,
41+
nchars: int = 0
42+
) -> 'Result':
3743
"""
3844
Set node and matched string.
3945
"""
@@ -65,9 +71,20 @@ def get_matched_string(self) -> str:
6571
return self.matched
6672

6773
def get_matched_nchars(self) -> int:
74+
"""
75+
Get the the number of matched characters.
76+
77+
Return
78+
------
79+
int
80+
Number of characters in the matched substring.
81+
"""
6882
return self.nchars
6983

70-
def __getitem__(self, pos) -> Union[AddressNode, str]:
84+
def __getitem__(
85+
self,
86+
pos
87+
) -> Union[AddressNode, str]:
7188
if pos == 0:
7289
return self.node
7390
elif pos == 1:
@@ -77,7 +94,11 @@ def __getitem__(self, pos) -> Union[AddressNode, str]:
7794

7895
raise IndexError()
7996

80-
def __setitem__(self, pos, val: Union[AddressNode, str]) -> None:
97+
def __setitem__(
98+
self,
99+
pos,
100+
val: Union[AddressNode, str]
101+
) -> None:
81102
from jageocoder.node import AddressNode
82103
if pos == 0 and isinstance(val, AddressNode):
83104
self.node = val
@@ -89,13 +110,41 @@ def __setitem__(self, pos, val: Union[AddressNode, str]) -> None:
89110
raise RuntimeError()
90111

91112
def as_dict(self) -> dict:
113+
"""
114+
Convert Result object to dict type for display.
115+
116+
Return
117+
------
118+
dict
119+
A dict object containing the following elements;
120+
121+
"node"
122+
AddressNode object converted to dict type.
123+
124+
"matched"
125+
The substring matching the query.
126+
"""
92127
return {
93128
"node": self.node.as_dict(),
94129
"matched": self.matched,
95-
# "nchars": self.nchars
96130
}
97131

98132
def as_geojson(self) -> dict:
133+
"""
134+
Convert Result to GeoJSON dict type for display.
135+
136+
Return
137+
------
138+
dict
139+
A GeoJSON dict object containing the following elements;
140+
141+
"type"
142+
Always "Feature".
143+
"geometry"
144+
A point type geometry containing latitude and longitude.
145+
"properties"
146+
Include in "matched" the substring that matched the query, in addition to the attributes of the node.
147+
"""
99148
geojson = self.node.as_geojson()
100149
geojson['properties']['matched'] = self.matched
101150
return geojson

jageocoder/rtree.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ def nearest(
408408
self,
409409
x: float,
410410
y: float,
411-
level: Optional[int] = None
411+
level: Optional[int] = None,
412+
as_dict: Optional[bool] = True,
412413
):
413414
"""
414415
Search nearest nodes of the target point.
@@ -422,10 +423,13 @@ def nearest(
422423
level: int, optional
423424
The level of the address ndoes to be retrieved as a result.
424425
If omitted, search down to the AZA level.
426+
as_dict: bool, default=True
427+
If False is specified, the addressNode object is stored
428+
in the "candidate" field.
425429
426430
Returns
427431
-------
428-
[{"candidate":AddressNode, "dist":float}]
432+
[{"candidate":AddressNode or dict, "dist":float}]
429433
Returns the results of retrieval up to 3 nodes.
430434
"""
431435
level = level or AddressLevel.AZA
@@ -497,7 +501,7 @@ def nearest(
497501
continue
498502

499503
results.append({
500-
"candidate": node.as_dict(),
504+
"candidate": node.as_dict() if as_dict else node,
501505
"dist": self.distance(x, y, node.x, node.y)
502506
})
503507
registered.add(node.id)

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "jageocoder"
3-
version = "2.1.4"
3+
version = "2.1.5.post1"
44
description = "A Japanese-address geocoder for Python."
55
authors = ["Takeshi Sagara <[email protected]>"]
66
repository = "https://github.com/t-sagara/jageocoder/"
@@ -28,7 +28,7 @@ docopt = "^0.6.2"
2828
geographiclib = "^2.0"
2929
idna = ">=3.7"
3030
jaconv = "^0.3.4"
31-
marisa-trie = "^0.7.8"
31+
marisa-trie = ">=0.7.8"
3232
pycapnp = "*"
3333
portabletab = ">=0.3.3"
3434
rtree = "^1.0.0"

0 commit comments

Comments
 (0)