mistval / unofficial-jisho-api

Encapsulates the official Jisho.org API and also provides kanji, example, and stroke diagram search.
MIT License
137 stars 14 forks source link

Word Type Search #7

Open afortiori opened 5 years ago

afortiori commented 5 years ago

On jisho.org, it is possible to see the 'type' of word, for example, suru verb, godan verb etc. In the future would it be possible to get that information via the unofficial jisho api? I also now Jisho has a lot of information about inflection, being able to get that information would be super cool too.

mistval commented 5 years ago

Hi, I'll see if I can add that information when I have some time 👍

afortiori commented 5 years ago

Thanks! :)

mistval commented 5 years ago

I added a new scrapeForPhrase function to master that can get you the word type among other things. I need to test it a bit more and write documentation before I push a new version to NPM, but if you want to try it out now you can do npm install https://github.com/mistval/unofficial-jisho-api to install the master branch.

console.log(JSON.stringify(await jisho.scrapeForPhrase('ゆっくり'), null, 2)) returns the following:

{
  "found": true,
  "tags": [
    "Common word",
    "JLPT N5"
  ],
  "meanings": [
    {
      "seeAlsoTerms": [],
      "sentences": [],
      "meaning": "slowly; at ease; restful",
      "supplemental": [
        "Onomatopoeic or mimetic word"
      ],
      "meaningAbstract": "",
      "meaningTags": [
        "adverb",
        "noun",
        "suru verb",
        "adverb taking the 'to' particle"
      ]
    }
  ],
  "query": "ゆっくり",
  "uri": "https://jisho.org/word/%E3%82%86%E3%81%A3%E3%81%8F%E3%82%8A"
}

The word type is in the "meaningTags" property, it's the same as in the entry on Jisho.org.

As for the inflections, those are actually conjugated by JavaScript in the browser (here), so I'd have to do something like use Puppeteer to execute that code, I'll look into that some other time if I get a chance.

mistval commented 5 years ago

New version 1.2.0 on NPM has the above mentioned scrapeForPhrase function. Please see the README or jsdocs for more info.

afortiori commented 5 years ago

Wow, thanks! This is super cool.