mistval / unofficial-jisho-api

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

Associate furigana with phrases in searchForExamples #9

Closed Nonemoticoner closed 5 years ago

Nonemoticoner commented 5 years ago

I was looking at this feature and immediately spotted what is lacking or what would be great to have.

What we currently get is this:

今日はとても暑い きょうはとてもあつい It is very hot today.

From above you can't tell (at least not immediately and in more complex sentances you for sure gonna run in troubles) which kana is associated with which phrase written in kanjis. But on Jisho this is visible: https://jisho.org/sentences/5186634ed5dda7e981000029

I assume this would likely require implementation of new method i.e. scrapForExamples but I didn't investigate much so might be wrong.

mistval commented 5 years ago

I added this in new version 1.3.0, now on NPM.

It's part of the data returned from searchForExamples (that's already a scraper so I just had to add some code there) and also part of the example sentence data returned by scrapeForPhrase.

Now jisho.searchForExamples('今日はとても暑い') will give you the following:

{
  "query": "今日はとても暑い",
  "found": true,
  "results": [
    {
      "english": "It is very hot today.",
      "kanji": "今日はとても暑い。",
      "kana": "きょうはとてもあつい。",
      "pieces": [
        {
          "lifted": "きょう",
          "unlifted": "今日"
        },
        {
          "lifted": "",
          "unlifted": "は"
        },
        {
          "lifted": "",
          "unlifted": "とても"
        },
        {
          "lifted": "あつ",
          "unlifted": "暑い"
        }
      ]
    },
    {
      "english": "As it is very hot today, I don't feel like studying.",
      "kanji": "今日はとても暑いので勉強する気になれない。",
      "kana": "きょうはとてもあついのでべんきょうするきになれない。",
      "pieces": [
        {
          "lifted": "きょう",
          "unlifted": "今日"
        },
        {
          "lifted": "",
          "unlifted": "は"
        },
        {
          "lifted": "",
          "unlifted": "とても"
        },
        {
          "lifted": "あつ",
          "unlifted": "暑い"
        },
        {
          "lifted": "",
          "unlifted": "ので"
        },
        {
          "lifted": "べんきょう",
          "unlifted": "勉強する"
        },
        {
          "lifted": "き",
          "unlifted": "気になれない"
        }
      ]
    }
  ],
  "uri": "http://jisho.org/search/%E4%BB%8A%E6%97%A5%E3%81%AF%E3%81%A8%E3%81%A6%E3%82%82%E6%9A%91%E3%81%84%23sentences",
  "phrase": "今日はとても暑い"
}