A Elixir library for translating between hiragana, katakana, romaji and kanji. It uses Mecab.
If available in Hex, the package can be installed as:
- Add exkanji to your list of dependencies in
mix.exs
:
def deps do
[{:exkanji, "~> 0.2"}]
end
- Exkanji package needs
nkf
andmecab
command and it needs to install those in your environment when you don't have those.
$ brew install nkf
$ brew install mecab mecab-ipadic
Exkanji provides some convinient functions in Exkanji module through Exkanji.Translator and Exkanji.Mecab. Those provided functions are able to translate into hiragana(ひらがな), katakana(カタカナ) and Romaji(ローマ字).
Into hiragana(ひらがな)
iex(1)> Exkanji.hiragana "a a A ア ア ァ ァ あ ぁ 亜"
"あ あ あ あ あ ぁ ぁ あ ぁ あ"
iex(2)> Exkanji.hiragana "平仮名 ひらがな hiragana"
"ひらがな ひらがな ひらがな"
Into katakana(カタカナ)
iex(3)> Exkanji.katakana "a a A ア ア ァ ァ あ ぁ 亜"
"ア ア ア ア ア ァ ァ ア ァ ア"
iex(4)> Exkanji.katakana "片仮名 かたかな katakana"
"カタカナ カタカナ カタカナ"
Into Romaji(ローマ字)
iex(5)> Exkanji.romaji "a a A ア ア ァ ァ あ ぁ 亜"
"a a a a a ァ ァ a ァ a"
iex(6)> Exkanji.romaji "ローマ字 ろーまじ ローマジ"
"ro-maji ro-maji ro-maji"
Exkanji is capable of detecting Part-of-Speech from text, As a Morphological Analyzer. It uses Mecab.
iex(1)> Exkanji.parse "エモい"
{:ok,
[%Exkanji.Mecab{base: "*", cform: "*", ctype: "*",
feature: "名詞,一般,*,*,*,*,*", hiragana: nil, pos: "名詞",
pos1: "一般", pos2: "*", pos3: "*", pron: nil, read: nil, romaji: nil,
surface: "エモ"},
%Exkanji.Mecab{base: "いる", cform: "一段", ctype: "連用形",
feature: "動詞,自立,*,*,一段,連用形,いる,イ,イ", hiragana: nil,
pos: "動詞", pos1: "自立", pos2: "*", pos3: "*", pron: "イ",
read: "イ", romaji: nil, surface: "い"}]}
It also makes to change that sets Mecab's dictionaly into second arguments in Exkanji.parse function.
iex(2)> Exkanji.parse "エモい", dict: "/opt/local/lib/mecab/dic/neologd-utf8"
{:ok,
[%Exkanji.Mecab{base: "エモい", cform: "*", ctype: "*",
feature: "名詞,固有名詞,一般,*,*,*,エモい,エモイ,エモイ",
hiragana: nil, pos: "名詞", pos1: "固有名詞", pos2: "一般",
pos3: "*", pron: "エモイ", read: "エモイ", romaji: nil,
surface: "エモい"}]}