dgw / sopel-jisho

Jisho lookup plugin for Sopel IRC bots.
GNU General Public License v3.0
0 stars 0 forks source link

Improve output when there are multiple results #1

Open SnoopJ opened 1 year ago

SnoopJ commented 1 year ago

The Jisho plugin currently just spits out the first result. It would be helpful if the plugin response also included some information about other responses, even to indicate that they are present.

Example scenario:

<+SnoopJ> .jisho muri <+Sopel> [Jisho] 無理 (むり): unreasonable, unnatural, unjustifiable <+dgw> Not convinced that's the right muri

dgw commented 1 year ago

Spitballing: I've seen other word-lookup features (like Urban Dictionary via Rizon's Internets bot) send a notice to the calling user indicating that there are more results available. Internets in particular also outputs the first three definitions by default, not just one. Not sure I'd choose any of those implementation details, but they're out there.

Speaking of Urban Dictionary, both Internets and sopel-modules.urban support picking additional definitions (blindly) by appending /2 etc. to the query, up to /10; the full command is then e.g. .u frunk /3.

All that said, maybe this plugin should take more inspiration from Sopel's built-in (for now) wiktionary feature, which simply strings together as many definitions as it has space for, annotated by part of speech:

[wiktionary] test — noun: 1. A challenge, trial, 2. A cupel or cupelling hearth in which precious
metals are melted for trial and refinement, 3. (academia) An examination, given often during the
academic term — verb: 1. To challenge, 2. To refine (gold, silver, etc.) in a test or cupel; to
subject to cupellation, 3. To put to the proof; to prove the truth, genuineness, or quality of by
experiment, or by some principle or standard; to try

Jisho's API certainly outputs plenty of details about each word that aren't currently used:

