unofficial_jisho_api 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new64

unofficial_jisho_api #

A rewrite of the unofficial-jisho-api

Usage #

Below are some basic examples.

Word/phrase search (provided by official Jisho API) #

This returns the same results as the official Jisho.org API. See the discussion of that here.

import 'package:unofficial_jisho_api/api.dart' as jisho;

void main() async {
  jisho.searchForPhrase('日').then((result) {
    ...
    ...
    ...
  });
}
import 'dart:convert' show jsonEncode;
import 'package:unofficial_jisho_api/api.dart' as jisho;

void main() async {
  await jisho.searchForKanji('語').then((result) {
    print('Found: ${result.found}');
    print('Taught in: ${result.taughtIn}');
    print('JLPT level: ${result.jlptLevel}');
    print('Newspaper frequency rank: ${result.newspaperFrequencyRank}');
    print('Stroke count: ${result.strokeCount}');
    print('Meaning: ${result.meaning}');
    print('Kunyomi: ${jsonEncode(result.kunyomi)}');
    print('Kunyomi example: ${jsonEncode(result.kunyomiExamples[0])}');
    print('Onyomi: ${jsonEncode(result.onyomi)}');
    print('Onyomi example: ${jsonEncode(result.onyomiExamples[0])}');
    print('Radical: ${jsonEncode(result.radical)}');
    print('Parts: ${jsonEncode(result.parts)}');
    print('Stroke order diagram: ${result.strokeOrderDiagramUri}');
    print('Stroke order SVG: ${result.strokeOrderSvgUri}');
    print('Stroke order GIF: ${result.strokeOrderGifUri}');
    print('Jisho Uri: ${result.uri}');
  });
}

This outputs the following:

Found: true
Taught in: grade 2
JLPT level: N5
Newspaper frequency rank: 301
Stroke count: 14
Meaning: word, speech, language
Kunyomi: ["かた.る","かた.らう"]
Kunyomi example: {"example":"語る","reading":"かたる","meaning":"to talk about, to speak of, to tell, to narrate, to recite, to chant, to indicate, to show"}
Onyomi: ["ゴ"]
Onyomi example: {"example":"語","reading":"ゴ","meaning":"language, word"}
Radical: {"symbol":"言","forms":["訁"],"meaning":"speech"}
Parts: ["五","口","言"]
Stroke order diagram: https://classic.jisho.org/static/images/stroke_diagrams/35486_frames.png
Stroke order SVG: https://d1w6u4xc3l95km.cloudfront.net/kanji-2015-03/08a9e.svg
Stroke order GIF: https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/8a9e.gif
Jisho Uri: https://jisho.org/search/%E8%AA%9E%23kanji
import 'dart:convert' show jsonEncode;
import 'package:unofficial_jisho_api/api.dart' as jisho;

void main() async {
  await jisho.searchForExamples('日').then((result) {
    print('Jisho Uri: ${result.uri}');
    print('');

    for (var i = 0; i < 3; i++) {
      var example = result.results[i];
      print(example.kanji);
      print(example.kana);
      print(example.english);
      print(jsonEncode(example.pieces));
      print('');
    }
  });
}

This outputs the following:

Jisho Uri: https://jisho.org/search/%E6%97%A5%23sentences

日本人ならそんなことはけっしてしないでしょう。
にほんじんならそんなことはけっしてしないでしょう。
A Japanese person would never do such a thing.
[{"lifted":"にほんじん","unlifted":"日本人"},{"lifted":null,"unlifted":"なら"},{"lifted":null,"unlifted":"そんな"},{"lifted":null,"unlifted":"こと"},{"lifted":null,"unlifted":"は"},{"lifted":null,"unlifted":"けっして"},{"lifted":null,"unlifted":"しない"},{"lifted":null,"unlifted":"でしょう"}]

今日はとても暑い。
きょうはとてもあつい。
It is very hot today.
[{"lifted":"きょう","unlifted":"今日"},{"lifted":null,"unlifted":"は"},{"lifted":null,"unlifted":"とても"},{"lifted":"あつ","unlifted":"暑い"}]

日本には美しい都市が多い。例えば京都、奈良だ。
にほんにはうつくしいとしがおおい。たとえばきょうと、奈良だ。
Japan is full of beautiful cities. Kyoto and Nara, for instance.
[{"lifted":"にほん","unlifted":"日本"},{"lifted":null,"unlifted":"には"},{"lifted":"うつく","unlifted":"美しい"},{"lifted":"とし","unlifted":"都市"},{"lifted":null,"unlifted":"が"},{"lifted":"おお","unlifted":"多い"},{"lifted":"たと","unlifted":"例えば"},{"lifted":"きょうと","unlifted":"京都"},{"lifted":null,"unlifted":"だ"}]

