iki / unidecode Goto Github PK
View Code? Open in Web Editor NEWUnicode transliteration in Python (clone of Tomaž Šolc repository at zemanta.com)
Home Page: http://www.tablix.org/~avian/blog/archives/2009/01/unicode_transliteration_in_python/
Unicode transliteration in Python (clone of Tomaž Šolc repository at zemanta.com)
Home Page: http://www.tablix.org/~avian/blog/archives/2009/01/unicode_transliteration_in_python/
Unidecode ASCII transliterations of Unicode text EXAMPLE USE from unidecode import unidecode print unidecode(u"\u5317\u4EB0") # That prints: Bei Jing DESCRIPTION It often happens that you have non-Roman text data in Unicode, but you can't display it -- usually because you're trying to show it to a user via an application that doesn't support Unicode, or because the fonts you need aren't accessible. You could represent the Unicode characters as "???????" or "\15BA\15A0\1610...", but that's nearly useless to the user who actually wants to read what the text says. What Unidecode provides is a function, 'unidecode(...)' that takes Unicode data and tries to represent it in ASCII characters (i.e., the universally displayable characters between 0x00 and 0x7F). The representation is almost always an attempt at *transliteration* -- i.e., conveying, in Roman letters, the pronunciation expressed by the text in some other writing system. (See the example above) This is a Python port of Text::Unidecode Perl module by Sean M. Burke <[email protected]>. REQUIREMENTS Nothing except Python itself. You will need a Python build with "wide" Unicode characters in order for unidecode to work correctly with characters outside of Basic Multilingual Plane. Surrogate pair encoding of "narrow" builds is not supported. INSTALLATION You install Unidecode, as you would install any Python module, by running these commands: python setup.py install python setup.py test SUPPORT Questions, bug reports, useful code bits, and suggestions for Unidecode should be sent to [email protected] AVAILABILITY The latest version of Unidecode is available from the GIT repository at http://code.zemanta.com/tsolc/git/unidecode You can get it by running: git clone http://code.zemanta.com/tsolc/git/unidecode COPYRIGHT Original character transliteration tables: Copyright 2001, Sean M. Burke <[email protected]>, all rights reserved. Python code and later additions: Copyright 2011, Tomaz Solc <[email protected]> The programs and documentation in this dist are distributed in the hope that they will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. This library is free software; you can redistribute it and/or modify it under the same terms as Perl.
>>> unidecode("ى")
'~'
I'd expect anything, even simply removing it, just not tilde. I think "a" would be a good option, though I'm not an expert in Arabic.
Punchline: from builtins import str; str(unidecode(str('2b or not 2b')))
"b'2b or not 2b'"
>>> from unidecode import unidecode
>>> str(unidecode(str('2b or not 2b'))) # no problem
'2b or not 2b'
>>> from builtins import str
>>> str(unidecode(str('2b or not 2b'))) # big problem
"b'2b or not 2b'"
>>> str(str('2b or not 2b')) # str recursively all you want
'2b or not 2b'
>>> unidecode(str('2b or not 2b')) # `newbyte` obj is `repr`ed by unidecode
b'2b or not 2b'
>>> unidecode('2b or not 2b')
'2b or not 2b'
>>> unidecode(unidecode('2b or not 2b'))
'2b or not 2b'
>>> unidecode(unidecode(b'2b or not 2b'))
'2b or not 2b'
>>> unidecode(unidecode(str('2b or not 2b'))) # because future.builtins creates a newbytes type
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
...
AttributeError: encode method has been disabled in newbytes
>>> unidecode(str('2b or not 2b'))
b'2b or not 2b'
Why chinese character always coded as Pinyin?
Pinyin only used in Mandarin (PuTongHua),
Chinese people in Kwangtung, HongKong and Macao using Cantonese, not Mandarin!
setuptools is new and cool, distutils is old and broken
We use:
pip install https://codeload.github.com/iki/unidecode/legacy.zip/master
And this is producing this error:
Downloading/unpacking https://codeload.github.com/iki/unidecode/legacy.zip/master
Downloading master (230kB): 230kB downloaded
Running setup.py egg_info for package from https://codeload.github.com/iki/unidecode/legacy.zip/master
Traceback (most recent call last):
File "", line 16, in
File "/tmp/pip-esUArV-build/setup.py", line 62
url = 'https://github.com/iki/unidecode/'
SyntaxError: keyword argument repeated
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 16, in
File "/tmp/pip-esUArV-build/setup.py", line 62
url = 'https://github.com/iki/unidecode/'
SyntaxError: keyword argument repeated
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-esUArV-build
Storing complete log in /root/.pip/pip.log
@iki I would be happy to work on this and submit a PR.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.