studyforge-vocab 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. studyforge_vocab-0.2.0/LICENSE +21 -0
  2. studyforge_vocab-0.2.0/PKG-INFO +408 -0
  3. studyforge_vocab-0.2.0/README.md +371 -0
  4. studyforge_vocab-0.2.0/data/LICENSE_ECDICT.txt +21 -0
  5. studyforge_vocab-0.2.0/data/NOTICE.md +10 -0
  6. studyforge_vocab-0.2.0/data/NOTICE_CEFR.md +26 -0
  7. studyforge_vocab-0.2.0/pyproject.toml +69 -0
  8. studyforge_vocab-0.2.0/setup.cfg +4 -0
  9. studyforge_vocab-0.2.0/studyforge/__init__.py +23 -0
  10. studyforge_vocab-0.2.0/studyforge/__main__.py +4 -0
  11. studyforge_vocab-0.2.0/studyforge/api.py +116 -0
  12. studyforge_vocab-0.2.0/studyforge/cefr.py +62 -0
  13. studyforge_vocab-0.2.0/studyforge/cli.py +88 -0
  14. studyforge_vocab-0.2.0/studyforge/data/__init__.py +1 -0
  15. studyforge_vocab-0.2.0/studyforge/data/cefr_levels.json +1 -0
  16. studyforge_vocab-0.2.0/studyforge/data/studyforge_dictionary.db +0 -0
  17. studyforge_vocab-0.2.0/studyforge/dictionary.py +136 -0
  18. studyforge_vocab-0.2.0/studyforge/exporter.py +245 -0
  19. studyforge_vocab-0.2.0/studyforge/fallback_dictionary.py +142 -0
  20. studyforge_vocab-0.2.0/studyforge/models.py +65 -0
  21. studyforge_vocab-0.2.0/studyforge/pdf_reader.py +76 -0
  22. studyforge_vocab-0.2.0/studyforge/presentation.py +33 -0
  23. studyforge_vocab-0.2.0/studyforge/py.typed +1 -0
  24. studyforge_vocab-0.2.0/studyforge/resources.py +19 -0
  25. studyforge_vocab-0.2.0/studyforge/vocabulary.py +278 -0
  26. studyforge_vocab-0.2.0/studyforge_vocab.egg-info/PKG-INFO +408 -0
  27. studyforge_vocab-0.2.0/studyforge_vocab.egg-info/SOURCES.txt +41 -0
  28. studyforge_vocab-0.2.0/studyforge_vocab.egg-info/dependency_links.txt +1 -0
  29. studyforge_vocab-0.2.0/studyforge_vocab.egg-info/entry_points.txt +2 -0
  30. studyforge_vocab-0.2.0/studyforge_vocab.egg-info/requires.txt +11 -0
  31. studyforge_vocab-0.2.0/studyforge_vocab.egg-info/top_level.txt +1 -0
  32. studyforge_vocab-0.2.0/tests/test_api.py +47 -0
  33. studyforge_vocab-0.2.0/tests/test_app.py +18 -0
  34. studyforge_vocab-0.2.0/tests/test_build_dictionary.py +51 -0
  35. studyforge_vocab-0.2.0/tests/test_cefr.py +52 -0
  36. studyforge_vocab-0.2.0/tests/test_cli.py +55 -0
  37. studyforge_vocab-0.2.0/tests/test_deployment.py +48 -0
  38. studyforge_vocab-0.2.0/tests/test_dictionary.py +36 -0
  39. studyforge_vocab-0.2.0/tests/test_exporter.py +103 -0
  40. studyforge_vocab-0.2.0/tests/test_github_config.py +78 -0
  41. studyforge_vocab-0.2.0/tests/test_pdf_reader.py +55 -0
  42. studyforge_vocab-0.2.0/tests/test_presentation.py +22 -0
  43. studyforge_vocab-0.2.0/tests/test_vocabulary.py +76 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 StudyForge contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,408 @@