Word/phrase scraping #

This scrapes the word/phrase page on Jisho.org. This can get you some data that the official API doesn't have, such as JLPT level and part-of-speech. The official API (searchForPhrase) should be preferred if it has the data you need.

import 'dart:convert';
import 'package:unofficial_jisho_api/api.dart' as jisho;
final JsonEncoder encoder = JsonEncoder.withIndent('  ');

void main() async {
  await jisho.scrapeForPhrase('谷').then((data) {
    print(encoder.convert(data));
  });
}

This outputs the following:

{
  "found": true,
  "query": "谷",
  "uri": "https://jisho.org/word/%E8%B0%B7",
  "tags": [
    "Common word",
    "JLPT N3",
    "Wanikani level 5"
  ],
  "meanings": [
    {
      "seeAlsoTerms": [],
      "sentences": [],
      "definition": "valley",
      "supplemental": [],
      "definitionAbstract": null,
      "tags": [
        "noun"
      ]
    },
    {
      "seeAlsoTerms": [],
      "sentences": [],
      "definition": "Valley",
      "supplemental": [],
      "definitionAbstract": "In geology, a valley or dale is a depression with predominant extent in one direction. A very deep river valley may be called a canyon or gorge. The terms U-shaped and V-shaped are descriptive terms of geography to characterize the form of valleys. Most valleys belong to one of these two main types or a mixture of them, (at least) with respect of the cross section of the slopes or hillsides.",
      "tags": [
        "wikipedia definition"
      ]
    }
  ],
  "otherForms": [
    {
      "kanji": "渓",
      "kana": "たに"
    },
    {
      "kanji": "谿",
      "kana": "たに"
    }
  ],
  "notes": []
}

Parsing HTML strings #

You can provide the HTML responses from Jisho yourself. This can be useful if you need to use a CORS proxy or something. You can do whatever you need to do to get the HTML and then provide it to this module's parsing functions. For example:

Parse kanji page HTML #

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:unofficial_jisho_api/parser.dart' as jisho_parser;

final JsonEncoder encoder = JsonEncoder.withIndent('  ');

const String searchKanji = '車';
final String searchURI = jisho_parser.uriForKanjiSearch(searchKanji);

void main() async {
  await http.get(searchURI).then((result) {
    final parsedResult = jisho_parser.parseKanjiPageData(result.body, searchKanji);
    print('JLPT level: ${parsedResult.jlptLevel}');
    print('Stroke count: ${parsedResult.strokeCount}');
    print('Meaning: ${parsedResult.meaning}');
  });
}

Parse example page HTML #

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:unofficial_jisho_api/parser.dart' as jisho_parser;

final JsonEncoder encoder = JsonEncoder.withIndent('  ');

const String searchExample = '保護者';
final String searchURI = jisho_parser.uriForExampleSearch(searchExample);

void main() async {
  await http.get(searchURI).then((result) {
    final parsedResult = jisho_parser.parseExamplePageData(result.body, searchExample);
    print('English: ${parsedResult.results[0].english}');
    print('Kanji ${parsedResult.results[0].kanji}');
    print('Kana: ${parsedResult.results[0].kana}');
  });
}

Parse phrase page HTML #

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:unofficial_jisho_api/parser.dart' as jisho_parser;

final JsonEncoder encoder = JsonEncoder.withIndent('  ');

const String searchExample = '保護者';
final String searchURI = jisho_parser.uriForPhraseScrape(searchExample);

void main() async {

  await http.get(searchURI).then((result) {
    final parsedResult = jisho_parser.parsePhrasePageData(result.body, searchExample);
    print(encoder.convert(parsedResult));
  });
}

About #

Permission to scrape granted by Jisho's admin Kimtaro: https://jisho.org/forum/54fefc1f6e73340b1f160000-is-there-any-kind-of-search-api

1.1.0 #

  • Export object interfaces for both libraries
  • Add documentation for object interfaces
  • Remove accidental redundant property "phrase" from ExampleResults

1.0.2 #

  • Fix example README

1.0.1 #

  • Reformatted code
  • Added example readme

1.0.0 #

  • Initial version, created by Stagehand

example/README.md

Examples #

Examples for use of the api functions, and for parsing.

These examples are also available on the main readme.

API searching/scraping #

These are usage examples of the api library, providing results directly.

Word/phrase search (provided by official Jisho API) #

This returns the same results as the official Jisho.org API. See the discussion of that here.

import 'package:unofficial_jisho_api/api.dart' as jisho;

void main() async {
  jisho.searchForPhrase('日').then((result) {
    ...
    ...
    ...
  });
}
import 'dart:convert' show jsonEncode;
import 'package:unofficial_jisho_api/api.dart' as jisho;

