wwwjdic
© 2014-2021 Marco Bresciani
This file is part of wwwjdic.
wwwjdic is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
wwwjdic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with wwwjdic. If not, see http://www.gnu.org/licenses/.
SPDX-FileCopyrightText: 2014-2021 Marco Bresciani
SPDX-License-Identifier: GFDL-1.3-or-later -->
WWWJDic
This gem uses WWWJDic Backdoor Entry/API to interact with WWWJDic and translate to and from Japanese language.
This gem uses WWWJDic Backdoor Entry/API as described by
http://www.edrdg.org/wwwjdic/wwwjdicinf.html#backdoor_tag to interact
with WWWJDic and translate to and from Japanese language.
WWWJDic is an online Japanese translation server made by Jim Breen and
available at http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic?1C.
GNU GPLv3 license; source code available through anonymous checkout:
hg clone http://hg.savannah.nongnu.org/hgweb/wwwjdic/ or write me, and
I'll send it.
You can even decide to contribute to this little free software project
by registering to Savannah and ask to be part of the wwwjdic project!
Table of Contents
Background
This gem uses WWWJDic Backdoor Entry/API as described by http://www.edrdg.org/wwwjdic/wwwjdicinf.html#backdoor_tag to interact with WWWJDic and translate to and from Japanese language.
WWWJDic is an online Japanese translation server made by Jim Breen and available at http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic?1C.
Jim Breen's Japanese Page lists this gem: http://nihongo.monash.edu/japanese.html#links_software and has allowed the use of the same name.
GNU GPLv3 license; source code available through anonymous checkout:
hg clone http://hg.savannah.nongnu.org/hgweb/wwwjdic/ or write me, and
I'll send it.
You can even decide to contribute to this little free software project
by registering to Savannah and ask to be part of the wwwjdic project!
With great contributions from: Jim Breen, 新部裕, Jon Maken.
Install
RubyGems is the preferred easy install method for WWWJDic.
WWWJDic should be installed via the
RubyGems system.
To get the latest version, simply enter the following into your command
prompt: gem install wwwjdic.
Because WWWJDic is pure Ruby, it should run pretty much anywhere, including Rubinius, JRuby, MacRuby, etc. Officially the support is for >= 3.0 MJIT.
Savannah
- Project page: https://savannah.nongnu.org/projects/wwwjdic/
- Source code (Mercurial) repository: http://hg.savannah.gnu.org/hgweb/wwwjdic/
- Known Bugs: https://savannah.nongnu.org/bugs/?group=wwwjdic
- Users Mailing List: https://savannah.nongnu.org/mail/?group=wwwjdic
- News: https://savannah.nongnu.org/news/?group=wwwjdic
RubyGems
- Gem page: https://rubygems.org/gems/wwwjdic
- Online RDoc: http://rubydoc.info/gems/wwwjdic/
- Gem updates Atom Feed: https://rubygems.org/gems/wwwjdic/versions.atom
Usage
See examples folder.
To run the examples just run rubyEXAMPLE_NAME.rb.
Running the examples you'll see both the example description and correct
code usage to perform such action.
Here below there are the currently available examples:
- The
basics.rbexample (runruby examples/basics.rb) shows how to initialize and use a WWWJDic object through thebreenerfactory method; - The
uri.rbexample (runruby examples/uri.rb) shows how to ask for different types of translation URIs at WWWJDic, with all available options and configurations. - The
translate.rbexample (runruby examples/translate.rb) shows how to ask for an actual translation through WWWJDic Backdoor/API, with all available options and configurations. It will also show how to download such translation;
Using this API is pretty simple.
First, remember that this API maintains a context, so you can save your
preferred configuration of server, dictionary, output formats, ... by
assigning those value to your object.
Get a reference to the WWWJDic object, through its factory method, with
my_wwwjdic = WWWJDic::breener.
This will save a WWWJDic instance in your my_wwwjdic object.
At this point the object does contain a default configuration in terms
of dictionary, server, ...
You can take a look at the current status/configuration of your
my_wwwjdic object using the dictionary method
my_wwwjdic.dictionary that shows the dictionary currently in use
(default is Jpn-Eng General (EDICT)), or using the server method
my_wwwjdic.server that shows the dictionary server currently in use
(default is http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic.cgi?).
dictionary: you can set your own dictionary through the samedictionarymethod, by assigning it one of the available dictionaries, either using the dictionary number, or the (exact) dictionary name.
| Number | Dictionary Name | |:------:|---------------------------| | 1 | Jpn-Eng General (EDICT) | | 2 | Japanese Names (ENAMDICT) | | 3 | Computing/Telecomms | | 4 | Life Sciences/Bio-Med | | 5 | Legal Terms | | 6 | Finance/Marketing | | 7 | Buddhism | | 8 | Miscellaneous | | 9 | Special Text-glossing | | A | Engineering/Science | | B | Linguistics | | C | River & Water Systems | | D | Automobile Industry | | E | Japanese Wordnet | | F | Work-in-progress File | | G | Japanese-German (WaDoku) | | H | Japanese-French | | I | Japanese-Russian | | J | Japanese-Swedish | | K | Japanese-Hungarian | | L | Japanese-Spanish | | M | Japanese-Dutch | | N | Japanese-Slovenian | | O | Japanese-Italian | | P | Untranslated | | Q | Combined Jpn-Eng | | R | Expanded Text-glossing |
For example, with my_wwwjdic.dictionary = '7' you set the Buddhism
dictionary or with my_wwwjdic.dictionary = 'Japanese Wordnet' you
just set the Japanese Wordnet one.
Your my_wwwjdic object saves and maintains these values unless
reset.
server: you can set your own server through the sameservermethod, by assigning it one of the available servers. Usingmy_wwwjdic.server = :edrdgthe library will use the main (default) URL at http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic.cgi? for the dictionary server while instead usingmy_wwwjdic.server = :monashwill use the URL http://nihongo.monash.edu/cgi-bin/wwwjdic? that relays on Monash University mirror.uri: you can ask for a translation reference URL; that is not a translation by itself, but it's the full URL where to find the translation.- You can get the translation URL of a specific word using the command
my_wwwjdic.uri 'word'that returns the normal URL. - Then you can use the
my_wwwjdic.raw_uri 'word', for the raw display format. The raw dictionary display option is useful for calls from other programs, smartphones, etc. It omits all header and footer information from the pages, and displays the unedited dictionary entries in EDICT and KANJIDIC format, one-per-line and encapsulated by
. In this option the output is always in UTF-8 coding.... - the
my_wwwjdic.json_uri 'word'command, instead, returns the URL for translation ofwordin a JSON format as{ "word: "url" }with normal display format.
- You can get the translation URL of a specific word using the command
translate: you can, finaly, obviously ask for a specific translation using the configured parameters.- you can get a simple translation with the command
my_wwwjdic.translate 'word', that returns a string containing the web page content of the translation ofwordin the raw display format. It's equivalent tomy_wwwjdic.translate 'word', display: :raw. my_wwwjdic.translate 'word', nil, filename, regardless thenil(see it later), the thirdfilenameparameter is the name of the file where the translation will be saved into. Specifying thisfilenameparameter, the translation will not be shown, but it will be saved in the specified file.- Another possible result for translation is to get it in JSON format
also with the possibility to save it in a file:
my_wwwjdic.json_translate 'word', returns the JSON format of the translation: - The JSON will contain a field having the same name of the word to be translated that contains the URL of the translation from the reference dictionary server used. The URL is exatcly the same used to retrieve the translation and filling the resulting JSON.
- The
titlefield will contain the title of the translation page result. - The
translationfield will contain the raw translation as received from the server. - The
messagefield will contain all the text that will possibly be included as error message in the translation. This means that if any<p>tag encloses some text, such text will be presented in thismessagefield. - The
linesfield will contain an array of all the lines of the translation, that is: thelinesfield contains a split of thetranslationfield using its existing\ncharacters. - The
contentfield contains an array of JSON objects, each containing the formatted translation of each line:- a field with the name of the word asked for translation, containing the actual translation, first field of the translation in each line;
- a
kanafield with the kana writing for the translation, as shown in brackets, in each line; - a
textfield containing the explanation associated to such translation; - a
meaningsfield containing the different meaning associated to each line. The/characters mark the splitting point for each line.
So, basically, the JSON will contain the whole raw translation, the same translation split into different lines, when asked by the translation itself, and each of those lines above split again into a set of available meanings.
For the example translation above, the resulting JSON format is:
{ "word": "http://www.edrdg.org/cgi-bin/wwwjdic/wwwjdic.cgi?1ZDQword", "title": "WWWJDIC: Word Display", "translation": "伝言 [つてこと] /(n) (1) (See 伝言・でんごん) verbal message/word (from someone)/(n) (2) rumour/rumor/\n伝言 [でんごん] /(n,vs) verbal message/word (from someone)/(P)/\n一議 [いちぎ] /(n) word (opinion, objection)/\n言の葉 [ことのは;ことのえ] /(n) (1) (arch) word/(n) (2) (See 和歌) waka (classic Japanese poem, esp. a tanka)/\nワード /(n) (1) word/(n) (2) {comp} word/(n) (3) {comp} Word/Microsoft Word/(P)/\n語 [ご] /(n,n-suf) (1) language/(n,n-suf,ctr) (2) word/(P)/\n単語 [たんご] /(n,adj-no) {ling} word/vocabulary/(usually) single-character word/(P)/\n訪れ [おとずれ] /(n) (1) visit/call/(n) (2) arrival (e.g. of spring)/advent/coming/appearance/(n) (3) news/tidings/word/(P)/\n音沙汰;音さた [おとさた] /(n) news (from someone)/word/contact/\n言 [げん(P);こと] /(n) word/remark/statement/(P)/\n知らせ(P);報せ [しらせ] /(n) (1) (See お知らせ) news/word/tidings/notice/notification/information/(n) (2) omen/(P)/\n言葉(P);詞;辞 [ことば(P);けとば(言葉)(ok)] /(n) (1) (See 言語) language/dialect/(n) (2) (See 単語) word/words/phrase/term/expression/remark/(n) (3) speech/(manner of) speaking/(n) (4) learning to speak/language acquisition/(P)/", "message": null, "lines": [ "伝言 [つてこと] /(n) (1) (See 伝言・でんごん) verbal message/word (from someone)/(n) (2) rumour/rumor/", "伝言 [でんごん] /(n,vs) verbal message/word (from someone)/(P)/", "一議 [いちぎ] /(n) word (opinion, objection)/", "言の葉 [ことのは;ことのえ] /(n) (1) (arch) word/(n) (2) (See 和歌) waka (classic Japanese poem, esp. a tanka)/", "ワード /(n) (1) word/(n) (2) {comp} word/(n) (3) {comp} Word/Microsoft Word/(P)/", "語 [ご] /(n,n-suf) (1) language/(n,n-suf,ctr) (2) word/(P)/", "単語 [たんご] /(n,adj-no) {ling} word/vocabulary/(usually) single-character word/(P)/", "訪れ [おとずれ] /(n) (1) visit/call/(n) (2) arrival (e.g. of spring)/advent/coming/appearance/(n) (3) news/tidings/word/(P)/", "音沙汰;音さた [おとさた] /(n) news (from someone)/word/contact/", "言 [げん(P);こと] /(n) word/remark/statement/(P)/", "知らせ(P);報せ [しらせ] /(n) (1) (See お知らせ) news/word/tidings/notice/notification/information/(n) (2) omen/(P)/", "言葉(P);詞;辞 [ことば(P);けとば(言葉)(ok)] /(n) (1) (See 言語) language/dialect/(n) (2) (See 単語) word/words/phrase/term/expression/remark/(n) (3) speech/(manner of) speaking/(n) (4) learning to speak/language acquisition/(P)/" ], "content": [ { "word": "伝言", "kana": "つてこと", "text": "(n)(1) (See 伝言・でんごん) verbal message/word (from someone)/(n) (2) rumour/rumor", "meanings": [ "(n) (1) (See 伝言・でんごん) verbal message", "word (from someone)", "(n) (2) rumour", "rumor" ] }, { "word": "伝言", "kana": "でんごん", "text": "(n,vs) verbal message/word (from someone)/(P)", "meanings": [ "(n,vs) verbal message", "word (from someone)", "(P)" ] }, { "word": "一議", "kana": "いちぎ", "text": "(n) word (opinion, objection)" }, { "word": "言の葉", "kana": "ことのは;ことのえ", "text": "(n) (1) (arch) word/(n) (2) (See 和歌) waka (classic Japanese poem, esp. a tanka)", "meanings": [ "(n) (1) (arch) word", "(n) (2) (See 和歌) waka (classic Japanese poem, esp. a tanka)" ] }, { "kana": "ワード", "word": "ワード", "text": "(n) (1) word/(n) (2) {comp} word/(n) (3) {comp} Word/Microsoft Word/(P)", "meanings": [ "(n) (1) word", "(n) (2) {comp} word", "(n) (3) {comp} Word", "Microsoft Word", "(P)" ] }, { "word": "語", "kana": "ご", "text": "(n,n-suf) (1) language/(n,n-suf,ctr) (2) word/(P)", "meanings": [ "(n,n-suf) (1) language", "(n,n-suf,ctr) (2) word", "(P)" ] }, { "word": "単語", "kana": "たんご", "text": "(n,adj-no) {ling} word/vocabulary/(usually) single-character word/(P)", "meanings": [ "(n,adj-no) {ling} word", "vocabulary", "(usually) single-character word", "(P)" ] }, { "word": "訪れ", "kana": "おとずれ", "text": "(n) (1) visit/call/(n) (2) arrival (e.g. of spring)/advent/coming/appearance/(n) (3) news/tidings/word/(P)", "meanings": [ "(n) (1) visit", "call", "(n) (2) arrival (e.g. of spring)", "advent", "coming", "appearance", "(n) (3) news", "tidings", "word", "(P)" ] }, { "word": "音沙汰;音さた", "kana": "おとさた", "text": "(n) news (from someone)/word/contact", "meanings": [ "(n) news (from someone)", "word", "contact" ] }, { "word": "言", "kana": "げん(P);こと", "text": "(n) word/remark/statement/(P)", "meanings": [ "(n) word", "remark", "statement", "(P)" ] }, { "word": "知らせ(P);報せ", "kana": "しらせ", "text": "(n) (1) (See お知らせ) news/word/tidings/notice/notification/information/(n) (2) omen/(P)", "meanings": [ "(n) (1) (See お知らせ) news", "word", "tidings", "notice", "notification", "information", "(n) (2) omen", "(P)" ] }, { "word": "言葉(P);詞;辞", "kana": "ことば(P);けとば(言葉)(ok)", "text": "(n) (1) (See 言語) language/dialect/(n) (2) (See 単語) word/words/phrase/term/expression/remark/(n) (3) speech/(manner of) speaking/(n) (4) learning to speak/language acquisition/(P)", "meanings": [ "(n) (1) (See 言語) language", "dialect", "(n) (2) (See 単語) word", "words", "phrase", "term", "expression", "remark", "(n) (3) speech", "(manner of) speaking", "(n) (4) learning to speak", "language acquisition", "(P)" ] } ] }Please note that the resulting JSON is not pretty-printed, as shown here.
- you can get a simple translation with the command
Now let's come to the second parameter of the methods above (set to
nilin the examples), the arguments for the translation. The default is to translate to/from English/Japanese with normal display layout and no other specificities, except that the API automatically identifies Japanese or English and manages the romaji and so on. The returned URL is the default EDR&DG one, as required by Jim Breen himself. What if the user wants to customize something? Theargs, second parameter of all those methods above, is a dictionary (hash map) that allows specifying which parameters and to which values they shall be set.
Valid parameters, and their values are:
* dict parameter allows both numbers and (exact) strings to select
dictionaries:
| Number | Dictionary Name |
|:------:|---------------------------|
| 1 | Jpn-Eng General (EDICT) |
| 2 | Japanese Names (ENAMDICT) |
| 3 | Computing/Telecomms |
| 4 | Life Sciences/Bio-Med |
| 5 | Legal Terms |
| 6 | Finance/Marketing |
| 7 | Buddhism |
| 8 | Miscellaneous |
| 9 | Special Text-glossing |
| A | Engineering/Science |
| B | Linguistics |
| C | River & Water Systems |
| D | Automobile Industry |
| E | Japanese Wordnet |
| F | Work-in-progress File |
| G | Japanese-German (WaDoku) |
| H | Japanese-French |
| I | Japanese-Russian |
| J | Japanese-Swedish |
| K | Japanese-Hungarian |
| L | Japanese-Spanish |
| M | Japanese-Dutch |
| N | Japanese-Slovenian |
| O | Japanese-Italian |
| P | Untranslated |
| Q | Combined Jpn-Eng |
| R | Expanded Text-glossing |
* `display` parameter to select the final format of the referred
HTML page (either regular HTML or raw): `:regular`, `:raw`.
* `server` allows the user to select from the default URL (at
Electronic Dictionaries R&D Group) or the Monash university URL:
`:edrdg`, `:monash`.
Some examples of these parameters' usage:
my_wwwjdic.translate 'Sprache', dict: 'G', key: english, this translates using theFdictionary, that is the German onemy_wwwjdic.uri 'Sprache', dict: 'G', same as above, but returns the translation URL, insteadmy_wwwjdic.raw_uri 'Sprache', dict: 'G', same as above, but returns the translation URL with raw display, insteadmy_wwwjdic.uri 'Sprache', dict: 'G', display: raw
Maintainers
Thanks
Contributor: Jim Breen
Author: Jon Maken, An HTTP/HTTPS/FTP file downloader library/CLI based upon MiniPortile's HTTP implementation. About An HTTP/HTTPS/FTP file downloader library/CLI based upon MiniPortile's HTTP implementation, please note that "License: 3-clause BSD". This license is GNU GPLv3 compatible according to http://www.gnu.org/licenses/license-list.en.html#ModifiedBSD.
FSIJ理事会の理事長、新部裕さんの日本語の翻訳。 Japanese translation by Yutaka Niibe, President of Free Software Initiative of Japan.
Thanks to Łukasz Niemier for his suggestions on possible improvements.
Contributing
WWWJDic tries to follow semantic versioning (see http://semver.org/).
There may be backward incompatible changes each time minor version
number changes, but that any tiny version number change should be bug
fixes and internal changes only.
Be sure to read the CHANGELOG each time we cut a new release and lock
your gems accordingly.
RDoc documentation available in the html folder.
The easiest way to get help with WWWJDic is to post a message to the
mailing list: http://lists.nongnu.org/mailman/listinfo/wwwjdic-users
Feel free to post any question there, developers are responsive and will be happy to help you figure out how to use WWWJDic, or help you determine whether it's the right tool for the task you are working on.
Please make your posts to the list as specific as possible, including code samples and output where relevant. Do not post any information that should not be shared publicly, and be sure to reduce your example code as much as possible so that those who are responding to your question can more easily see what the issue might be.
If you've found a bug, want to submit a patch, or have a feature
request, please enter a ticket into our bug tracker:
https://savannah.nongnu.org/bugs/?func=additem&group=wwwjdic
We strongly encourage adding bug reports with failing tests or at least a reduced example that demonstrates the problem.
Similarly, patches should include tests, API documentation, and an update to the manual where relevant. Feel free to clone early though and participate in the project, if you just want some feedback, or a code review before preparing your code to be merged.
If you are unsure about whether you've found a bug, or want to check to see whether we'd be interested in the feature you want to add before you start working on it, feel free to post to our mailing list.
License
SPDX-FileCopyrightText: 2014 Marco Bresciani
SPDX-License-Identifier: GFDL-1.3-or-later
(C) 2014 Marco Bresciani
This file is part of wwwjdic.
wwwjdic is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
wwwjdic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with wwwjdic. If not, see http://www.gnu.org/licenses/.