// https://jisho.org/api/v1/search/words?keyword=muri
// syntax-highlighted as json5 so I can use comments
{
  "meta": {
    "status": 200
  },
  "data": [
    {
      "slug": "無理",
      "is_common": true,
      "tags": [
        "wanikani17"
      ],
      "jlpt": [
        "jlpt-n4"
      ],
      "japanese": [
        {
          "word": "無理",
          "reading": "むり"
        },
        {
          "reading": "ムリ"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "unreasonable",
            "unnatural",
            "unjustifiable"
          ],
          "parts_of_speech": [
            "Na-adjective (keiyodoshi)",
            "Noun"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        },
        {
          "english_definitions": [
            "impossible"
          ],
          "parts_of_speech": [
            "Na-adjective (keiyodoshi)",
            "Noun"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        },
        {
          "english_definitions": [
            "forcible",
            "forced",
            "compulsory"
          ],
          "parts_of_speech": [
            "Na-adjective (keiyodoshi)",
            "Noun"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": [
            "oft. adverbially as 〜に"
          ]
        },
        {
          "english_definitions": [
            "excessive (work, etc.)",
            "immoderate"
          ],
          "parts_of_speech": [
            "Na-adjective (keiyodoshi)"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        },
        {
          "english_definitions": [
            "to work too hard",
            "to try too hard"
          ],
          "parts_of_speech": [
            "Suru verb",
            "Intransitive verb"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        },
        {
          "english_definitions": [
            "no way",
            "not a chance",
            "never",
            "dream on"
          ],
          "parts_of_speech": [],
          "links": [],
          "tags": [
            "Colloquial"
          ],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        },
        {
          "english_definitions": [
            "irrational"
          ],
          "parts_of_speech": [
            "Noun which may take the genitive case particle 'no'"
          ],
          "links": [],
          "tags": [
            "Mathematics"
          ],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": false
      }
    },
    {
      "slug": "無料",
      "is_common": true,
      "tags": [
        "wanikani17"
      ],
      "jlpt": [
        "jlpt-n3"
      ],
      "japanese": [
        {
          "word": "無料",
          "reading": "むりょう"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "free (of charge)",
            "gratuitous"
          ],
          "parts_of_speech": [
            "Noun which may take the genitive case particle 'no'",
            "Noun"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [
            "有料"
          ],
          "source": [],
          "info": []
        },
        {
          "english_definitions": [
            "Gratis"
          ],
          "parts_of_speech": [
            "Wikipedia definition"
          ],
          "links": [
            {
              "text": "Read “Gratis” on English Wikipedia",
              "url": "http://en.wikipedia.org/wiki/Gratis?oldid=494825215"
            },
            {
              "text": "Read “無料” on Japanese Wikipedia",
              "url": "http://ja.wikipedia.org/wiki/無料?oldid=38106925"
            }
          ],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": [],
          "sentences": []
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": "http://dbpedia.org/resource/Gratis"
      }
    },
    {
      "slug": "無理やり",
      "is_common": true,
      "tags": [],
      "jlpt": [],
      "japanese": [
        {
          "word": "無理やり",
          "reading": "むりやり"
        },
        {
          "word": "無理矢理",
          "reading": "むりやり"
        },
        {
          "word": "無理遣り",
          "reading": "むりやり"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "forcibly",
            "by force",
            "against one's will"
          ],
          "parts_of_speech": [
            "Adverb (fukushi)"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": false
      }
    },
    {
      "slug": "無力",
      "is_common": true,
      "tags": [
        "wanikani17"
      ],
      "jlpt": [],
      "japanese": [
        {
          "word": "無力",
          "reading": "むりょく"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "powerlessness",
            "helplessness",
            "incompetent"
          ],
          "parts_of_speech": [
            "Na-adjective (keiyodoshi)",
            "Noun which may take the genitive case particle 'no'",
            "Noun"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": false
      }
    },
    {
      "slug": "無利子",
      "is_common": true,
      "tags": [],
      "jlpt": [],
      "japanese": [
        {
          "word": "無利子",
          "reading": "むりし"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "(earning or paying) no interest"
          ],
          "parts_of_speech": [
            "Noun"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": false
      }
    },
    {
      "slug": "無理強い",
      "is_common": false,
      "tags": [],
      "jlpt": [],
      "japanese": [
        {
          "word": "無理強い",
          "reading": "むりじい"
        },
        {
          "word": "無理じい",
          "reading": "むりじい"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "forcing",
            "compulsion",
            "coercion",
            "pushing (to do)"
          ],
          "parts_of_speech": [
            "Noun",
            "Suru verb",
            "Transitive verb"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": false
      }
    },
    {
      "slug": "無理押し",
      "is_common": false,
      "tags": [],
      "jlpt": [],
      "japanese": [
        {
          "word": "無理押し",
          "reading": "むりおし"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "pushing through (e.g. a proposal)",
            "bulldozing",
            "doing something by force",
            "arm-twisting"
          ],
          "parts_of_speech": [
            "Noun",
            "Suru verb",
            "Transitive verb",
            "Intransitive verb"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": false
      }
    },
    {
      "slug": "無理はない",
      "is_common": false,
      "tags": [],
      "jlpt": [],
      "japanese": [
        {
          "word": "無理はない",
          "reading": "むりはない"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "natural",
            "understandable",
            "reasonable",
            "no wonder"
          ],
          "parts_of_speech": [
            "Expressions (phrases, clauses, etc.)",
            "I-adjective (keiyoushi)"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": [
            "oft. as 〜のも無理はない"
          ]
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": false
      }
    },
    {
      "slug": "無理もない",
      "is_common": false,
      "tags": [],
      "jlpt": [],
      "japanese": [
        {
          "word": "無理もない",
          "reading": "むりもない"
        },
        {
          "word": "無理も無い",
          "reading": "むりもない"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "natural",
            "understandable",
            "reasonable",
            "no wonder"
          ],
          "parts_of_speech": [
            "Expressions (phrases, clauses, etc.)",
            "I-adjective (keiyoushi)"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": false
      }
    },
    {
      "slug": "無量",
      "is_common": true,
      "tags": [],
      "jlpt": [],
      "japanese": [
        {
          "word": "無量",
          "reading": "むりょう"
        }
      ],
      "senses": [
        {
          "english_definitions": [
            "immeasurable",
            "infinite",
            "inestimable"
          ],
          "parts_of_speech": [
            "Noun which may take the genitive case particle 'no'",
            "Noun"
          ],
          "links": [],
          "tags": [],
          "restrictions": [],
          "see_also": [],
          "antonyms": [],
          "source": [],
          "info": []
        }
      ],
      "attribution": {
        "jmdict": true,
        "jmnedict": false,
        "dbpedia": false
      }
    }
  ]
}