Num2words là một thư viện chuyển đổi các số như 42 thành các từ như bốn mươi hai. Nó hỗ trợ nhiều ngôn ngữ [tiếng Anh, tiếng Pháp, tiếng Tây Ban Nha, tiếng Đức và tiếng Litva] và thậm chí có thể tạo ra các số thứ tự như bốn mươi giây [nhìn thấy tính năng cuối cùng này là một chút lỗi vào lúc này]. is a library that converts numbers like 42 to words like forty-two. It supports multiple languages [English, French, Spanish, German and Lithuanian] and can even generate ordinal numbers like forty-second [altough this last feature is a bit buggy at the moment]. Dự án được lưu trữ trên //github.com/savoirfairelinux/num2words Cách dễ nhất để cài đặt num2words là sử dụng PIP:num2words is to use pip: Nếu không, bạn có thể tải xuống gói nguồn và sau đó thực thi: Có một chức năng chỉ sử dụng một chức năng: Bên cạnh đối số số, còn có hai đối số tùy chọn. Thứ tự: Một lá cờ Boolean cho biết sẽ trả về một số thứ tự thay vì một Hồng y. A boolean flag indicating to return an ordinal number instead of a cardinal one. Lang: Ngôn ngữ để chuyển đổi số. Các giá trị được hỗ trợ là: The language in which to convert the number. Supported values are: en [tiếng Anh, mặc định] [English, default] fr [tiếng Pháp] [French] de [tiếng Đức] [German] es [tiếng Tây Ban Nha] [Spanish]num2words - chuyển đổi số thành từ bằng nhiều ngôn ngữ
Cài đặt
pip install num2words
python setup.py install
Cách sử dụng
>>> from num2words import num2words
>>> num2words[42]
forty-two
>>> num2words[42, ordinal=True]
forty-second
>>> num2words[42, lang='fr']
quarante-deux
LT [Litva] [Lithuanian]
LV [Latvian] [Latvian]
en_gb [tiếng Anh Anh] [British English]
en_in [tiếng Anh Ấn Độ] [Indian English]
Bạn có thể cung cấp các giá trị như FR_FR, mã sẽ được giải thích chính xác. Nếu bạn cung cấp một ngôn ngữ không được hỗ trợ, NotMementedError sẽ được nâng lên. Do đó, nếu bạn muốn gọi num2words với dự phòng, bạn có thể làm:fr_FR, the code will be correctly interpreted. If you supply an unsupported language, NotImplementedError is raised. Therefore, if you want to call num2words with a fallback, you can do:
try: return num2words[42, lang=mylang] except NotImplementedError: return num2words[42, lang='en']
Lịch sử
Num2words dựa trên một thư viện cũ, pynum2word được tạo bởi Taro Ogawa vào năm 2003. Thật không may, thư viện đã ngừng được duy trì và tác giả có thể đạt được. Có một nhà phát triển khác, Marius Grigaitis, người vào năm 2011 đã bổ sung sự hỗ trợ của Litva, nhưng đã không tiếp tục bảo trì dự án. is based on an old library , pynum2word created by Taro Ogawa in 2003. Unfortunately, the library stopped being maintained and the author can’t be reached. There was another developer, Marius Grigaitis, who in 2011 added Lithuanian support, but didn’t take over maintenance of the project.
Do đó, tôi đang dựa trên những cải tiến của Marius Grigaitis và xuất bản lại pynum2word dưới dạng num2words.pynum2word as num2words.
Virgil Dupras, Savoir-Faire Linux
Thay đổi
Phiên bản 0.5.2 - 2015/01/23
Đã thêm nội địa hóa Latvia. [#9]
Cải thiện nội địa hóa Tây Ban Nha. [ #10, #13, #14]
Cải thiện nội địa hóa Litva. [#12]
Phiên bản 0.5.1 - 2014/03/14
Đã thêm hỗ trợ Python 3 với 2to3. [#3]
Đã sửa những con số lớn bằng tiếng Tây Ban Nha. [#2]
Đã sửa lỗi trong thời gian Tanslation từ 30 đến 40 bằng tiếng Tây Ban Nha. [#4]
Đã sửa lỗi tham gia bằng tiếng Anh. [#số 8]
Phiên bản 0.5.0 - 2013/05/28
Đã tạo Num2Words dựa trên dự án Pynum2word cũ.num2words based on the old pynum2word project.
Mô-đun Num2Words trong Python, chuyển đổi số [như 34] thành các từ [như ba mươi tư]. Ngoài ra, thư viện này có hỗ trợ cho nhiều ngôn ngữ. Trong bài viết này, chúng ta sẽ thấy cách chuyển đổi số thành các từ bằng cách sử dụng num2words
Module.
Cài đặt có thể dễ dàng cài đặt num2words
bằng PIP.
One can easily install num2words
using pip.
pip install num2words
Hãy xem xét hai trích đoạn sau từ các tệp khác nhau được lấy từ 20 nhóm tin, cơ sở dữ liệu NLP phổ biến. Tiền xử lý 20 nhóm tin một cách hiệu quả vẫn là một vấn đề quan tâm.
Trong bài viết, Martin Preston viết: Tại sao không sử dụng thư viện PD C để đọc/viết các tệp TIFF? Tôi đã mất 20 phút để bắt đầu sử dụng chúng trong ứng dụng của riêng bạn.iscis VIII là lần thứ tám của một loạt các cuộc họp đã tập hợp các nhà khoa học và kỹ sư máy tính từ khoảng hai mươi quốc gia. Hội nghị năm nay sẽ được tổ chức tại Thành phố Khu nghỉ mát Địa Trung Hải xinh đẹp của Antalya, trong một khu vực giàu có về các địa điểm tự nhiên cũng như lịch sử.20 minutes to start using them in your own app.
ISCIS VIII is the eighth of a series of meetings which have brought together computer scientists and engineers from about twenty countries. This year’s conference will be held in the beautiful Mediterranean resort city of Antalya, in a region rich in natural as well as historical sites.
Trong hai trích đoạn trên, người ta có thể quan sát rằng số 20 20 xuất hiện ở cả hai dạng số và bảng chữ cái. Đơn giản chỉ cần làm theo các bước xử lý trước, liên quan đến mã thông báo, hóa hóa và vv sẽ không thể ánh xạ vào 20, và hai mươi vào cùng một thân cây, có tầm quan trọng theo ngữ cảnh. May mắn thay, chúng tôi có thư viện được xây dựng, num2words
giải quyết vấn đề này trong một dòng.
Dưới đây là việc sử dụng mẫu của công cụ.
from
num2words
python setup.py install1
num2words
python setup.py install3
python setup.py install4
python setup.py install5
python setup.py install6
Các
python setup.py install3
python setup.py install4
python setup.py install5
>>> from num2words import num2words >>> num2words[42] forty-two >>> num2words[42, ordinal=True] forty-second >>> num2words[42, lang='fr'] quarante-deux0
>>> from num2words import num2words >>> num2words[42] forty-two >>> num2words[42, ordinal=True] forty-second >>> num2words[42, lang='fr'] quarante-deux1
>>> from num2words import num2words >>> num2words[42] forty-two >>> num2words[42, ordinal=True] forty-second >>> num2words[42, lang='fr'] quarante-deux9
python setup.py install6
python setup.py install3
python setup.py install4
python setup.py install5
>>> from num2words import num2words >>> num2words[42] forty-two >>> num2words[42, ordinal=True] forty-second >>> num2words[42, lang='fr'] quarante-deux0
>>> from num2words import num2words >>> num2words[42] forty-two >>> num2words[42, ordinal=True] forty-second >>> num2words[42, lang='fr'] quarante-deux1
try: return num2words[42, lang=mylang] except NotImplementedError: return num2words[42, lang='en']6
python setup.py install6
python setup.py install3
python setup.py install4
python setup.py install5
>>> from num2words import num2words >>> num2words[42] forty-two >>> num2words[42, ordinal=True] forty-second >>> num2words[42, lang='fr'] quarante-deux0
>>> from num2words import num2words >>> num2words[42] forty-two >>> num2words[42, ordinal=True] forty-second >>> num2words[42, lang='fr'] quarante-deux1
pip install num2words3
python setup.py install6
python setup.py install3
python setup.py install4
python setup.py install5
pip install num2words8
>>> from num2words import num2words >>> num2words[42] forty-two >>> num2words[42, ordinal=True] forty-second >>> num2words[42, lang='fr'] quarante-deux1
thirty-six thirty-sixth 36th zero euro, thirty-six cents treinta y seis0
python setup.py install6
Output:
thirty-six thirty-sixth 36th zero euro, thirty-six cents treinta y seis
Do đó, trong bước xử lý trước, người ta có thể chuyển đổi tất cả các giá trị số thành các từ để có độ chính xác tốt hơn trong các giai đoạn tiếp theo.
Tài liệu tham khảo: //pypi.org/project/num2words/ //pypi.org/project/num2words/