Duplicate from kknono668/toeic-vocab-tw
Browse filesCo-authored-by: YANG SHIH WEI <kknono668@users.noreply.huggingface.co>
- LICENSE +16 -0
- README.md +174 -0
- data/toeic_vocabulary.json +0 -0
- data/toeic_vocabulary_raw.json +0 -0
- data/toeic_vocabulary_view.json +0 -0
- scripts/flatten_toeic.py +54 -0
- scripts/make_viewer_json.ps1 +51 -0
- scripts/release.ps1 +38 -0
- scripts/update_metadata.ps1 +42 -0
- scripts/update_readme.ps1 +22 -0
LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Creative Commons Attribution 4.0 International (CC BY 4.0)
|
| 2 |
+
|
| 3 |
+
This dataset is licensed under the Creative Commons Attribution 4.0 International License.
|
| 4 |
+
|
| 5 |
+
You are free to:
|
| 6 |
+
- Share — copy and redistribute the material in any medium or format
|
| 7 |
+
- Adapt — remix, transform, and build upon the material for any purpose, even commercially.
|
| 8 |
+
|
| 9 |
+
Under the following terms:
|
| 10 |
+
- Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
|
| 11 |
+
|
| 12 |
+
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
|
| 13 |
+
|
| 14 |
+
Full License Text:
|
| 15 |
+
https://creativecommons.org/licenses/by/4.0/legalcode
|
| 16 |
+
|
README.md
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: 完整 TOEIC 單字庫 (English–Traditional Chinese)
|
| 3 |
+
license: cc-by-4.0
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
- zh
|
| 7 |
+
language_bcp47:
|
| 8 |
+
- zh-Hant
|
| 9 |
+
configs:
|
| 10 |
+
- config_name: default
|
| 11 |
+
data_files:
|
| 12 |
+
- data/toeic_vocabulary_view.json
|
| 13 |
+
tags:
|
| 14 |
+
- toeic
|
| 15 |
+
- vocabulary
|
| 16 |
+
- bilingual
|
| 17 |
+
- english-chinese
|
| 18 |
+
- traditional-chinese
|
| 19 |
+
- business
|
| 20 |
+
- education
|
| 21 |
+
task_categories:
|
| 22 |
+
- other
|
| 23 |
+
size_categories:
|
| 24 |
+
- 1K<n<10K
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
# 完整 TOEIC 單字庫(English–Traditional Chinese)
|
| 28 |
+
|
| 29 |
+
一份面向 TOEIC 情境的雙語單字庫,涵蓋商務、辦公、會議、客戶服務、財務會計、行銷銷售、採購物流、法律合規、資訊技術等多個常見領域。資料以 JSON 提供,並依重要度劃分 5★–1★ 等級,附詞性、詞形變化與中英雙語例句,便於教學、備考、應用開發與語言學習研究。
|
| 30 |
+
|
| 31 |
+
## Dataset Summary
|
| 32 |
+
|
| 33 |
+
- Title: 完整 TOEIC 單字庫
|
| 34 |
+
- Version: 110.5
|
| 35 |
+
- Total Words: 9,537
|
| 36 |
+
- Language Pair: English ↔ Traditional Chinese (繁體中文)
|
| 37 |
+
- Structure: 單一 JSON 陣列(每列一個詞條)+ `data/metadata.json`
|
| 38 |
+
|
| 39 |
+
## Files
|
| 40 |
+
|
| 41 |
+
- `data/toeic_vocabulary.json`:主資料檔(頂層為陣列,每列一個詞條)
|
| 42 |
+
- `data/metadata.json`:資料集中繼資料(title/version/last_updated/total_words…)
|
| 43 |
+
|
| 44 |
+
可選(仍為 JSON,便於 Viewer 預覽):
|
| 45 |
+
- `data/toeic_vocabulary_view.json`:Viewer 友善版(巢狀欄位以字串存放,如 `word_forms_json`、`examples_json`,方便 HF 轉成表格)
|
| 46 |
+
|
| 47 |
+
## Schema
|
| 48 |
+
|
| 49 |
+
- 主檔(`data/toeic_vocabulary.json`)為「頂層陣列」,每個詞條包含:
|
| 50 |
+
|
| 51 |
+
- `english_word`:英文單字
|
| 52 |
+
- `chinese_definition`:中文定義
|
| 53 |
+
- `star_rating`:整數(1–5)
|
| 54 |
+
- `category`:所屬主題分類
|
| 55 |
+
- `parts_of_speech`:詞性陣列(如 noun/verb/adj/adv 等)
|
| 56 |
+
- `word_forms`:依詞性細分的詞形(例:名詞複數、動詞三單/過去式/分詞/動名詞等)
|
| 57 |
+
- `examples`:例句陣列(`english`、`chinese`)
|
| 58 |
+
- `importance_group`:原始分組標籤(如 `5_stars_essential`)
|
| 59 |
+
|
| 60 |
+
- 中繼資料(`data/metadata.json`):
|
| 61 |
+
- `title`、`version`、`description`、`total_words`、`creation_date`、`language_pair`
|
| 62 |
+
- `categories`、`star_system`、`last_updated`
|
| 63 |
+
|
| 64 |
+
### Star System 說明
|
| 65 |
+
|
| 66 |
+
- 5★ 核心商業詞彙:最高優先級,TOEIC 必備
|
| 67 |
+
- 4★ 重要專業詞彙:商務場合常用
|
| 68 |
+
- 3★ 職場/學術詞彙:有助提升語言能力
|
| 69 |
+
- 2★ 有用支援詞彙:擴展詞彙量
|
| 70 |
+
- 1★ 一般詞彙:建議了解
|
| 71 |
+
|
| 72 |
+
## Example Instance
|
| 73 |
+
|
| 74 |
+
```json
|
| 75 |
+
{
|
| 76 |
+
"english_word": "answer",
|
| 77 |
+
"chinese_definition": "回覆;答覆;回應",
|
| 78 |
+
"star_rating": 5,
|
| 79 |
+
"category": "溝通互動",
|
| 80 |
+
"parts_of_speech": ["noun", "verb"],
|
| 81 |
+
"word_forms": {
|
| 82 |
+
"noun": {"plural": "answers"},
|
| 83 |
+
"verb": {
|
| 84 |
+
"third_person_sg": "answers",
|
| 85 |
+
"past": "answered",
|
| 86 |
+
"past_participle": "answered",
|
| 87 |
+
"present_participle": "answering"
|
| 88 |
+
}
|
| 89 |
+
},
|
| 90 |
+
"examples": [
|
| 91 |
+
{"english": "Could you please answer the questionnaire before the meeting?", "chinese": "請在會議前填寫問卷並回覆。"},
|
| 92 |
+
{"english": "The applicant needs to answer all the questions truthfully.", "chinese": "申請人需要誠實地回答所有問題。"}
|
| 93 |
+
],
|
| 94 |
+
"importance_group": "5_stars_essential"
|
| 95 |
+
}
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
## Usage
|
| 99 |
+
|
| 100 |
+
### Local (JSON)
|
| 101 |
+
|
| 102 |
+
```python
|
| 103 |
+
import json
|
| 104 |
+
from pathlib import Path
|
| 105 |
+
|
| 106 |
+
path = Path("data/toeic_vocabulary.json")
|
| 107 |
+
rows = json.loads(path.read_text(encoding="utf-8")) # 頂層為陣列
|
| 108 |
+
|
| 109 |
+
print(len(rows), "words total")
|
| 110 |
+
# 篩選 5★ 詞條
|
| 111 |
+
top_words = [r for r in rows if r.get("importance_group") == "5_stars_essential"]
|
| 112 |
+
print(len(top_words), "top words")
|
| 113 |
+
print(top_words[0]["english_word"], top_words[0]["chinese_definition"])
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
### After Upload (datasets)
|
| 117 |
+
|
| 118 |
+
上傳到 Hugging Face 後,可使用 `datasets` 套件讀取:
|
| 119 |
+
|
| 120 |
+
```python
|
| 121 |
+
from datasets import load_dataset
|
| 122 |
+
|
| 123 |
+
# 直接載入主檔(頂層陣列 JSON;保留巢狀欄位)
|
| 124 |
+
ds = load_dataset(
|
| 125 |
+
"json",
|
| 126 |
+
data_files="https://huggingface.co/datasets/kknono668/toeic-vocab-tw/resolve/main/data/toeic_vocabulary.json",
|
| 127 |
+
split="train",
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
# 若要簡化成純表格欄位,可改載入 viewer 友善版(巢狀欄位已字串化)
|
| 131 |
+
# ds = load_dataset(
|
| 132 |
+
# "json",
|
| 133 |
+
# data_files="https://huggingface.co/datasets/kknono668/toeic-vocab-tw/resolve/main/data/toeic_vocabulary_view.json",
|
| 134 |
+
# split="train",
|
| 135 |
+
# )
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
> 提示:若要轉為扁平表格(如 Pandas DataFrame),可將各重要度群組展開並加上 `importance_group` 欄位。
|
| 139 |
+
|
| 140 |
+
## Intended Uses
|
| 141 |
+
|
| 142 |
+
- TOEIC 應試準備、語言教學與練習
|
| 143 |
+
- 商務英語學習應用(查詢、測驗、卡片、練習題生成)
|
| 144 |
+
- 詞彙表與例句檢索工具
|
| 145 |
+
|
| 146 |
+
## Limitations
|
| 147 |
+
|
| 148 |
+
- 定義與例句聚焦於職場/商務情境,對一般語境未必全面
|
| 149 |
+
- 詞性與詞形為常見用法彙整,未涵蓋所有罕見變化
|
| 150 |
+
|
| 151 |
+
## License
|
| 152 |
+
|
| 153 |
+
本資料集以 CC BY 4.0 釋出。請在使用時適當標註來源與作者,並附上授權連結。
|
| 154 |
+
|
| 155 |
+
- Name: Creative Commons Attribution 4.0 International (CC BY 4.0)
|
| 156 |
+
- Link: https://creativecommons.org/licenses/by/4.0/
|
| 157 |
+
|
| 158 |
+
## Citation
|
| 159 |
+
|
| 160 |
+
如果你在研究或產品中使用了本資料集,請引用:
|
| 161 |
+
|
| 162 |
+
```
|
| 163 |
+
@misc{toeic_vocab_2025,
|
| 164 |
+
title = {完整 TOEIC 單字庫 (English–Traditional Chinese)},
|
| 165 |
+
year = {2025},
|
| 166 |
+
note = {CC BY 4.0},
|
| 167 |
+
howpublished = {Hugging Face Dataset}
|
| 168 |
+
}
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
## Changelog
|
| 172 |
+
|
| 173 |
+
- v34.8: 初版公開;9,855 詞條;依 5★–1★ 分組;含詞性、詞形、例句與分類。
|
| 174 |
+
|
data/toeic_vocabulary.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/toeic_vocabulary_raw.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/toeic_vocabulary_view.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scripts/flatten_toeic.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import csv
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
SRC = Path("data/toeic_vocabulary.json")
|
| 6 |
+
OUT_JSONL = Path("data/toeic_vocabulary_flat.jsonl")
|
| 7 |
+
OUT_CSV = Path("data/toeic_vocabulary_flat.csv")
|
| 8 |
+
|
| 9 |
+
def main():
|
| 10 |
+
data = json.loads(SRC.read_text(encoding="utf-8"))
|
| 11 |
+
vocab_groups = data.get("vocabulary_by_importance", {})
|
| 12 |
+
|
| 13 |
+
rows = []
|
| 14 |
+
for importance_group, items in vocab_groups.items():
|
| 15 |
+
if not isinstance(items, list):
|
| 16 |
+
continue
|
| 17 |
+
for item in items:
|
| 18 |
+
row = {
|
| 19 |
+
"importance_group": importance_group,
|
| 20 |
+
"english_word": item.get("english_word"),
|
| 21 |
+
"chinese_definition": item.get("chinese_definition"),
|
| 22 |
+
"star_rating": item.get("star_rating"),
|
| 23 |
+
"category": item.get("category"),
|
| 24 |
+
"parts_of_speech": "|".join(item.get("parts_of_speech", []) or []),
|
| 25 |
+
"word_forms": json.dumps(item.get("word_forms", {}), ensure_ascii=False),
|
| 26 |
+
"examples": json.dumps(item.get("examples", []), ensure_ascii=False),
|
| 27 |
+
}
|
| 28 |
+
rows.append(row)
|
| 29 |
+
|
| 30 |
+
# write jsonl
|
| 31 |
+
with OUT_JSONL.open("w", encoding="utf-8", newline="\n") as f:
|
| 32 |
+
for r in rows:
|
| 33 |
+
f.write(json.dumps(r, ensure_ascii=False) + "\n")
|
| 34 |
+
|
| 35 |
+
# write csv
|
| 36 |
+
cols = [
|
| 37 |
+
"importance_group",
|
| 38 |
+
"english_word",
|
| 39 |
+
"chinese_definition",
|
| 40 |
+
"star_rating",
|
| 41 |
+
"category",
|
| 42 |
+
"parts_of_speech",
|
| 43 |
+
"word_forms",
|
| 44 |
+
"examples",
|
| 45 |
+
]
|
| 46 |
+
with OUT_CSV.open("w", encoding="utf-8", newline="") as f:
|
| 47 |
+
writer = csv.DictWriter(f, fieldnames=cols)
|
| 48 |
+
writer.writeheader()
|
| 49 |
+
for r in rows:
|
| 50 |
+
writer.writerow(r)
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
main()
|
| 54 |
+
|
scripts/make_viewer_json.ps1
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Param()
|
| 2 |
+
|
| 3 |
+
$ErrorActionPreference = 'Stop'
|
| 4 |
+
|
| 5 |
+
$root = Split-Path $PSScriptRoot -Parent
|
| 6 |
+
$src = Join-Path $root 'data' 'toeic_vocabulary.json'
|
| 7 |
+
$dst = Join-Path $root 'data' 'toeic_vocabulary_view.json'
|
| 8 |
+
|
| 9 |
+
if (!(Test-Path $src)) { throw "找不到資料檔:$src" }
|
| 10 |
+
|
| 11 |
+
$obj = Get-Content -Path $src -Raw -Encoding UTF8 | ConvertFrom-Json
|
| 12 |
+
|
| 13 |
+
# 支援兩種結構:
|
| 14 |
+
# 1) 頂層陣列(新結構)
|
| 15 |
+
# 2) 含 vocabulary_by_importance(舊結構)
|
| 16 |
+
|
| 17 |
+
$items = @()
|
| 18 |
+
if ($obj -is [System.Array]) {
|
| 19 |
+
$items = $obj
|
| 20 |
+
} else {
|
| 21 |
+
$groups = $obj.vocabulary_by_importance.PSObject.Properties
|
| 22 |
+
foreach ($prop in $groups) {
|
| 23 |
+
$importance = $prop.Name
|
| 24 |
+
foreach ($it in $prop.Value) {
|
| 25 |
+
# 注入 importance_group 以統一欄位
|
| 26 |
+
$it | Add-Member -NotePropertyName importance_group -NotePropertyValue $importance -Force
|
| 27 |
+
$items += $it
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
$out = @()
|
| 33 |
+
foreach ($r in $items) {
|
| 34 |
+
# 保持欄位型別簡單:純字串、整數
|
| 35 |
+
$pos = $r.parts_of_speech
|
| 36 |
+
if ($null -eq $pos) { $pos = @() }
|
| 37 |
+
if ($pos -isnot [System.Array]) { $pos = @($pos) }
|
| 38 |
+
$out += [pscustomobject]@{
|
| 39 |
+
english_word = [string]$r.english_word
|
| 40 |
+
chinese_definition = [string]$r.chinese_definition
|
| 41 |
+
star_rating = [int]$r.star_rating
|
| 42 |
+
category = [string]$r.category
|
| 43 |
+
parts_of_speech = ($pos -join '|')
|
| 44 |
+
word_forms_json = if ($r.word_forms) { ($r.word_forms | ConvertTo-Json -Depth 20 -Compress) } else { $null }
|
| 45 |
+
examples_json = if ($r.examples) { ($r.examples | ConvertTo-Json -Depth 20 -Compress) } else { $null }
|
| 46 |
+
importance_group = [string]$r.importance_group
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
$out | ConvertTo-Json -Depth 5 | Set-Content -Path $dst -Encoding UTF8
|
| 51 |
+
Write-Host "已輸出 Viewer 友善 JSON -> $dst" -ForegroundColor Green
|
scripts/release.ps1
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Param(
|
| 2 |
+
[string]$Version,
|
| 3 |
+
[string]$Message = "Release"
|
| 4 |
+
)
|
| 5 |
+
|
| 6 |
+
$ErrorActionPreference = 'Stop'
|
| 7 |
+
|
| 8 |
+
$root = Split-Path $PSScriptRoot -Parent
|
| 9 |
+
Set-Location $root
|
| 10 |
+
|
| 11 |
+
Write-Host "[1/4] 更新 metadata (version=$Version)" -ForegroundColor Cyan
|
| 12 |
+
& (Join-Path $PSScriptRoot 'update_metadata.ps1') -Version $Version
|
| 13 |
+
|
| 14 |
+
# 讀取更新後的總詞數與版本(兼容兩種結構)
|
| 15 |
+
$dataPath = Join-Path $root 'data' 'toeic_vocabulary.json'
|
| 16 |
+
$obj = Get-Content -Path $dataPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
| 17 |
+
if ($obj -is [System.Array]) {
|
| 18 |
+
$total = @($obj).Count
|
| 19 |
+
$metaPath = Join-Path $root 'data' 'metadata.json'
|
| 20 |
+
$meta = if (Test-Path $metaPath) { Get-Content -Path $metaPath -Raw -Encoding UTF8 | ConvertFrom-Json } else { $null }
|
| 21 |
+
$v = if ($meta) { $meta.version } else { $Version }
|
| 22 |
+
} else {
|
| 23 |
+
$total = [int]$obj.metadata.total_words
|
| 24 |
+
$v = $obj.metadata.version
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
Write-Host "[2/4] 產生 Viewer 友善 JSON" -ForegroundColor Cyan
|
| 28 |
+
& (Join-Path $PSScriptRoot 'make_viewer_json.ps1')
|
| 29 |
+
|
| 30 |
+
Write-Host "[3/4] 更新 README 統計" -ForegroundColor Cyan
|
| 31 |
+
& (Join-Path $PSScriptRoot 'update_readme.ps1') -Version $v -TotalWords $total
|
| 32 |
+
|
| 33 |
+
Write-Host "[4/4] 提交並推送" -ForegroundColor Cyan
|
| 34 |
+
git add README.md data/toeic_vocabulary.json data/metadata.json data/toeic_vocabulary_view.json scripts/*.ps1 | Out-Null
|
| 35 |
+
$commitMsg = if ($Version) { "${Message} v${v}" } else { $Message }
|
| 36 |
+
git commit -m $commitMsg | Out-Null
|
| 37 |
+
git push -u origin main
|
| 38 |
+
Write-Host "完成發佈:$commitMsg" -ForegroundColor Green
|
scripts/update_metadata.ps1
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Param(
|
| 2 |
+
[string]$Version
|
| 3 |
+
)
|
| 4 |
+
|
| 5 |
+
$ErrorActionPreference = 'Stop'
|
| 6 |
+
|
| 7 |
+
$root = Split-Path $PSScriptRoot -Parent
|
| 8 |
+
$jsonPath = Join-Path $root 'data' 'toeic_vocabulary.json'
|
| 9 |
+
if (!(Test-Path $jsonPath)) { throw "找不到資料檔:$jsonPath" }
|
| 10 |
+
|
| 11 |
+
$data = Get-Content -Path $jsonPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
| 12 |
+
|
| 13 |
+
if ($data -is [System.Array]) {
|
| 14 |
+
# 新結構:頂層陣列,metadata 存在 data/metadata.json
|
| 15 |
+
$total = @($data).Count
|
| 16 |
+
$metaPath = Join-Path $root 'data' 'metadata.json'
|
| 17 |
+
if (Test-Path $metaPath) {
|
| 18 |
+
$meta = Get-Content -Path $metaPath -Raw -Encoding UTF8 | ConvertFrom-Json
|
| 19 |
+
} else {
|
| 20 |
+
$meta = [ordered]@{}
|
| 21 |
+
}
|
| 22 |
+
$meta.total_words = $total
|
| 23 |
+
$meta.last_updated = (Get-Date).ToString('o')
|
| 24 |
+
if ($Version) { $meta.version = $Version }
|
| 25 |
+
($meta | ConvertTo-Json -Depth 100) | Set-Content -Path $metaPath -Encoding UTF8
|
| 26 |
+
Write-Host "已更新 metadata.json:total_words=$total; version=$($meta.version); last_updated=$($meta.last_updated)"
|
| 27 |
+
} else {
|
| 28 |
+
# 舊結構:含 metadata 與 vocabulary_by_importance
|
| 29 |
+
$total = 0
|
| 30 |
+
foreach ($prop in $data.vocabulary_by_importance.PSObject.Properties) {
|
| 31 |
+
$items = $prop.Value
|
| 32 |
+
if ($items -is [System.Collections.IEnumerable]) {
|
| 33 |
+
$total += @($items).Count
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
$data.metadata.total_words = $total
|
| 37 |
+
$data.metadata.last_updated = (Get-Date).ToString('o')
|
| 38 |
+
if ($Version) { $data.metadata.version = $Version }
|
| 39 |
+
$jsonOut = $data | ConvertTo-Json -Depth 100
|
| 40 |
+
Set-Content -Path $jsonPath -Value $jsonOut -Encoding UTF8
|
| 41 |
+
Write-Host "已更新 metadata:total_words=$total; version=$($data.metadata.version); last_updated=$($data.metadata.last_updated)"
|
| 42 |
+
}
|
scripts/update_readme.ps1
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Param(
|
| 2 |
+
[Parameter(Mandatory=$true)][string]$Version,
|
| 3 |
+
[Parameter(Mandatory=$true)][int]$TotalWords
|
| 4 |
+
)
|
| 5 |
+
|
| 6 |
+
$ErrorActionPreference = 'Stop'
|
| 7 |
+
|
| 8 |
+
$readme = Join-Path $PSScriptRoot '..' 'README.md'
|
| 9 |
+
if (!(Test-Path $readme)) { throw "找不到 README:$readme" }
|
| 10 |
+
|
| 11 |
+
$content = Get-Content -Path $readme -Raw -Encoding UTF8
|
| 12 |
+
|
| 13 |
+
# 版本
|
| 14 |
+
$content = [regex]::Replace($content, "(?m)^-\s*Version:\s*.*$", "- Version: $Version")
|
| 15 |
+
|
| 16 |
+
# 總詞數(加上千位逗號)
|
| 17 |
+
$totalFmt = ([string]::Format([System.Globalization.CultureInfo]::InvariantCulture, "{0:N0}", $TotalWords))
|
| 18 |
+
$content = [regex]::Replace($content, "(?m)^-\s*Total Words:\s*.*$", "- Total Words: $totalFmt")
|
| 19 |
+
|
| 20 |
+
Set-Content -Path $readme -Value $content -Encoding UTF8
|
| 21 |
+
Write-Host "已更新 README:Version=$Version, Total Words=$totalFmt"
|
| 22 |
+
|