pythainlp
pythainlp copied to clipboard
pythainlp.corpus.get_corpus_path() should not try to download the corpus automatically
เสนอว่าไม่ควรใช้ pythainlp.corpus.get_corpus_path() นั้นเรียกดาวน์โหลดแฟ้มโดยอัตโนมัติหากมันหาแฟ้มไม่เจอครับ ควรจะปล่อยให้ผู้ใช้ตัดสินใจเองมากกว่า
Current get_corpus_path() try to download the corpus file if it is not yet exist locally:
https://github.com/PyThaiNLP/pythainlp/blob/831a9fcfd24e069b6e929283b3abdc161a9a5608/pythainlp/corpus/core.py#L81
if db.search(query.name == name):
path = get_full_data_path(db.search(query.name == name)[0]["file"])
if not os.path.exists(path):
download(name)
I proposed that it shouldn't do that.
If the file is not exist, user/developer should get notified and decided if they want to download it or not (using API or using command line).
Currently, inside pythainlp module, every single call of get_corpus_path() do exactly that. They check if returned path is "true", if not they call pythainlp.corpus.download() by themselves:
- https://github.com/PyThaiNLP/pythainlp/blob/831a9fcfd24e069b6e929283b3abdc161a9a5608/pythainlp/tag/named_entity.py#L79
- https://github.com/PyThaiNLP/pythainlp/blob/831a9fcfd24e069b6e929283b3abdc161a9a5608/pythainlp/transliterate/thai2rom.py#L24
- https://github.com/PyThaiNLP/pythainlp/blob/831a9fcfd24e069b6e929283b3abdc161a9a5608/pythainlp/transliterate/thaig2p.py#L25
- https://github.com/PyThaiNLP/pythainlp/blob/831a9fcfd24e069b6e929283b3abdc161a9a5608/pythainlp/ulmfit/init.py#L134
- https://github.com/PyThaiNLP/pythainlp/blob/831a9fcfd24e069b6e929283b3abdc161a9a5608/pythainlp/word_vector/init.py#L23
So removing the auto-download inside pythainlp.corpus.get_corpus_path() will not change the behavior of those functions in submodules. (Anyway, it can be further discuss if we want to remove the auto-downloads from those submodules as well or not).
Proposed return values
I propose these for discussion:
- full path - if the corpus name is valid and the file is exist locally
- "" (empty string) - if the corpus name is valid but the file is not exist locally
- None - if the corpus name is not valid (not inside the corpus database)
เห็นด้วยครับ เราควรถามผู้ใช้งานก่อนว่ายินยอมไหม ความเห็นผม ผมคิดว่า ถ้าไม่พบ ให้ขึ้น Error ไปเลยว่าไม่พบ พร้อมกับบอกวิธีติดตั้ง corpus นั้น แต่ไม่ควรขึ้นถามว่าคุณไม่มี corpus นี้ ต้องการติดตั้งไหม? เพราะเพื่อป้องกันปัญหาเวลาคนนำไปใช้งานกับ Web api ที่อาจจะมองไม่เห็นครับ
อาจจะมี error message ให้มนุษย์รู้ และ raise FileNotFoundError เพื่อให้โปรแกรมจัดการต่อได้?
seems the issue has been solved?
ทำให้ทุกฟังก์ชันที่ต้องโหลด model หรือ dataset ให้มีฟังก์ชัน setup ไหมครับ หลักการ คือ ในการใช้งานครั้งแรก ให้ผู้ใช้งานเรียกฟังก์ชันนี้ก่อน โดยจะโชว์ license กับรายละเอียด ถ้าผู้ใช้งานยินยอมให้พิมพ์ y แต่จะโหลด model หรือ dataset
นอกจากนั้น ฟังก์ชัน setup สามารถยินยอมตามพารามิเตอร์ได้โดยตรง เผื่อผู้ใช้งานที่ไม่สะดวกมากดในคอมมาไลน์ เช่น setup(agree=True) โดยในโค้ดของเรา agree ค่าเริ่มต้นจะเป็น False
หากผู้ใช้งานไม่เคยเรียก พอเรียกใช้งานคำสั่งนั้นจะขึ้น Error แล้วอธิบายว่าให้เรียกฟังก์ชัน setup ก่อน
ไอเดียดี โดยให้มีไฟล์ config กำหนดไว้ และบันทึกไว้ว่าผู้ใช้เคยยอมรับเงื่อนไข model/dataset ไหนแล้ว
จริงๆ จำเป็นไมว่าต้องมีไฟล์ กำลังคิดอยู่ว่าถ้า user ยอมรับแล้ว ก็จะมี directory ข้อมูลอยู่ เราก้อเช็คจากตรงนั้นก้อได้ไหมน่ะ?