void main() async {
  await jisho.searchForKanji('語').then((result) {
    print('Found: ${result.found}');
    print('Taught in: ${result.taughtIn}');
    print('JLPT level: ${result.jlptLevel}');
    print('Newspaper frequency rank: ${result.newspaperFrequencyRank}');
    print('Stroke count: ${result.strokeCount}');
    print('Meaning: ${result.meaning}');
    print('Kunyomi: ${jsonEncode(result.kunyomi)}');
    print('Kunyomi example: ${jsonEncode(result.kunyomiExamples[0])}');
    print('Onyomi: ${jsonEncode(result.onyomi)}');
    print('Onyomi example: ${jsonEncode(result.onyomiExamples[0])}');
    print('Radical: ${jsonEncode(result.radical)}');
    print('Parts: ${jsonEncode(result.parts)}');
    print('Stroke order diagram: ${result.strokeOrderDiagramUri}');
    print('Stroke order SVG: ${result.strokeOrderSvgUri}');
    print('Stroke order GIF: ${result.strokeOrderGifUri}');
    print('Jisho Uri: ${result.uri}');
  });
}
import 'dart:convert' show jsonEncode;
import 'package:unofficial_jisho_api/api.dart' as jisho;

void main() async {
  await jisho.searchForExamples('日').then((result) {
    print('Jisho Uri: ${result.uri}');
    print('');

    for (var i = 0; i < 3; i++) {
      var example = result.results[i];
      print(example.kanji);
      print(example.kana);
      print(example.english);
      print(jsonEncode(example.pieces));
      print('');
    }
  });
}

Word/phrase scraping #

This scrapes the word/phrase page on Jisho.org. This can get you some data that the official API doesn't have, such as JLPT level and part-of-speech. The official API (searchForPhrase) should be preferred if it has the data you need.

import 'dart:convert';
import 'package:unofficial_jisho_api/api.dart' as jisho;
final JsonEncoder encoder = JsonEncoder.withIndent('  ');

void main() async {
  await jisho.scrapeForPhrase('谷').then((data) {
    print(encoder.convert(data));
  });
}

Parsing #

You can provide the HTML responses from Jisho yourself. This can be useful if you need to use a CORS proxy or something. You can do whatever you need to do to get the HTML and then provide it to this module's parsing functions. For example:

Parse kanji page HTML #

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:unofficial_jisho_api/parser.dart' as jisho_parser;

final JsonEncoder encoder = JsonEncoder.withIndent('  ');

const String searchKanji = '車';
final String searchURI = jisho_parser.uriForKanjiSearch(searchKanji);

void main() async {
  await http.get(searchURI).then((result) {
    final parsedResult = jisho_parser.parseKanjiPageData(result.body, searchKanji);
    print('JLPT level: ${parsedResult.jlptLevel}');
    print('Stroke count: ${parsedResult.strokeCount}');
    print('Meaning: ${parsedResult.meaning}');
  });
}

Parse example page HTML #

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:unofficial_jisho_api/parser.dart' as jisho_parser;

final JsonEncoder encoder = JsonEncoder.withIndent('  ');

const String searchExample = '保護者';
final String searchURI = jisho_parser.uriForExampleSearch(searchExample);

void main() async {
  await http.get(searchURI).then((result) {
    final parsedResult = jisho_parser.parseExamplePageData(result.body, searchExample);
    print('English: ${parsedResult.results[0].english}');
    print('Kanji ${parsedResult.results[0].kanji}');
    print('Kana: ${parsedResult.results[0].kana}');
  });
}

Parse phrase page HTML #

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:unofficial_jisho_api/parser.dart' as jisho_parser;

final JsonEncoder encoder = JsonEncoder.withIndent('  ');

const String searchExample = '保護者';
final String searchURI = jisho_parser.uriForPhraseScrape(searchExample);

void main() async {

  await http.get(searchURI).then((result) {
    final parsedResult = jisho_parser.parsePhrasePageData(result.body, searchExample);
    print(encoder.convert(parsedResult));
  });
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  unofficial_jisho_api: ^1.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:unofficial_jisho_api/api.dart';
import 'package:unofficial_jisho_api/parser.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Format lib/src/exampleSearch.dart.

Run dartfmt to format lib/src/exampleSearch.dart.

Format lib/src/objects.dart.

Run dartfmt to format lib/src/objects.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
html ^0.14.0+3 0.14.0+3
html_unescape ^1.0.1+3 1.0.1+3
http ^0.12.1 0.12.1
Transitive dependencies
charcode 1.1.3
collection 1.14.13
csslib 0.16.1
http_parser 3.1.4
meta 1.1.8
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.2.0
Dev dependencies
effective_dart ^1.2.3
path ^1.7.0 1.7.0
pedantic ^1.9.0 1.9.0 1.9.1
test ^1.15.0