Skip to content

Commit a158dd4

Browse files
authored
Merge pull request #442 from PyThaiNLP/fix-update-bug
Fix update bug
2 parents 6c83fd5 + ab74589 commit a158dd4

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Using PyThaiNLP:
2828
- More tutorials at [https://www.thainlp.org/pythainlp/tutorials/](https://www.thainlp.org/pythainlp/tutorials/)
2929
- See full documentation at [https://thainlp.org/pythainlp/docs/2.2/](https://thainlp.org/pythainlp/docs/2.2/)
3030
- Some additional data (like word lists and language models) may get automatically download during runtime and it will be kept under the directory `~/pythainlp-data` by default. See corpus catalog at [https://github.com/PyThaiNLP/pythainlp-corpus](https://github.com/PyThaiNLP/pythainlp-corpus).
31-
- The data location can be changed, using `PYTHAINLP_DATA_DIR` environment variable.
31+
- The data location can be changed, using `PYTHAINLP_DATA_DIR` environment variable.
3232
- For PyThaiNLP tokenization performance and measurement methods, see [tokenization benchmark](tokenization-benchmark.md)
3333
- 📫 follow our [PyThaiNLP](https://www.facebook.com/pythainlp/) Facebook page
3434

pythainlp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = "2.2.0"
2+
__version__ = "2.2.1"
33

44
thai_consonants = "กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรลวศษสหฬอฮ" # 44 chars
55

pythainlp/corpus/core.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ def get_corpus(filename: str) -> frozenset:
8888
return frozenset(lines)
8989

9090

91+
def _update_all():
92+
print("Update Corpus...")
93+
with TinyDB(corpus_db_path()) as local_db:
94+
item_all = local_db.all()
95+
query = Query()
96+
for item in item_all:
97+
name = item["name"]
98+
if "file_name" in item.keys():
99+
local_db.update({"filename": item["file_name"]}, query.name == name)
100+
elif "file" in item.keys():
101+
local_db.update({"filename": item["file"]}, query.name == name)
102+
local_db.close()
103+
104+
91105
def get_corpus_path(name: str) -> Union[str, None]:
92106
"""
93107
Get corpus path.
@@ -125,13 +139,18 @@ def get_corpus_path(name: str) -> Union[str, None]:
125139
"""
126140
# check if the corpus is in local catalog, download if not
127141
corpus_db_detail = get_corpus_db_detail(name)
128-
if not corpus_db_detail or not corpus_db_detail.get("file_name"):
142+
if corpus_db_detail.get("file_name") is not None and corpus_db_detail.get("filename") is None:
143+
_update_all()
144+
elif corpus_db_detail.get("file") is not None and corpus_db_detail.get("filename") is None:
145+
_update_all()
146+
147+
if not corpus_db_detail or not corpus_db_detail.get("filename"):
129148
download(name)
130149
corpus_db_detail = get_corpus_db_detail(name)
131150

132-
if corpus_db_detail and corpus_db_detail.get("file_name"):
151+
if corpus_db_detail and corpus_db_detail.get("filename"):
133152
# corpus is in the local catalog, get full path to the file
134-
path = get_full_data_path(corpus_db_detail.get("file_name"))
153+
path = get_full_data_path(corpus_db_detail.get("filename"))
135154
# check if the corpus file actually exists, download if not
136155
if not os.path.exists(path):
137156
download(name)
@@ -263,7 +282,7 @@ def download(name: str, force: bool = False, url: str = None, version: str = Non
263282
{
264283
"name": name,
265284
"version": version,
266-
"file_name": file_name,
285+
"filename": file_name,
267286
}
268287
)
269288
else:

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.2.0
2+
current_version = 2.2.1
33
commit = True
44
tag = True
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171

7272
setup(
7373
name="pythainlp",
74-
version="2.2.0",
74+
version="2.2.1",
7575
description="Thai Natural Language Processing library",
7676
long_description=readme,
7777
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)