1
+ Metadata-Version: 2.4
2
+ Name: studyforge-vocab
3
+ Version: 0.2.0
4
+ Summary: Extract reusable English vocabulary study data from PDF files.
5
+ Author: StudyForge contributors
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://studyforge-kpamprbzckvvgx4sz6fxvz.streamlit.app/
8
+ Project-URL: Repository, https://github.com/gfr211306-crypto/StudyForge
9
+ Project-URL: Issues, https://github.com/gfr211306-crypto/StudyForge/issues
10
+ Project-URL: Changelog, https://github.com/gfr211306-crypto/StudyForge/blob/main/CHANGELOG.md
11
+ Keywords: pdf,vocabulary,anki,ielts,cefr,streamlit
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Environment :: Web Environment
15
+ Classifier: Intended Audience :: Education
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Education
20
+ Classifier: Topic :: Text Processing :: Linguistic
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ License-File: data/LICENSE_ECDICT.txt
25
+ License-File: data/NOTICE.md
26
+ License-File: data/NOTICE_CEFR.md
27
+ Requires-Dist: PyMuPDF<2.0,>=1.25
28
+ Requires-Dist: opencc-python-reimplemented<0.2,>=0.1.7
29
+ Provides-Extra: web
30
+ Requires-Dist: streamlit<2.0,>=1.61; extra == "web"
31
+ Requires-Dist: pandas<3.0,>=2.3; extra == "web"
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest<10,>=9; extra == "dev"
34
+ Requires-Dist: PyYAML<7,>=6; extra == "dev"
35
+ Requires-Dist: build<2,>=1.5; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # StudyForge
39
+
40
+ [![CI](https://github.com/gfr211306-crypto/StudyForge/actions/workflows/ci.yml/badge.svg)](https://github.com/gfr211306-crypto/StudyForge/actions/workflows/ci.yml)
41
+ [![Python](https://img.shields.io/badge/Python-3.11%20%7C%203.12-3776AB?logo=python&logoColor=white)](https://www.python.org/)
42
+ [![Streamlit](https://img.shields.io/badge/Streamlit-1.61.1-FF4B4B?logo=streamlit&logoColor=white)](https://streamlit.io/)
43
+ [![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
44
+
45
+ StudyForge v0.2.0 是一個可重用的開源 PDF vocabulary toolkit。它提供
46
+ Streamlit Web App、CLI 與 Python API,可將英文 PDF 自動整理成可複習、
47
+ 可編輯並能匯入 Anki 的單字資料:
48
+
49
+ **PDF → 文字擷取 → 重要英文單字 → 繁體中文釋義/詞性/原文例句 → Anki CSV**
50
+
51
+ 全程不需要 API key,也不會把文件內容送往翻譯或 AI API。
52
+
53
+ ## Live Demo
54
+
55
+ ### 🚀 [立即開啟 StudyForge 公開版](https://studyforge-kpamprbzckvvgx4sz6fxvz.streamlit.app/)
56
+
57
+ - 公開網址:<https://studyforge-kpamprbzckvvgx4sz6fxvz.streamlit.app/>
58
+ - 本機示範:執行 `streamlit run app.py` 後開啟 `http://localhost:8501`
59
+ - 示範教材:`samples/StudyForge_demo.pdf`
60
+ - Community Cloud 入口檔:`app.py`
61
+ - 建議部署 Python:`3.12`
62
+
63
+ ## Features
64
+
65
+ - 使用 **PyMuPDF** 擷取文字型 PDF 的逐頁內容
66
+ - 依出現頻率、跨頁分布、字頻與學術標籤推薦重要單字
67
+ - 使用超過 50,000 個詞條的本機離線英中詞典
68
+ - 將簡體詞典釋義轉成繁體中文
69
+ - 合併常見詞形,例如 `analyzed` → `analyze`
70
+ - IELTS vocabulary mode 優先排列詞典中明確標記為 IELTS 的單字
71
+ - CEFR A1–C2 分級;來源無法可靠判定時明確標示 `unknown`
72
+ - 從 PDF 原文自動挑選例句
73
+ - 顯示音標、詞性、中文意思、出現次數與頁碼
74
+ - 可在匯出前直接編輯或取消單字
75
+ - 支援 Anki CSV、普通 CSV 與 JSON
76
+ - 提供 `studyforge extract` CLI
77
+ - 提供可供其他 Python 專案 import 的 public API
78
+ - 對空白、損壞、密碼保護與掃描型 PDF 提供中文錯誤訊息
79
+ - 防護公開部署資源:25 MB、400 頁、2,000,000 個擷取字元上限
80
+ - 對 PDF 與使用者輸入進行 HTML escaping
81
+ - 使用每個 Streamlit session 獨立的分析結果,不共用使用者 PDF 快取
82
+
83
+ ## Architecture
84
+
85
+ ```mermaid
86
+ flowchart LR
87
+ Web[Streamlit Web App] --> API[StudyForge public API]
88
+ CLI[studyforge CLI] --> API
89
+ Python[Other Python projects] --> API
90
+ API --> PDF[PyMuPDF reader]
91
+ API --> Dictionary[Offline ECDICT database]
92
+ API --> CEFR[Reliable partial CEFR profile]
93
+ API --> Ranker[Vocabulary ranking / IELTS mode]
94
+ Ranker --> Exporters[Anki CSV / CSV / JSON exporters]
95
+ ```
96
+
97
+ Web、CLI 與 Python API 共用同一套 reader、dictionary、CEFR、ranking 與
98
+ exporter,沒有複製三份邏輯。
99
+
100
+ StudyForge 不使用生成式 AI。中文意思、詞性、音標與詞形資料來自專案內的
101
+ 離線詞典;例句取自使用者上傳的 PDF。
102
+
103
+ ## Installation
104
+
105
+ ### 系統需求
106
+
107
+ - Python 3.11 或 3.12(公開部署建議 3.12)
108
+ - pip
109
+ - Git(只有 clone 或貢獻程式時需要)
110
+
111
+ ### Windows 快速安裝
112
+
113
+ 1. 安裝 [Python](https://www.python.org/downloads/),並勾選
114
+ **Add python.exe to PATH**。
115
+ 2. 下載或 clone 此儲存庫。
116
+ 3. 雙擊 `setup.bat`。
117
+ 4. 安裝完成後雙擊 `run.bat`。
118
+
119
+ `run.bat` 會啟動網站並開啟 `http://localhost:8501`。
120
+
121
+ ### 安裝 CLI 與 Python package
122
+
123
+ PyPI 套件尚未正式發布。從原始碼安裝:
124
+
125
+ ```bash
126
+ git clone https://github.com/gfr211306-crypto/StudyForge.git
127
+ cd StudyForge
128
+ python -m pip install -e .
129
+ ```
130
+
131
+ 若也要執行 Web App:
132
+
133
+ ```bash
134
+ python -m pip install -e ".[web]"
135
+ ```
136
+
137
+ ### Windows PowerShell
138
+
139
+ ```powershell
140
+ git clone https://github.com/gfr211306-crypto/StudyForge.git
141
+ cd StudyForge
142
+ python -m venv .venv
143
+ .\.venv\Scripts\Activate.ps1
144
+ python -m pip install --upgrade pip
145
+ python -m pip install -r requirements.txt
146
+ streamlit run app.py
147
+ ```
148
+
149
+ ### macOS / Linux
150
+
151
+ ```bash
152
+ git clone https://github.com/gfr211306-crypto/StudyForge.git
153
+ cd StudyForge
154
+ python3 -m venv .venv
155
+ source .venv/bin/activate
156
+ python -m pip install --upgrade pip
157
+ python -m pip install -r requirements.txt
158
+ streamlit run app.py
159
+ ```
160
+
161
+ ## Usage
162
+
163
+ ### Web App
164
+
165
+ 1. 啟動 StudyForge。
166
+ 2. 上傳文字可以被反白選取的英文 PDF。
167
+ 3. 在側邊欄選擇單字數量、難度與最低出現次數。
168
+ 4. 等待 StudyForge 擷取文字並整理單字。
169
+ 5. 在表格中修正中文意思、詞性或例句,取消不需要的項目。
170
+ 6. 選擇 Anki CSV、普通 CSV 或 JSON 後下載。
171
+
172
+ ### CLI
173
+
174
+ 最基本的 Anki 匯出:
175
+
176
+ ```bash
177
+ studyforge extract file.pdf --limit 30 --format anki
178
+ ```
179
+
180
+ IELTS mode 與 JSON:
181
+
182
+ ```bash
183
+ studyforge extract file.pdf \
184
+ --mode ielts \
185
+ --limit 50 \
186
+ --format json \
187
+ --output ielts-vocabulary.json
188
+ ```
189
+
190
+ 支援的選項:
191
+
192
+ ```text
193
+ --mode balanced|basic|intermediate|advanced|ielts
194
+ --format anki|csv|json
195
+ --limit 1-500
196
+ --min-occurrences 1-100
197
+ --output FILE
198
+ ```
199
+
200
+ 未指定 `--output` 時,CLI 會在目前目錄建立
201
+ `<pdf-name>_<format>.csv` 或 `.json`。使用 `--output -` 可輸出至 stdout。
202
+
203
+ 也可以不安裝 console script:
204
+
205
+ ```bash
206
+ python -m studyforge extract file.pdf --format csv
207
+ ```
208
+
209
+ ### Python API
210
+
211
+ ```python
212
+ from studyforge import StudyForge, analyze_pdf, export_vocabulary
213
+
214
+ # Convenience function
215
+ result = analyze_pdf(
216
+ "file.pdf",
217
+ limit=30,
218
+ mode="ielts",
219
+ )
220
+
221
+ for item in result.items:
222
+ print(item.word, item.cefr_level, item.is_ielts)
223
+
224
+ anki_bytes = export_vocabulary(result.items, "anki")
225
+ json_bytes = export_vocabulary(result.items, "json")
226
+
227
+ # Reuse one service instance for multiple PDFs
228
+ engine = StudyForge()
229
+ another_result = engine.analyze_file("another.pdf", mode="balanced")
230
+ ```
231
+
232
+ 主要 public API:
233
+
234
+ ```text
235
+ StudyForge
236
+ analyze_pdf
237
+ analyze_pdf_bytes
238
+ AnalysisResult
239
+ VocabularyItem
240
+ CEFRProfile
241
+ export_vocabulary
242
+ export_rows
243
+ ```
244
+
245
+ ### 匯入 Anki
246
+
247
+ 1. 在 Anki 選擇 **檔案 → 匯入**。
248
+ 2. 選擇 StudyForge 下載的 CSV。
249
+ 3. 對應欄位:`Front`、`Back`、`Tags`。
250
+ 4. 勾選允許欄位使用 HTML。
251
+ 5. 確認分隔符號為逗號後匯入。
252
+
253
+ ### PDF 限制
254
+
255
+ | 類型 | 支援狀態 |
256
+ | --- | --- |
257
+ | 一般文字型 PDF | 支援 |
258
+ | 密碼保護 PDF | 請先解除密碼 |
259
+ | 掃描圖片 PDF | 請先使用 OCR |
260
+ | 超過 25 MB | 請先壓縮或分割 |
261
+ | 超過 400 頁 | 請先分割 |
262
+
263
+ ## Streamlit Community Cloud deployment
264
+
265
+ 本儲存庫已符合 Community Cloud 的基本檔案配置:
266
+
267
+ ```text
268
+ app.py
269
+ requirements.txt
270
+ .streamlit/config.toml
271
+ studyforge/data/studyforge_dictionary.db
272
+ studyforge/data/cefr_levels.json
273
+ ```
274
+
275
+ 部署時使用:
276
+
277
+ | 設定 | 值 |
278
+ | --- | --- |
279
+ | Repository | `gfr211306-crypto/StudyForge` |
280
+ | Branch | `main` |
281
+ | Main file path | `app.py` |
282
+ | Python version | `3.12` |
283
+ | Secrets | 不需要 |
284
+
285
+ `requirements.txt` 只包含網站執行依賴;pytest 位於
286
+ `requirements-dev.txt`,不會增加 Community Cloud 的部署負擔。
287
+
288
+ ## Testing
289
+
290
+ 先安裝開發依賴:
291
+
292
+ ```bash
293
+ python -m pip install -r requirements-dev.txt
294
+ ```
295
+
296
+ 執行完整檢查:
297
+
298
+ ```bash
299
+ python -m pip check
300
+ python scripts/audit_repository.py
301
+ python -m pytest -q
302
+ python -m compileall -q app.py studyforge scripts tests
303
+ ```
304
+
305
+ GitHub Actions 會在每次 push、pull request 與手動觸發時,於 Python 3.11
306
+ 及 3.12 執行相同的依賴檢查、儲存庫掃描、pytest、編譯檢查、package
307
+ build 與 CLI smoke test。
308
+
309
+ 建立 wheel 與 source distribution:
310
+
311
+ ```bash
312
+ python -m build
313
+ ```
314
+
315
+ ## Project structure
316
+
317
+ ```text
318
+ StudyForge/
319
+ ├─ .github/
320
+ │ ├─ ISSUE_TEMPLATE/ # Bug 與功能建議表單
321
+ │ ├─ workflows/ci.yml # GitHub Actions CI
322
+ │ └─ dependabot.yml
323
+ ├─ .streamlit/config.toml # Streamlit 公開部署設定
324
+ ├─ app.py # Streamlit 入口檔
325
+ ├─ data/
326
+ │ ├─ NOTICE.md
327
+ │ ├─ NOTICE_CEFR.md
328
+ │ └─ LICENSE_ECDICT.txt
329
+ ├─ samples/ # 可直接上傳測試的教材
330
+ ├─ scripts/
331
+ │ ├─ audit_repository.py # 敏感檔案與秘密掃描
332
+ │ ├─ build_cefr_data.py # 重建可靠 CEFR mapping
333
+ │ └─ build_dictionary.py # 從 ECDICT 重建詞典
334
+ ├─ studyforge/
335
+ │ ├─ api.py # Web/CLI 共用 public API
336
+ │ ├─ cli.py # studyforge extract
337
+ │ ├─ cefr.py # CEFR 查詢與 unknown policy
338
+ │ ├─ exporter.py # Anki CSV/CSV/JSON
339
+ │ ├─ vocabulary.py # 排序與 IELTS mode
340
+ │ └─ data/ # wheel 內含詞典與 CEFR mapping
341
+ ├─ tests/ # pytest 測試
342
+ ├─ pyproject.toml # PyPI package metadata
343
+ ├─ CONTRIBUTING.md
344
+ ├─ SECURITY.md
345
+ ├─ requirements.txt # 公開部署執行依賴
346
+ └─ requirements-dev.txt # 開發與測試依賴
347
+ ```
348
+
349
+ ## Privacy and security
350
+
351
+ - **本機執行:** PDF 只在你的電腦處理。
352
+ - **公開部署:** PDF 會傳送至執行 StudyForge 的 Streamlit 伺服器。
353
+ - PDF 不會被送往外部翻譯服務或 AI API。
354
+ - 專案不會主動把 PDF 或擷取文字寫入永久檔案。
355
+ - 分析結果只保留於目前使用者的 Streamlit session。
356
+ - 公開部署不適合機密、醫療、法律或含大量個資的文件。
357
+ - 回報問題時,請勿把真實敏感 PDF 上傳到公開 GitHub Issue。
358
+
359
+ 安全問題請參閱 [SECURITY.md](SECURITY.md)。
360
+
361
+ ## Contributing
362
+
363
+ 歡迎 Bug 修正、測試、文件與功能改善。開始前請閱讀
364
+ [CONTRIBUTING.md](CONTRIBUTING.md),並使用專案提供的 Issue templates。
365
+
366
+ 基本流程:
367
+
368
+ 1. Fork 儲存庫並建立功能分支。
369
+ 2. 安裝 `requirements-dev.txt`。
370
+ 3. 修改程式並補充測試。
371
+ 4. 通過完整測試與 repository audit。
372
+ 5. 建立內容聚焦的 Pull Request。
373
+
374
+ 參與者請遵守 [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)。
375
+
376
+ ## Roadmap
377
+
378
+ - [x] PDF 文字擷取
379
+ - [x] 離線英中詞典與繁體中文轉換
380
+ - [x] 原文例句與 Anki CSV
381
+ - [x] GitHub Actions、Issue forms 與公開部署設定
382
+ - [x] IELTS vocabulary mode
383
+ - [x] CEFR A1–C2 可靠部分映射與 `unknown`
384
+ - [x] CLI、Python API、普通 CSV 與 JSON
385
+ - [x] 可建立 wheel 與 source distribution 的 `pyproject.toml`
386
+ - [ ] OCR 掃描型 PDF 支援
387
+ - [ ] 使用者自訂停用詞
388
+ - [ ] 單字清單去重與手動新增功能
389
+ - [ ] 更多 Anki 卡片模板
390
+ - [ ] 無障礙與手機版操作改善
391
+ - [ ] 多語言介面
392
+
393
+ ## Vocabulary data and CEFR policy
394
+
395
+ 離線詞典由 [ECDICT](https://github.com/skywind3000/ECDICT) 資料篩選轉換而成。
396
+ 詞典來源與授權說明請見 [data/NOTICE.md](data/NOTICE.md) 與
397
+ [data/LICENSE_ECDICT.txt](data/LICENSE_ECDICT.txt)。
398
+
399
+ CEFR mapping 由 CEFR-J 1.5 與 Octanove C1/C2 1.0 建置。StudyForge 只保留
400
+ 同一 normalized headword 在來源中一致的級別;若不同詞性或語義對應不同級別,
401
+ 就不做猜測並輸出 `unknown`。目前 bundled mapping 有約 7,900 個無歧義詞條。
402
+ 來源、授權與處理規則請見 [data/NOTICE_CEFR.md](data/NOTICE_CEFR.md)。
403
+
404
+ ## License
405
+
406
+ StudyForge 程式碼採 [MIT License](LICENSE)。
407
+
408
+ 第三方詞典資料保留其原始 MIT 授權與版權聲明。