Cutlet: A Japanese to Romaji Converter in Python

栏目: IT技术 · 发布时间: 4年前

内容简介:A few months ago I releasedCompared to other libraries cutlet has several advantages:The foreign spelling feature in particular is something I've never seen in another system, and in some cases is important for getting things right. For example, "Sweden Hi

A few months ago I released cutlet , a Python library and application for converting arbitrary Japanese text to romaji.

Cutlet: A Japanese to Romaji Converter in Python
Katsu curry illustrated by Irasutoya

Compared to other libraries cutlet has several advantages:

  • it uses fugashi , so you can re-use your existing dictionary
  • words of foreign origin optionally use their original spelling ("cutlet" instead of "katsu") thanks to Unidic
  • it's easy to add exceptions for specific words
  • a built-in slug mode for URL generation

The foreign spelling feature in particular is something I've never seen in another system, and in some cases is important for getting things right. For example, "Sweden Hills" is a neighborhood in Hokkaido, but even the Post Office data gives the romaji as the odd-looking "Suedenhiruzu". With cutlet the output would be "Sweden hill" and it's easy to add an exception if you want "Hills".

Here's an example of usage from Python:

from cutlet import Cutlet
katsu = Cutlet()
katsu.romaji("カツカレー")
# => 'Cutlet curry'
katsu.slug("カツカレー")
# => 'cutlet-curry'

One of my main motivations for making this library was dealing with the frequent case where using Japanese text isn't an option for technical reasons, or it is an option but comes with downsides. A common example is urls - while you can use Japanese text in URLs, in many situations the text becomes unreadable hex escapes, so it's not actually helpful for anyone. Generating an article slug in romaji creates something that can still be interpreted in Japanese and is free from any technical compatability worries.

cutlet is available for install via pip, and works on the command line as well as via Python. If you make use of it I'd love to hear about it. If there's a feature you'd like it to include feel free to open an issue . While I don't have any more major features planned, I would like to make a web version you can use to try it out; I'll post about that on Twitter if I ever get it set up. Ψ


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

社交电商

社交电商

[美] Stephan Spencer(斯蒂芬.斯宾塞)、[美] Jimmy Harding(吉米.哈丁)、[美] Jennifer Sheahan(詹尼弗.希汉) / 谭磊 / 电子工业出版社 / 2015-3 / 69.00元

你想要在互联网上赚钱吗?想要做好电子商务吗?那么你一定不能忽视社交媒体的力量。不管你想要营销的是实物商品、电子类产品还是本地的服务,这本书会教你怎么做。 《社交电商》全面介绍形形色色的社交媒体以及如何利用这些社交媒体来为你的企业做好服务。如果你经营得不好,在社交媒体上散发出的只是噪声而不是真正的信息。 而如果做得好,社交媒体会成为你最有效的营销工具,帮助你赢得老客户的拥戴,获得新的客户。 ......一起来看看 《社交电商》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

随机密码生成器
随机密码生成器

多种字符组合密码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具