【问题标题】:Convert fancy/artistic unicode text to ASCII将花哨/艺术 unicode 文本转换为 ASCII
【发布时间】:2021-11-28 10:04:10
【问题描述】:

我有一个 unicode 字符串,例如“?????????????????? ????????????????”并想将其转换为 ASCII 形式的“暴徒生活”。

我知道我可以在 Python 中实现这一点

import unidecode
print(unidecode.unidecode('???????????????? ????????????????'))
// thug life

但是,这也会关联我想要保留的其他 unicode 字符(例如中文/日文字符、表情符号、重音字符等)。

有没有办法检测这些类型的“艺术”Unicode 字符?

更多示例:

?????????????????? ??????????????????

?????????????????? ??????????????????

?????????????????? ??????????????????

生命的意义

感谢您的帮助!

【问题讨论】:

标签: python-3.x unicode ascii


【解决方案1】:
import unicodedata
strings = [
  '???? ????',
  '???? ????',
  '???? ????',
  '???? ????',
  'thug life']
for x in strings:
  print(unicodedata.normalize( 'NFKC', x), x)

输出.\62803325.py

thug life ???? ????
thug life ???? ????
thug life ???? ????
thug life ???? ????
thug life thug life

资源

【讨论】:

  • 不适用于以下情况:"? ? ?"、"?︎?︎?︎?︎"、"ωεłł"、"ʜᴀᴋsʜɪ"、"???"、"??? ”、“RᗅIPႮ”、“ғʀᴇᴇ”、“ᕼᗩᑭᑭIᗴᗴ”、“?υεεɴ”。
  • @GokulNC 你需要Romanization/transliteration of Unicode text恕我直言……另请参阅pypi.org/project/Unidecode
  • @GokulNC,您知道如何使用 python 将此类字体转换为 unicode 吗?如果是,请在此处评论您的方法。
  • 如上所述,Unidecode 能够清理大部分,尽管它并没有完全 100% 解决问题。
  • 是的,我也是这样。我想知道,如果你找到一种方法来规范化字体,如“? ? ?”、“?︎?︎?︎?︎”、“ωεłł”、“ʜᴀᴋsʜɪ”、“???”、“???” , "RᗅIPႮ", "ғʀᴇᴇ", "ᕼᗩᑭᑭIᗴᗴ", "?υεεɴ" 你在评论中提到的。
猜你喜欢
  • 2015-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-04
相关资源
最近更新 更多