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 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 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 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 www.edrdg.org/cgi-bin/wwwjdic/wwwjdic?1C.

Jim Breen's Japanese Page lists this gem: nihongo.monash.edu/japanese.html#links_software

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 >= 2.7 YARV/KRI.

Savannah

RubyGems

Usage

See examples folder. To run the examples just run ruby{EXAMPLE_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.rb example (run ruby examples/basics.rb) shows how to initialize and use a WWWJDic object through the breener factory method; * The uri.rb example (run ruby examples/uri.rb) shows how to ask for different types of translation URIs at WWWJDic, with all available options and configurations. * The translate.rb example (run ruby 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?).

| 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 same server method, by assigning it one of the available servers. Using my_wwwjdic.server = :edrdg the library will use the main (default) URL at www.edrdg.org/cgi-bin/wwwjdic/wwwjdic.cgi? for the dictionary server while instead using my_wwwjdic.server = :monash will use the URL 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 <pre> … </pre>. In this option the output is always in UTF-8 coding. * the my_wwwjdic.json_uri 'word' command, instead, returns the URL for translation of word in a JSON format as { "word: "url" } with normal display format. * 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 of word in the raw display format. It's equivalent to my_wwwjdic.translate 'word', display: :raw. * my_wwwjdic.translate 'word', nil, filename, regardless the nil (see it later), the third filename parameter is the name of the file where the translation will be saved into. Specifying this filename parameter, 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 title field will contain the title of the translation page result. * The translation field will contain the raw translation as received from the server. * The message field 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 this message field. * The lines field will contain an array of all the lines of the translation, that is: the lines field contains a split of the translation field using its existing \n characters. * The content field 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 kana field with the kana writing for the translation, as shown in brackets, in each line; * a text field containing the explanation associated to such translation; * a meanings field 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:
```json5
{
  "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.

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 the F dictionary, that is the German one * my_wwwjdic.uri 'Sprache', dict: 'G', same as above, but returns the translation URL, instead * my_wwwjdic.raw_uri 'Sprache', dict: 'G', same as above, but returns the translation URL with raw display, instead * my_wwwjdic.uri 'Sprache', dict: 'G', display: raw

Maintainers

Thanks

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 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 www.gnu.org/licenses/.