Skip to content

Commit

Permalink
Update Proficiency v0.5.10
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed Sep 29, 2023
1 parent 817c193 commit ed989a6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 36 deletions.
2 changes: 1 addition & 1 deletion custom_lemmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def check_empty_kindle_gloss(self) -> None:
if not package_name:
device_not_found_dialog(self)
return
custom_folder = custom_lemmas_folder(plugin_path)
custom_folder = custom_lemmas_folder(plugin_path, "en")
if isinstance(package_name, str):
copy_klld_from_android(package_name, custom_folder)
else:
Expand Down
4 changes: 2 additions & 2 deletions data/deps.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"cupy": "12.2.0",
"lxml": "4.9.3",
"thinc-apple-ops": "0.1.3",
"thinc-apple-ops": "0.1.4",
"torch": "2.0.1",
"rapidfuzz": "3.3.0",
"rapidfuzz": "3.3.1",
"spacy_cpu_model": "3.6.0",
"spacy_trf_model": "3.6.1"
}
29 changes: 9 additions & 20 deletions deps.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env python3

import bz2
import platform
import shutil
import tarfile
from io import BytesIO
from pathlib import Path
from typing import Any
from urllib.request import urlopen
Expand All @@ -12,16 +11,13 @@

from .utils import (
PROFICIENCY_RELEASE_URL,
PROFICIENCY_VERSION,
Prefs,
custom_lemmas_folder,
get_plugin_path,
get_wiktionary_klld_path,
kindle_db_path,
load_plugin_json,
mac_bin_path,
run_subprocess,
use_kindle_ww_db,
wiktionary_db_path,
)

Expand Down Expand Up @@ -173,25 +169,18 @@ def download_word_wise_file(
else:
db_path = wiktionary_db_path(plugin_path, lemma_lang, gloss_lang)

extract_folder = custom_lemmas_folder(get_plugin_path())
if not db_path.exists():
filename = f"wiktionary_{lemma_lang}_{gloss_lang}_v{PROFICIENCY_VERSION}.bz2"
if is_kindle and use_kindle_ww_db(lemma_lang, prefs):
filename = f"kindle_en_en_v{PROFICIENCY_VERSION}.bz2"
url = f"{PROFICIENCY_RELEASE_URL}/{filename}"
download_and_extract(url, extract_folder)
bz2_filename = db_path.with_suffix(db_path.suffix + ".bz2").name
download_and_extract(f"{PROFICIENCY_RELEASE_URL}/{bz2_filename}", db_path)

if is_kindle:
klld_path = get_wiktionary_klld_path(plugin_path, lemma_lang, gloss_lang)
if not klld_path.exists():
url = (
PROFICIENCY_RELEASE_URL
+ f"/kll.{lemma_lang}.{gloss_lang}_v{PROFICIENCY_VERSION}.klld.bz2"
)
download_and_extract(url, extract_folder)
bz2_filename = klld_path.with_suffix(klld_path.suffix + ".bz2").name
download_and_extract(f"{PROFICIENCY_RELEASE_URL}/{bz2_filename}", klld_path)


def download_and_extract(url: str, extract_folder: Path) -> None:
with urlopen(url) as r:
with tarfile.open(fileobj=BytesIO(r.read())) as tar:
tar.extractall(extract_folder)
def download_and_extract(url: str, extract_path: Path) -> None:
extract_path.parent.mkdir(parents=True, exist_ok=True)
with urlopen(url) as r, bz2.open(r) as bz2_f, extract_path.open("wb") as f:
shutil.copyfileobj(bz2_f, f)
5 changes: 2 additions & 3 deletions dump_lemmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ def spacy_doc_path(
if is_kindle and not use_kindle_ww_db(lemma_lang, prefs):
is_kindle = False
py_version = ".".join(platform.python_version_tuple()[:2])
path = custom_lemmas_folder(plugin_path).joinpath(
f"{lemma_lang}/{spacy_model}_"
f"{'kindle' if is_kindle else 'wiktionary'}"
path = custom_lemmas_folder(plugin_path, lemma_lang).joinpath(
f"{spacy_model}_{'kindle' if is_kindle else 'wiktionary'}"
f"_{gloss_lang}_{model_version}_{py_version}"
)
if prefs["use_pos"]:
Expand Down
17 changes: 7 additions & 10 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Any, TypedDict

CJK_LANGS = ["zh", "ja", "ko"]
PROFICIENCY_VERSION = "0.5.8"
PROFICIENCY_VERSION = "0.5.10"
PROFICIENCY_RELEASE_URL = (
f"https://github.com/xxyzz/Proficiency/releases/download/v{PROFICIENCY_VERSION}"
)
Expand Down Expand Up @@ -98,8 +98,8 @@ def get_plugin_path() -> Path:
return Path(config_dir) / "plugins/WordDumb.zip"


def custom_lemmas_folder(plugin_path: Path) -> Path:
return plugin_path.parent / "worddumb-lemmas"
def custom_lemmas_folder(plugin_path: Path, lemma_lang: str) -> Path:
return plugin_path.parent / "worddumb-lemmas" / lemma_lang


def use_kindle_ww_db(lemma_lang: str, prefs: Prefs) -> bool:
Expand All @@ -113,8 +113,7 @@ def use_kindle_ww_db(lemma_lang: str, prefs: Prefs) -> bool:
def kindle_db_path(plugin_path: Path, lemma_lang: str, prefs: Prefs) -> Path:
if use_kindle_ww_db(lemma_lang, prefs):
return (
custom_lemmas_folder(plugin_path)
/ lemma_lang
custom_lemmas_folder(plugin_path, lemma_lang)
/ f"kindle_en_en_v{PROFICIENCY_MAJOR_VERSION}.db"
)
else:
Expand All @@ -123,14 +122,13 @@ def kindle_db_path(plugin_path: Path, lemma_lang: str, prefs: Prefs) -> Path:

def wiktionary_db_path(plugin_path: Path, lemma_lang: str, gloss_lang: str) -> Path:
return (
custom_lemmas_folder(plugin_path)
/ lemma_lang
custom_lemmas_folder(plugin_path, lemma_lang)
/ f"wiktionary_{lemma_lang}_{gloss_lang}_v{PROFICIENCY_MAJOR_VERSION}.db"
)


def get_klld_path(plugin_path: Path) -> Path | None:
custom_folder = custom_lemmas_folder(plugin_path)
custom_folder = custom_lemmas_folder(plugin_path, "")
for path in custom_folder.glob("*.en.klld"):
return path
for path in custom_folder.glob("*.en.db"):
Expand All @@ -142,8 +140,7 @@ def get_wiktionary_klld_path(
plugin_path: Path, lemma_lang: str, gloss_lang: str
) -> Path:
return (
custom_lemmas_folder(plugin_path)
/ lemma_lang
custom_lemmas_folder(plugin_path, lemma_lang)
/ f"kll.{lemma_lang}.{gloss_lang}_v{PROFICIENCY_MAJOR_VERSION}.klld"
)

Expand Down

0 comments on commit ed989a6

Please sign in to comment.