Project

jmdict

0.0
No commit activity in last 3 years
No release in over 3 years
This gem parses the JMDict XML file to get a more friendly hash interface for its entries
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 10.0

Runtime

~> 1.7
 Project Readme

JMDict Gem

This is a simple gem that takes in an XML file containing the JMDict Japanese/English dictionary from the Electronic Dictionary Research and Development Group. To avoid dealing with the parsing of this complex file this gem gives the functionality of retrieving each entry in a Ruby Hash more friendly to just focus on the processing step.

Installation

Add this line to your application's Gemfile:

gem 'jmdict'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install jmdict

And use it in your application:

require 'jmdict'

Dependencies

This gem depends on nokogiri for XML parsing.

Usage

The usage is very simple, just do:

jmdict = JMDict.new("JMdict.xml")
jmdict.each_entry do |entry|
  # Here you can play with the entry
end

Example of an entry hash:

{"ent_seq"=>1000310,
  "k_ele"=>[{"keb"=>"馬酔木", "ke_inf"=>[], "ke_pri"=>[]}],
  "r_ele"=>[{"reb"=>"あせび", "re_nokanji"=>"", "re_restr"=>[], "re_inf"=>[], "re_pri"=>[]},
            {"reb"=>"あしび", "re_nokanji"=>"", "re_restr"=>[], "re_inf"=>[], "re_pri"=>[]},
            {"reb"=>"あせぼ", "re_nokanji"=>"", "re_restr"=>[], "re_inf"=>[], "re_pri"=>[]},
            {"reb"=>"あせぶ", "re_nokanji"=>"", "re_restr"=>[], "re_inf"=>[], "re_pri"=>[]},
            {"reb"=>"アセビ", "re_nokanji"=>"", "re_restr"=>[], "re_inf"=>[], "re_pri"=>[]}],
  "sense"=>[{"stagk"=>[], "stagr"=>[], "pos"=>["noun (common) (futsuumeishi)"], "xref"=>[], "ant"=>[],
            "field"=>[], "misc"=>["word usually written using kana alone"], "s_inf"=>[], "l_source"=>[], "dial"=>[], "gloss"=>[{"lang"=>nil, "gloss"=>"Japanese andromeda (Pieris japonica)"},{"lang"=>nil,"gloss"=>"lily-of-the-valley"}]},
            {"stagk"=>[], "stagr"=>[], "pos"=>[], "xref"=>[], "ant"=>[], "field"=>[], "misc"=>[], "s_inf"=>[], "l_source"=>[], "dial"=>[], "gloss"=>[{"lang"=>"dut", "gloss"=>"{plantk.} Japanse rotsheide"}, {"lang"=>"dut", "gloss"=>"Pieris japonica"}]},
            {"stagk"=>[], "stagr"=>[], "pos"=>[], "xref"=>[], "ant"=>[], "field"=>[], "misc"=>[], "s_inf"=>[], "l_source"=>[], "dial"=>[], "gloss"=>[{"lang"=>"dut", "gloss"=>"Ashibi {naam van een tanka-tijdschrift, 1903-1908}"}]},
            {"stagk"=>[], "stagr"=>[], "pos"=>[], "xref"=>[], "ant"=>[], "field"=>[], "misc"=>[], "s_inf"=>[], "l_source"=>[], "dial"=>[], "gloss"=>[{"lang"=>"dut", "gloss"=>"Ashibi {sedert 1928 de naam van het vanaf 1922 gepubliceerde haiku-tijdschrift Hamayumi 破魔弓}"}, {"lang"=>"dut", "gloss"=>"{plantk.} Japanse rotsheide"}, {"lang"=>"dut", "gloss"=>"Pieris japonica"}]},
            {"stagk"=>[], "stagr"=>[], "pos"=>[], "xref"=>[], "ant"=>[], "field"=>[], "misc"=>[], "s_inf"=>[], "l_source"=>[], "dial"=>[], "gloss"=>[{"lang"=>"ger", "gloss"=>"(f) Lavendelheide"}, {"lang"=>"ger", "gloss"=>"Pieris japonica"}]},
            {"stagk"=>[], "stagr"=>[], "pos"=>[], "xref"=>[], "ant"=>[], "field"=>[], "misc"=>[], "s_inf"=>[], "l_source"=>[], "dial"=>[], "gloss"=>[{"lang"=>"rus", "gloss"=>"(см.) あせび"}, {"lang"=>"rus", "gloss"=>"(бот.) подбел, Picris japonicum (D. Don.)"}]}]
}

Please read the DTD for more information and to know how to deal with this data. This is only a wrapper.

Versioning

I decided to put a version number that follows the same pattern as the official DTD revision version for aknowledge the compatibility of this gem with the XML file used. The minor number is reserved for bugfixes or changes of the gem.

Performance

In matter of time we have a notable increase for converting the Node element into a Hash. Using this gem therefore takes more time than dealing with Nokogiri directly but it's aimed for a one shot use for processing the XML file and brings a more unified form of accessing all the fields.

License

The gem is available as open source under the terms of the MIT License.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/r-antonio/jmdict.