From 5be39da75e526eb823fdc60b4d428665fb28f5ec Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 8 Mar 2020 21:11:32 +0100 Subject: [PATCH] Init --- .gitignore | 11 + CHANGELOG.md | 3 + README.md | 22 + analysis_options.yaml | 14 + example/unofficial_jisho_api_example.dart | 4 + lib/src/objects.dart | 154 +++ lib/src/unofficial_jisho_api_base.dart | 495 +++++++++ lib/unofficial_jisho_api.dart | 7 + pubspec.yaml | 16 + test/create_test_cases.dart | 0 test/example_test_cases/0.json | 1071 ++++++++++++++++++ test/example_test_cases/1.json | 891 +++++++++++++++ test/example_test_cases/2.json | 10 + test/example_test_cases/3.json | 1215 +++++++++++++++++++++ test/example_test_cases/4.json | 10 + test/example_test_cases/5.json | 10 + test/kanji_test_cases/0.json | 68 ++ test/kanji_test_cases/1.json | 127 +++ test/kanji_test_cases/2.json | 99 ++ test/kanji_test_cases/3.json | 7 + test/kanji_test_cases/4.json | 52 + test/kanji_test_cases/5.json | 7 + test/kanji_test_cases/6.json | 7 + test/kanji_test_cases/7.json | 78 ++ test/phrase_scrape_test_cases/0.json | 100 ++ test/phrase_scrape_test_cases/1.json | 40 + test/phrase_scrape_test_cases/2.json | 135 +++ test/phrase_scrape_test_cases/3.json | 69 ++ test/phrase_scrape_test_cases/4.json | 7 + test/unofficial_jisho_api_test.dart | 60 + 30 files changed, 4789 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 README.md create mode 100644 analysis_options.yaml create mode 100644 example/unofficial_jisho_api_example.dart create mode 100644 lib/src/objects.dart create mode 100644 lib/src/unofficial_jisho_api_base.dart create mode 100644 lib/unofficial_jisho_api.dart create mode 100644 pubspec.yaml create mode 100644 test/create_test_cases.dart create mode 100644 test/example_test_cases/0.json create mode 100644 test/example_test_cases/1.json create mode 100644 test/example_test_cases/2.json create mode 100644 test/example_test_cases/3.json create mode 100644 test/example_test_cases/4.json create mode 100644 test/example_test_cases/5.json create mode 100644 test/kanji_test_cases/0.json create mode 100644 test/kanji_test_cases/1.json create mode 100644 test/kanji_test_cases/2.json create mode 100644 test/kanji_test_cases/3.json create mode 100644 test/kanji_test_cases/4.json create mode 100644 test/kanji_test_cases/5.json create mode 100644 test/kanji_test_cases/6.json create mode 100644 test/kanji_test_cases/7.json create mode 100644 test/phrase_scrape_test_cases/0.json create mode 100644 test/phrase_scrape_test_cases/1.json create mode 100644 test/phrase_scrape_test_cases/2.json create mode 100644 test/phrase_scrape_test_cases/3.json create mode 100644 test/phrase_scrape_test_cases/4.json create mode 100644 test/unofficial_jisho_api_test.dart diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50602ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Files and directories created by pub +.dart_tool/ +.packages +# Remove the following pattern if you wish to check in your lock file +pubspec.lock + +# Conventional directory for build outputs +build/ + +# Directory created by dartdoc +doc/api/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..687440b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version, created by Stagehand diff --git a/README.md b/README.md new file mode 100644 index 0000000..d73e4b0 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +A library for Dart developers. + +Created from templates made available by Stagehand under a BSD-style +[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE). + +## Usage + +A simple usage example: + +```dart +import 'package:unofficial_jisho_api/unofficial_jisho_api.dart'; + +main() { + var awesome = new Awesome(); +} +``` + +## Features and bugs + +Please file feature requests and bugs at the [issue tracker][tracker]. + +[tracker]: http://example.com/issues/replaceme diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..a686c1b --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,14 @@ +# Defines a default set of lint rules enforced for +# projects at Google. For details and rationale, +# see https://github.com/dart-lang/pedantic#enabled-lints. +include: package:pedantic/analysis_options.yaml + +# For lint rules and documentation, see http://dart-lang.github.io/linter/lints. +# Uncomment to specify additional rules. +# linter: +# rules: +# - camel_case_types + +analyzer: +# exclude: +# - path/to/excluded/files/** diff --git a/example/unofficial_jisho_api_example.dart b/example/unofficial_jisho_api_example.dart new file mode 100644 index 0000000..d068193 --- /dev/null +++ b/example/unofficial_jisho_api_example.dart @@ -0,0 +1,4 @@ +import 'package:unofficial_jisho_api/unofficial_jisho_api.dart'; + +void main() { +} diff --git a/lib/src/objects.dart b/lib/src/objects.dart new file mode 100644 index 0000000..0592d97 --- /dev/null +++ b/lib/src/objects.dart @@ -0,0 +1,154 @@ +class PhraseScrapeSentence { + String english; + String japanese; + List pieces; + + PhraseScrapeSentence ({String english, String japanese, List pieces}){ + this.english = english; + this.japanese = japanese; + this.pieces = pieces; + } +} + +class PhraseScrapeMeaning { + List seeAlsoTerms; + List sentences; + String definition; + List supplemental; + String definitionAbstract; + List tags; + + PhraseScrapeMeaning({ + List seeAlsoTerms, + List sentences, + String definition, + List supplemental, + String definitionAbstract, + List tags, + }){ + this.seeAlsoTerms = seeAlsoTerms; + this.sentences = sentences; + this.definition = definition; + this.supplemental = supplemental; + this.definitionAbstract = definitionAbstract; + this.tags = tags; + + } +} + +class PhrasePageScrapeResult { + bool found; + String query; + String uri; + List otherForms; + List meanings; + List tags; + List notes; + + PhrasePageScrapeResult({ + bool found, + String query, + String uri, + List otherForms, + List meanings, + List tags, + List notes, + }){ + this.found = found; + this.query = query; + this.uri = uri; + this.otherForms = otherForms; + this.meanings = meanings; + this.tags = tags; + this.notes = notes; + } +} + +class YomiExample { + String example; + String reading; + String meaning; + + YomiExample({String example, String reading, String meaning}){ + this.example = example; + this.reading = reading; + this.meaning = meaning; + } +} + +class Radical { + String symbol; + List forms; + String meaning; + + Radical({String symbol, List forms, String meaning}){ + this.symbol = symbol; + this.forms = forms; + this.meaning = meaning; + } +} + +class KanjiResult { + String query; + bool found; + + String taughtIn; + String jlptLevel; + int newspaperFrequencyRank; + int strokeCount; + String meaning; + List kunyomi; + List onyomi; + List onyomiExamples; + List kunyomiExamples; + Radical radical; + List parts; + String strokeOrderDiagramUri; + String strokeOrderSvgUri; + String strokeOrderGifUri; + String uri; +} + +class ExampleSentencePiece { + String unlifted; + String lifted; + + ExampleSentencePiece({String unlifted, String lifted}){ + this.unlifted = unlifted; + this.lifted = lifted; + } +} + +class ExampleResultData { + String kanji; + String kana; + String english; + List pieces; + + ExampleResultData({String kanji, String kana, String english, List pieces}){ + this.kanji = kanji; + this.kana = kana; + this.english = english; + this.pieces = pieces; + } +} + +class ExampleResults { + String query; + bool found; + String uri; + List results; + String phrase; + + ExampleResults({String query, bool found, String uri, List results, String phrase}){ + this.query = query; + this.found = found; + this.uri = uri; + this.results = results; + this.phrase = phrase; + } +} + + + + diff --git a/lib/src/unofficial_jisho_api_base.dart b/lib/src/unofficial_jisho_api_base.dart new file mode 100644 index 0000000..0299261 --- /dev/null +++ b/lib/src/unofficial_jisho_api_base.dart @@ -0,0 +1,495 @@ +import 'package:unofficial_jisho_api/src/objects.dart'; +import 'package:http/http.dart' as http; +import 'package:xml/xml.dart' as xml; +import 'package:html_unescape/html_unescape.dart' as html_entities; +import 'dart:convert'; + +final htmlUnescape = html_entities.HtmlUnescape(); + +// TODO: Put public facing types in this file. + +const String JISHO_API = 'http://jisho.org/api/v1/search/words'; +const String SCRAPE_BASE_URI = 'http://jisho.org/search/'; +const String STROKE_ORDER_DIAGRAM_BASE_URI = 'http://classic.jisho.org/static/images/stroke_diagrams/'; + +/* KANJI SEARCH FUNCTIONS START */ + +const String ONYOMI_LOCATOR_SYMBOL = 'On'; +const KUNYOMI_LOCATOR_SYMBOL = 'Kun'; + +String removeNewlines(String str) { + return str.replaceAll(RegExp(r'(?:\r|\n)') , '').trim(); +} + +String uriForKanjiSearch(String kanji) { + return '${SCRAPE_BASE_URI}${Uri.encodeComponent(kanji)}%23kanji'; +} + +String getUriForStrokeOrderDiagram(String kanji) { + return '${STROKE_ORDER_DIAGRAM_BASE_URI}${kanji.codeUnitAt(0)}_frames.png'; +} + +String uriForPhraseSearch(String phrase) { + return '${JISHO_API}?keyword=${Uri.encodeComponent(phrase)}'; +} + +bool containsKanjiGlyph(pageHtml, String kanji) { + final kanjiGlyphToken = '

${kanji}

'; + return pageHtml.indexOf(kanjiGlyphToken) != -1; +} + +String getStringBetweenIndicies(String data, int startIndex, int endIndex) { + final result = data.substring(startIndex, endIndex); + return removeNewlines(result).trim(); +} + +String getStringBetweenStrings(String data, String startString, String endString) { + final regex = RegExp('${RegExp.escape(startString)}(.*?)${RegExp.escape(endString)}'); + final match = regex.allMatches(data).toList(); + + return match ?? match[1].toString(); +} + +int getIntBetweenStrings(pageHtml, String startString, String endString) { + final stringBetweenStrings = getStringBetweenStrings(pageHtml, startString, endString); + return stringBetweenStrings ?? int.parse(stringBetweenStrings); +} + +List getAllGlobalGroupMatches(String str, RegExp regex) { + var regexResults = regex.allMatches(str).toList(); + var results = []; + for (var match in regexResults) { + results.add(match.toString().split(' ')[0]); + } + + return results; +} + +List parseAnchorsToArray(String str) { + final regex = RegExp(r'(.*?)<\/a>'); + return getAllGlobalGroupMatches(str, regex); +} + +List getYomi(pageHtml, String yomiLocatorSymbol) { + final yomiSection = getStringBetweenStrings(pageHtml, '
${yomiLocatorSymbol}:
', ''); + return parseAnchorsToArray(yomiSection ?? ''); +} + +List getKunyomi(pageHtml) { + return getYomi(pageHtml, KUNYOMI_LOCATOR_SYMBOL); +} + +List getOnyomi(pageHtml) { + return getYomi(pageHtml, ONYOMI_LOCATOR_SYMBOL); +} + +List getYomiExamples(pageHtml, String yomiLocatorSymbol) { + final locatorString = '

${yomiLocatorSymbol} reading compounds

'; + final exampleSection = getStringBetweenStrings(pageHtml, locatorString, ''); + if (exampleSection==null) { + return null; + } + + final regex = RegExp(r'/
  • (.*?)<\/li>'); + final regexResults = getAllGlobalGroupMatches(exampleSection, regex).map((s) => s.trim()); + + final examples = regexResults.map((regexResult) { + final examplesLines = regexResult.split('\n').map((s) => s.trim()).toList(); + return YomiExample( + example: examplesLines[0], + reading: examplesLines[1].replaceAll('【', '').replaceAll('】', ''), + meaning: htmlUnescape.convert(examplesLines[2]), + ); + }); + + return examples; +} + +List getOnyomiExamples(pageHtml) { + return getYomiExamples(pageHtml, ONYOMI_LOCATOR_SYMBOL); +} + +List getKunyomiExamples(pageHtml) { + return getYomiExamples(pageHtml, KUNYOMI_LOCATOR_SYMBOL); +} + +Radical getRadical(pageHtml) { + const radicalMeaningStartString = ''; + const radicalMeaningEndString = ''; + + var radicalMeaning = getStringBetweenStrings( + pageHtml, + radicalMeaningStartString, + radicalMeaningEndString, + ).trim(); + + if (radicalMeaning!=null) { + final radicalMeaningStartIndex = pageHtml.indexOf(radicalMeaningStartString); + + final radicalMeaningEndIndex = pageHtml.indexOf( + radicalMeaningEndString, + radicalMeaningStartIndex, + ); + + final radicalSymbolStartIndex = radicalMeaningEndIndex + radicalMeaningEndString.length; + const radicalSymbolEndString = ''; + final radicalSymbolEndIndex = pageHtml.indexOf(radicalSymbolEndString, radicalSymbolStartIndex); + + final radicalSymbolsString = getStringBetweenIndicies( + pageHtml, + radicalSymbolStartIndex, + radicalSymbolEndIndex, + ); + + if (radicalSymbolsString.length > 1) { + final radicalForms = radicalSymbolsString + .substring(1) + .replaceAll('(', '') + .replaceAll(')', '') + .trim() + .split(', '); + + return Radical( + symbol: radicalSymbolsString[0], + forms: radicalForms, + meaning: radicalMeaning + ); + } + + return Radical ( + symbol: radicalSymbolsString, + meaning: radicalMeaning + ); + } + + return null; +} + +List getParts(pageHtml) { + const partsSectionStartString = '
    Parts:
    '; + const partsSectionEndString = ''; + + final partsSection = getStringBetweenStrings( + pageHtml, + partsSectionStartString, + partsSectionEndString, + ); + + var result = parseAnchorsToArray(partsSection); + result.sort(); + + return (result); +} + +String getSvgUri(pageHtml) { + var svgRegex = RegExp('\/\/.*?.cloudfront.net\/.*?.svg/'); + final regexResult = svgRegex.firstMatch(pageHtml).toString(); + return regexResult ?? 'http:${regexResult}'; +} + +String getGifUri(String kanji) { + final unicodeString = kanji.codeUnitAt(0).toRadixString(16); + final fileName = '${unicodeString}.gif'; + final animationUri = 'https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/${fileName}'; + + return animationUri; +} + +int getNewspaperFrequencyRank(pageHtml) { + final frequencySection = getStringBetweenStrings(pageHtml, '
    ', '
    '); + return frequencySection ?? int.parse(getStringBetweenStrings(frequencySection, '', '')); +} + +KanjiResult parseKanjiPageData(pageHtml, String kanji) { + final result = KanjiResult(); + result.query = kanji; + result.found = containsKanjiGlyph(pageHtml, kanji); + if (result.found==false) { + return result; + } + + result.taughtIn = getStringBetweenStrings(pageHtml, 'taught in ', ''); + result.jlptLevel = getStringBetweenStrings(pageHtml, 'JLPT level ', ''); + result.newspaperFrequencyRank = getNewspaperFrequencyRank(pageHtml); + result.strokeCount = getIntBetweenStrings(pageHtml, '', ' strokes'); + result.meaning = htmlUnescape.convert(removeNewlines(getStringBetweenStrings(pageHtml, '
    ', '
    ')).trim()); + result.kunyomi = getKunyomi(pageHtml); + result.onyomi = getOnyomi(pageHtml); + result.onyomiExamples = getOnyomiExamples(pageHtml); + result.kunyomiExamples = getKunyomiExamples(pageHtml); + result.radical = getRadical(pageHtml); + result.parts = getParts(pageHtml); + result.strokeOrderDiagramUri = getUriForStrokeOrderDiagram(kanji); + result.strokeOrderSvgUri = getSvgUri(pageHtml); + result.strokeOrderGifUri = getGifUri(kanji); + result.uri = uriForKanjiSearch(kanji); + return result; +} + +/* KANJI SEARCH FUNCTIONS END */ + +/* EXAMPLE SEARCH FUNCTIONS START */ + +RegExp kanjiRegex = RegExp(r'[\u4e00-\u9faf\u3400-\u4dbf]'); + +String uriForExampleSearch(String phrase) { + return '${SCRAPE_BASE_URI}${Uri.encodeComponent(phrase)}%23sentences'; +} + +ExampleResultData getKanjiAndKana(div) { + final ul = div.find('ul').eq(0); + final contents = ul.contents(); + + var kanji = ''; + var kana = ''; + for (var i = 0; i < contents.length; i += 1) { + final content = contents.eq(i); + if (content[0].name == 'li') { + final li = content; + final furigana = li.find('.furigana').text(); + final unlifted = li.find('.unlinked').text(); + + if (furigana) { + kanji += unlifted; + kana += furigana; + + final kanaEnding = []; + for (var j = unlifted.length - 1; j > 0; j -= 1) { + if (!unlifted[j].match(kanjiRegex)) { + kanaEnding.add(unlifted[j]); + } else { + break; + } + } + + kana += kanaEnding.reversed.join(''); + } else { + kanji += unlifted; + kana += unlifted; + } + } else { + final text = content.text().trim(); + if (text) { + kanji += text; + kana += text; + } + } + } + + return ExampleResultData( + kanji: kanji, + kana: kana, + ); +} + +List getPieces(sentenceElement) { + final pieceElements = sentenceElement.find('li.clearfix'); + final pieces = []; + for (var pieceIndex = 0; pieceIndex < pieceElements.length; pieceIndex += 1) { + final pieceElement = pieceElements.eq(pieceIndex); + pieces.add(ExampleSentencePiece( + lifted: pieceElement.children('.furigana').text(), + unlifted: pieceElement.children('.unlinked').text(), + )); + } + + return pieces; +} + +ExampleResultData parseExampleDiv(div) { + final result = getKanjiAndKana(div); + result.english = div.find('.english').text(); + result.pieces = getPieces(div); + + return result; +} + +ExampleResults parseExamplePageData(pageHtml, String phrase) { + final document = xml.parse(pageHtml); + final divs = document.descendants.where((node) => node.attributes[0].value == 'sentence_content').toList(); + + final results = divs.map((div) => parseExampleDiv(div)); + + return ExampleResults( + query: phrase, + found: results.isNotEmpty, + results: results, + uri: uriForExampleSearch(phrase), + phrase: phrase, + ); +} + +/* EXAMPLE SEARCH FUNCTIONS END */ + +/* PHRASE SCRAPE FUNCTIONS START */ + +List getTags(document) { + final tags = []; + final tagElements = document.descendants.where((node) => node.attributes[0].value == 'concept_light-tag').toList(); + + for (var i = 0; i < tagElements.length; i += 1) { + final tagText = tagElements.eq(i).text(); + tags.add(tagText); + } + + return tags; +} + +PhrasePageScrapeResult getMeaningsOtherFormsAndNotes(document) { + final returnValues = PhrasePageScrapeResult( otherForms: [], notes: [] ); + + //TODO: Fix + // const meaningsWrapper = $('#page_container > div > div > article > div > div.concept_light-meanings.medium-9.columns > div'); + final meaningsWrapper = document.descendants.where((node) => node.attributes[0].value == 'page_container').toList(); + + + + final meaningsChildren = meaningsWrapper.children(); + final meanings = []; + + var mostRecentWordTypes = []; + for (var meaningIndex = 0; meaningIndex < meaningsChildren.length; meaningIndex += 1) { + final child = meaningsChildren.eq(meaningIndex); + if (child.hasClass('meaning-tags')) { + mostRecentWordTypes = child.text().split(',').map((s) => s.trim().toLowerCase()); + } else if (mostRecentWordTypes[0] == 'other forms') { + returnValues.otherForms = child.text().split('、') + .map((s) => s.replaceAll('【', '').replaceAll('】', '').split(' ')) + .map((a) => (ExampleResultData( kanji: a[0], kana: a[1] ))); + } else if (mostRecentWordTypes[0] == 'notes') { + returnValues.notes = child.text().split('\n'); + } else { + final meaning = child.find('.meaning-meaning').text(); + final meaningAbstract = child.find('.meaning-abstract') + .find('a') + .remove() + .end() + .text(); + + final supplemental = child.find('.supplemental_info').text().split(',') + .map((s) => s.trim()) + .filter((s) => s); + + final seeAlsoTerms = []; + for (var i = supplemental.length - 1; i >= 0; i -= 1) { + final supplementalEntry = supplemental[i]; + if (supplementalEntry.startsWith('See also')) { + seeAlsoTerms.add(supplementalEntry.replaceAll('See also ', '')); + supplemental.splice(i, 1); + } + } + + final sentences = []; + final sentenceElements = child.find('.sentences').children('.sentence'); + + for (var sentenceIndex = 0; sentenceIndex < sentenceElements.length; sentenceIndex += 1) { + final sentenceElement = sentenceElements.eq(sentenceIndex); + + final english = sentenceElement.find('.english').text(); + final pieces = getPieces(sentenceElement); + + final japanese = sentenceElement + .find('.english').remove().end() + .find('.furigana') + .remove() + .end() + .text(); + + sentences.add(PhraseScrapeSentence(english: english, japanese: japanese, pieces: pieces)); + } + + meanings.add(PhraseScrapeMeaning( + seeAlsoTerms: seeAlsoTerms, + sentences: sentences, + definition: meaning, + supplemental: supplemental, + definitionAbstract: meaningAbstract, + tags: mostRecentWordTypes, + )); + } + } + + returnValues.meanings = meanings; + + return returnValues; +} + +String uriForPhraseScrape(searchTerm) { + return 'https://jisho.org/word/${Uri.encodeComponent(searchTerm)}'; +} + +PhrasePageScrapeResult parsePhrasePageData(pageHtml, query) { + final document = xml.parse(pageHtml); + final result = getMeaningsOtherFormsAndNotes(document); + + result.found = true; + result.query = query; + result.uri = uriForPhraseScrape(query); + result.tags = getTags(document); + // result.meanings = meanings; + // result.otherForms = forms; + // result.notes = notes; + + return result; +} + +class API { + + /// Query the official Jisho API for a word or phrase + /// + /// See [here]{@link https://jisho.org/forum/54fefc1f6e73340b1f160000-is-there-any-kind-of-search-api} + /// for discussion about the official API. + /// @param {string} phrase The search term to search for. + /// @returns {Object} The response data from the official Jisho.org API. Its format is somewhat + /// complex and is not documented, so put on your trial-and-error hat. + /// @async + searchForPhrase(String phrase) { + final uri = uriForPhraseSearch(phrase); + return http.read(uri).then((response) => jsonDecode(response).data); + } + + /// Scrape the word page for a word/phrase. + /// + /// This allows you to get some information that isn't provided by the official API, such as + /// part-of-speech and JLPT level. However, the official API should be preferred + /// if it has the information you need. This function scrapes https://jisho.org/word/XXX. + /// In general, you'll want to include kanji in your search term, for example 掛かる + /// instead of かかる (no results). + /// @param {string} phrase The search term to search for. + /// @returns {PhrasePageScrapeResult} Information about the searched query. + /// @async + Future scrapeForPhrase(String phrase) async { + final uri = uriForPhraseScrape(phrase); + try { + final response = await http.read(uri); + return parsePhrasePageData(jsonDecode(response).data, phrase); + } catch (err) { + if (err.response.status == 404) { + return PhrasePageScrapeResult( + query: phrase, + found: false, + ); + } + + throw err; + } + } + + /// Scrape Jisho.org for information about a kanji character. + /// @param {string} kanji The kanji to search for. + /// @returns {KanjiResult} Information about the searched kanji. + /// @async + Future searchForKanji(String kanji) { + final uri = uriForKanjiSearch(kanji); + return http.read(uri).then((response) => parseKanjiPageData(jsonDecode(response).data, kanji)); + } + + /// Scrape Jisho.org for examples. + /// @param {string} phrase The word or phrase to search for. + /// @returns {ExampleResults} + /// @async + Future searchForExamples(String phrase) { + final uri = uriForExampleSearch(phrase); + return http.read(uri).then((response) => parseExamplePageData(jsonDecode(response).data, phrase)); + } +} \ No newline at end of file diff --git a/lib/unofficial_jisho_api.dart b/lib/unofficial_jisho_api.dart new file mode 100644 index 0000000..495acfd --- /dev/null +++ b/lib/unofficial_jisho_api.dart @@ -0,0 +1,7 @@ +/// Support for doing something awesome. +/// +/// More dartdocs go here. +library unofficial_jisho_api; + +export 'src/unofficial_jisho_api_base.dart'; + diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..b0b25d2 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,16 @@ +name: unofficial_jisho_api +description: A starting point for Dart libraries or applications. +version: 1.0.0 +homepage: https://www.example.com #TODO: EDIT + +environment: + sdk: '>=2.7.0 <3.0.0' + +dependencies: +# path: ^1.6.0 + xml: ^3.7.0 + html_unescape: ^1.0.1+3 + +dev_dependencies: + pedantic: ^1.8.0 + test: ^1.6.0 diff --git a/test/create_test_cases.dart b/test/create_test_cases.dart new file mode 100644 index 0000000..e69de29 diff --git a/test/example_test_cases/0.json b/test/example_test_cases/0.json new file mode 100644 index 0000000..3babdd2 --- /dev/null +++ b/test/example_test_cases/0.json @@ -0,0 +1,1071 @@ +{ + "query": "車", + "expectedResult": { + "query": "車", + "found": true, + "results": [ + { + "english": "The colour and make of the president's car are?", + "kanji": "社長さんの車種と色は?", + "kana": "しゃちょうさんのしゃしゅといろは?", + "pieces": [ + { + "lifted": "しゃちょう", + "unlifted": "社長" + }, + { + "lifted": "", + "unlifted": "さん" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "しゃしゅ", + "unlifted": "車種" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "いろ", + "unlifted": "色" + }, + { + "lifted": "", + "unlifted": "は" + } + ] + }, + { + "english": "The car wouldn't start.", + "kanji": "その車は動こうとしなかった。", + "kana": "そのくるまはうごこうとしなかった。", + "pieces": [ + { + "lifted": "", + "unlifted": "その" + }, + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "うご", + "unlifted": "動こう" + }, + { + "lifted": "", + "unlifted": "としなかった" + } + ] + }, + { + "english": "Now that I think of it, I've been asked to look at a haiku he'd written by the tipsy bloke sitting next to me on the train.", + "kanji": "そういえば、電車の中で隣に座ったほろ酔いのおっさんに、自分の俳句を見て欲しいと言われたことがある。", + "kana": "そういえば、でんしゃのなかでとなりにすわったほろよいのおっさんに、じぶんのはいくをみてほしいといわれたことがある。", + "pieces": [ + { + "lifted": "", + "unlifted": "そういえば" + }, + { + "lifted": "でんしゃ", + "unlifted": "電車" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "なか", + "unlifted": "中" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "となり", + "unlifted": "隣" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "すわ", + "unlifted": "座った" + }, + { + "lifted": "ほろよ", + "unlifted": "ほろ酔い" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "", + "unlifted": "おっさん" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "じぶん", + "unlifted": "自分" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "はいく", + "unlifted": "俳句" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "み", + "unlifted": "見て" + }, + { + "lifted": "ほ", + "unlifted": "欲しい" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "い", + "unlifted": "言われた" + }, + { + "lifted": "", + "unlifted": "ことがある" + } + ] + }, + { + "english": "If you frequently spit-up blood you should call an ambulance or have a nearby physician make a house call.", + "kanji": "ひんぱんに吐血する場合は、救急車を呼ぶか、近くの内科医に往診してもらう。", + "kana": "ひんぱんにとけつするばあいは、きゅうきゅうしゃをよぶか、ちかくのないかいにおうしんしてもらう。", + "pieces": [ + { + "lifted": "", + "unlifted": "ひんぱんに" + }, + { + "lifted": "とけつ", + "unlifted": "吐血" + }, + { + "lifted": "", + "unlifted": "する" + }, + { + "lifted": "ばあい", + "unlifted": "場合" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "きゅうきゅうしゃ", + "unlifted": "救急車" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "よ", + "unlifted": "呼ぶ" + }, + { + "lifted": "", + "unlifted": "か" + }, + { + "lifted": "ちか", + "unlifted": "近く" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ないかい", + "unlifted": "内科医" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "おうしん", + "unlifted": "往診" + }, + { + "lifted": "", + "unlifted": "して" + }, + { + "lifted": "", + "unlifted": "もらう" + } + ] + }, + { + "english": "The front wheel plays an important role in two-wheeled vehicles moving without falling over.", + "kanji": "二輪車が倒れずに走行するのには前輪が大きな役割を演じています。", + "kana": "にりんしゃがたおれずにそうこうするのにはぜんりんがおおきなやくわりをえんじています。", + "pieces": [ + { + "lifted": "にりんしゃ", + "unlifted": "二輪車" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "たお", + "unlifted": "倒れず" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "そうこう", + "unlifted": "走行" + }, + { + "lifted": "", + "unlifted": "する" + }, + { + "lifted": "", + "unlifted": "のに" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "ぜんりん", + "unlifted": "前輪" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "おお", + "unlifted": "大きな" + }, + { + "lifted": "やくわりをえん", + "unlifted": "役割を演じています" + } + ] + }, + { + "english": "Did you catch the train?!", + "kanji": "列車に間に合ったのか?!", + "kana": "れっしゃにまにあったのか?!", + "pieces": [ + { + "lifted": "れっしゃ", + "unlifted": "列車" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "まにあ", + "unlifted": "間に合った" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "", + "unlifted": "か" + } + ] + }, + { + "english": "If you have any opinions concerning traffic calming devices (humps, curb extensions, etc.) please write them.", + "kanji": "車の速度を落とす装置(ハンプや狭さく)について、意見があったら書いてください。", + "kana": "くるまのそくどをおとすそうち(ハンプやきょうさく)について、いけんがあったらかいてください。", + "pieces": [ + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "そくど", + "unlifted": "速度" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "お", + "unlifted": "落とす" + }, + { + "lifted": "そうち", + "unlifted": "装置" + }, + { + "lifted": "", + "unlifted": "ハンプ" + }, + { + "lifted": "", + "unlifted": "や" + }, + { + "lifted": "きょう", + "unlifted": "狭さく" + }, + { + "lifted": "", + "unlifted": "について" + }, + { + "lifted": "いけん", + "unlifted": "意見" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "あったら" + }, + { + "lifted": "か", + "unlifted": "書いて" + }, + { + "lifted": "", + "unlifted": "ください" + } + ] + }, + { + "english": "The Mexican government announced the banning of all imports of second-hand cars, except for 1998 models.", + "kanji": "メキシコ政府は1998年型の中古車以外の中古車の輸入を禁止すると発表した。", + "kana": "メキシコせいふは1998ねんがたのちゅうこしゃいがいのちゅうこしゃのゆにゅうをきんしするとはっぴょうした。", + "pieces": [ + { + "lifted": "", + "unlifted": "メキシコ" + }, + { + "lifted": "せいふ", + "unlifted": "政府" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "ねんがた", + "unlifted": "年型" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ちゅうこしゃ", + "unlifted": "中古車" + }, + { + "lifted": "いがい", + "unlifted": "以外" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ちゅうこしゃ", + "unlifted": "中古車" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ゆにゅう", + "unlifted": "輸入" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "きんし", + "unlifted": "禁止" + }, + { + "lifted": "", + "unlifted": "する" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "はっぴょう", + "unlifted": "発表" + }, + { + "lifted": "", + "unlifted": "した" + } + ] + }, + { + "english": "The car dove into the field and, after bumping along for a time, came to a halt.", + "kanji": "車は草地に飛び込み、しばらくガクンガクンと走って止まったのです。", + "kana": "くるまはくさちにとびこみ、しばらくガクンガクンとはしってとまったのです。", + "pieces": [ + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "くさち", + "unlifted": "草地" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "とびこ", + "unlifted": "飛び込み" + }, + { + "lifted": "", + "unlifted": "しばらく" + }, + { + "lifted": "", + "unlifted": "ガクンガクンと" + }, + { + "lifted": "はし", + "unlifted": "走って" + }, + { + "lifted": "と", + "unlifted": "止まった" + }, + { + "lifted": "", + "unlifted": "のです" + } + ] + }, + { + "english": "I'm living on welfare, without a car or anything.", + "kanji": "車も何もなく、生活保護で生きてます。", + "kana": "くるまもなにもなく、せいかつほごでいきてます。", + "pieces": [ + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "も" + }, + { + "lifted": "なに", + "unlifted": "何も" + }, + { + "lifted": "", + "unlifted": "なく" + }, + { + "lifted": "せいかつほご", + "unlifted": "生活保護" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "い", + "unlifted": "生きてます" + } + ] + }, + { + "english": "Cars that, when new, cost 3,000,000 yen are apparently now worth 300,000, so I think I'll use mine a little longer.", + "kanji": "新車時300万円した車も今では30万円位だそうですから、もう少し乗ろうと思います。", + "kana": "しんしゃどき300まんえんしたくるまもいまでは30まんえん位だそうですから、もうすこしのろうとおもいます。", + "pieces": [ + { + "lifted": "しんしゃ", + "unlifted": "新車" + }, + { + "lifted": "どき", + "unlifted": "時" + }, + { + "lifted": "まん", + "unlifted": "万" + }, + { + "lifted": "えん", + "unlifted": "円" + }, + { + "lifted": "", + "unlifted": "した" + }, + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "も" + }, + { + "lifted": "いま", + "unlifted": "今では" + }, + { + "lifted": "まん", + "unlifted": "万" + }, + { + "lifted": "えん", + "unlifted": "円" + }, + { + "lifted": "", + "unlifted": "位" + }, + { + "lifted": "", + "unlifted": "だ" + }, + { + "lifted": "", + "unlifted": "そうです" + }, + { + "lifted": "", + "unlifted": "から" + }, + { + "lifted": "もうすこ", + "unlifted": "もう少し" + }, + { + "lifted": "の", + "unlifted": "乗ろう" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "おも", + "unlifted": "思います" + } + ] + }, + { + "english": "At that time the snow plow was certainly our hero.", + "kanji": "このとき除雪車は確かに私たちの英雄でした。", + "kana": "このときじょせつしゃはたしかにわたしたちのえいゆうでした。", + "pieces": [ + { + "lifted": "", + "unlifted": "この" + }, + { + "lifted": "", + "unlifted": "とき" + }, + { + "lifted": "じょせつしゃ", + "unlifted": "除雪車" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "たし", + "unlifted": "確かに" + }, + { + "lifted": "わたし", + "unlifted": "私たち" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "えいゆう", + "unlifted": "英雄" + }, + { + "lifted": "", + "unlifted": "でした" + } + ] + }, + { + "english": "He didn't intend to let her drive but she pestered him so much that he finally gave in.", + "kanji": "彼は彼女に車を運転させるつもりはなかったのだが、彼女があまりにせがむものだから、彼の方がとうとう折れた。", + "kana": "かれはかのじょにくるまをうんてんさせるつもりはなかったのだが、かのじょがあまりにせがむものだから、かれのほうがとうとうおれた。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "かのじょ", + "unlifted": "彼女" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "うんてん", + "unlifted": "運転させる" + }, + { + "lifted": "", + "unlifted": "つもり" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "なかった" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "", + "unlifted": "だ" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "かのじょ", + "unlifted": "彼女" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "あまり" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "", + "unlifted": "せがむ" + }, + { + "lifted": "", + "unlifted": "ものだから" + }, + { + "lifted": "かれ", + "unlifted": "彼の" + }, + { + "lifted": "ほう", + "unlifted": "方" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "とうとう" + }, + { + "lifted": "お", + "unlifted": "折れた" + } + ] + }, + { + "english": "We are now going to move to the crematorium so if Mr. Ogawa and you would enter the car ...", + "kanji": "これから火葬場へ移動しますので、小川様と君は車へ。", + "kana": "これからかそうばへいどうしますので、小川さまときみはくるまへ。", + "pieces": [ + { + "lifted": "", + "unlifted": "これから" + }, + { + "lifted": "かそうば", + "unlifted": "火葬場" + }, + { + "lifted": "", + "unlifted": "へ" + }, + { + "lifted": "いどう", + "unlifted": "移動" + }, + { + "lifted": "", + "unlifted": "します" + }, + { + "lifted": "", + "unlifted": "ので" + }, + { + "lifted": "さま", + "unlifted": "様" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "きみ", + "unlifted": "君" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "へ" + } + ] + }, + { + "english": "Japanese cars are right hand drive.", + "kanji": "日本車は右ハンドルです。", + "kana": "にほんしゃはみぎハンドルです。", + "pieces": [ + { + "lifted": "にほんしゃ", + "unlifted": "日本車" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "みぎ", + "unlifted": "右ハンドル" + }, + { + "lifted": "", + "unlifted": "です" + } + ] + }, + { + "english": "The coalition force fired at her car at the checkpoint in Bagdad.", + "kanji": "同盟軍はバグダッドの検問所で彼女の車を襲撃した。", + "kana": "どうめいぐんはバグダッドのけんもんじょでかのじょのくるまをしゅうげきした。", + "pieces": [ + { + "lifted": "どうめいぐん", + "unlifted": "同盟軍" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "バグダッド" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "けんもんじょ", + "unlifted": "検問所" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "かのじょ", + "unlifted": "彼女の" + }, + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "しゅうげき", + "unlifted": "襲撃" + }, + { + "lifted": "", + "unlifted": "した" + } + ] + }, + { + "english": "When it sets off the bell rings, \"ding-ding\". Thus 'ding-ding-train'.", + "kanji": "動き出すとき、ベルが「ちんちん」と鳴る。だから、ちんちん電車。", + "kana": "うごきだすとき、ベルが「ちんちん」となる。だから、ちんちんでんしゃ。", + "pieces": [ + { + "lifted": "うごきだ", + "unlifted": "動き出す" + }, + { + "lifted": "", + "unlifted": "とき" + }, + { + "lifted": "", + "unlifted": "ベル" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "ちんちん" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "な", + "unlifted": "鳴る" + }, + { + "lifted": "", + "unlifted": "だから" + }, + { + "lifted": "", + "unlifted": "ちんちん" + }, + { + "lifted": "でんしゃ", + "unlifted": "電車" + } + ] + }, + { + "english": "The car was stuck in the mud.", + "kanji": "車がぬかるみに填まり込んだ。", + "kana": "くるまがぬかるみにはまりこんだ。", + "pieces": [ + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "ぬかるみ" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "はまりこ", + "unlifted": "填まり込んだ" + } + ] + }, + { + "english": "We reached our destination just as I thought the car was going to give up the ghost.", + "kanji": "車がいかれるかと思ったころ終点に着きました。", + "kana": "くるまがいかれるかとおもったころしゅうてんにつきました。", + "pieces": [ + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "いかれる" + }, + { + "lifted": "", + "unlifted": "か" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "おも", + "unlifted": "思った" + }, + { + "lifted": "", + "unlifted": "ころ" + }, + { + "lifted": "しゅうてん", + "unlifted": "終点" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "つ", + "unlifted": "着きました" + } + ] + }, + { + "english": "Car? Ah, if you mean that limousine, - I chartered it.", + "kanji": "車?ああ・・・あのリムジンでしたら、私がチャーターした物ですわ。", + "kana": "くるま?ああ・・・あのリムジンでしたら、わたしがチャーターしたものですわ。", + "pieces": [ + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "ああ" + }, + { + "lifted": "", + "unlifted": "あの" + }, + { + "lifted": "", + "unlifted": "リムジン" + }, + { + "lifted": "", + "unlifted": "でしたら" + }, + { + "lifted": "わたし", + "unlifted": "私" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "チャーター" + }, + { + "lifted": "", + "unlifted": "した" + }, + { + "lifted": "もの", + "unlifted": "物" + }, + { + "lifted": "", + "unlifted": "です" + }, + { + "lifted": "", + "unlifted": "わ" + } + ] + } + ], + "uri": "http://jisho.org/search/%E8%BB%8A%23sentences", + "phrase": "車" + } +} \ No newline at end of file diff --git a/test/example_test_cases/1.json b/test/example_test_cases/1.json new file mode 100644 index 0000000..2fc5c7f --- /dev/null +++ b/test/example_test_cases/1.json @@ -0,0 +1,891 @@ +{ + "query": "日本人", + "expectedResult": { + "query": "日本人", + "found": true, + "results": [ + { + "english": "A Japanese person would never do such a thing.", + "kanji": "日本人ならそんなことはけっしてしないでしょう。", + "kana": "にほんじんならそんなことはけっしてしないでしょう。", + "pieces": [ + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "なら" + }, + { + "lifted": "", + "unlifted": "そんな" + }, + { + "lifted": "", + "unlifted": "こと" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "けっして" + }, + { + "lifted": "", + "unlifted": "しない" + }, + { + "lifted": "", + "unlifted": "でしょう" + } + ] + }, + { + "english": "When did the Japanese start eating polished rice?", + "kanji": "いつから日本人は精白米を食べるようになったのですか?", + "kana": "いつからにほんじんはせいはくまいをたべるようになったのですか?", + "pieces": [ + { + "lifted": "", + "unlifted": "いつから" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "せいはくまい", + "unlifted": "精白米" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "た", + "unlifted": "食べる" + }, + { + "lifted": "", + "unlifted": "ようになった" + }, + { + "lifted": "", + "unlifted": "のです" + }, + { + "lifted": "", + "unlifted": "か" + } + ] + }, + { + "english": "I think there are probably few Japanese who know this side of the Emperor Meiji, the side that left a song like this.", + "kanji": "こんな歌を残している明治天皇の一面を知っている日本人は少ないのではないだろうか。", + "kana": "こんなうたをのこしているめいじてんのうのいちめんをしっているにほんじんはすくないのではないだろうか。", + "pieces": [ + { + "lifted": "", + "unlifted": "こんな" + }, + { + "lifted": "うた", + "unlifted": "歌" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "のこ", + "unlifted": "残している" + }, + { + "lifted": "めいじてんのう", + "unlifted": "明治天皇" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "いちめん", + "unlifted": "一面" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "し", + "unlifted": "知っている" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "すく", + "unlifted": "少ない" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "", + "unlifted": "ではない" + }, + { + "lifted": "", + "unlifted": "だろうか" + } + ] + }, + { + "english": "I'm Japanese, but I don't live in Japan.", + "kanji": "私は日本人ですが、日本に住んでいません。", + "kana": "わたしはにほんじんですが、にほんにすんでいません。", + "pieces": [ + { + "lifted": "わたし", + "unlifted": "私" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "です" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "にほん", + "unlifted": "日本" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "す", + "unlifted": "住んでいません" + } + ] + }, + { + "english": "They don't use 'celeb' to mean 'rich man' over there. By which I determine that you are Japanese.", + "kanji": "向こうではセレブという言葉を「金持ち」の意味では使わない。という事で日本人と判明しました。", + "kana": "むこうではセレブということばを「かねもち」のいみではつかわない。ということでにほんじんとはんめいしました。", + "pieces": [ + { + "lifted": "む", + "unlifted": "向こう" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "セレブ" + }, + { + "lifted": "", + "unlifted": "という" + }, + { + "lifted": "ことば", + "unlifted": "言葉" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "かねも", + "unlifted": "金持ち" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "いみ", + "unlifted": "意味" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "つか", + "unlifted": "使わない" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "", + "unlifted": "いう" + }, + { + "lifted": "こと", + "unlifted": "事" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "はんめい", + "unlifted": "判明" + }, + { + "lifted": "", + "unlifted": "しました" + } + ] + }, + { + "english": "As you can also tell from these beautiful, far from Japanese, looks, Yuna is not pure-blood Japanese. She's a quarter-blood with a westerner as grandmother.", + "kanji": "日本人離れしたこの美しい相貌からもわかるように、優奈は実は生粋の日本人じゃない。西洋人をおばあちゃんに持つ、クォーターだったりする。", + "kana": "にほんじんはなれしたこのうつくしいそうぼうからもわかるように、優奈はじつはきっすいのにほんじんじゃない。せいようじんをおばあちゃんにもつ、クォーターだったりする。", + "pieces": [ + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "はな", + "unlifted": "離れ" + }, + { + "lifted": "", + "unlifted": "した" + }, + { + "lifted": "", + "unlifted": "この" + }, + { + "lifted": "うつく", + "unlifted": "美しい" + }, + { + "lifted": "そうぼう", + "unlifted": "相貌" + }, + { + "lifted": "", + "unlifted": "から" + }, + { + "lifted": "", + "unlifted": "も" + }, + { + "lifted": "", + "unlifted": "わかる" + }, + { + "lifted": "", + "unlifted": "ように" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "じつ", + "unlifted": "実は" + }, + { + "lifted": "きっすい", + "unlifted": "生粋の" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "じゃない" + }, + { + "lifted": "せいようじん", + "unlifted": "西洋人" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "", + "unlifted": "おばあちゃん" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "も", + "unlifted": "持つ" + }, + { + "lifted": "", + "unlifted": "クォーター" + }, + { + "lifted": "", + "unlifted": "だったり" + }, + { + "lifted": "", + "unlifted": "する" + } + ] + }, + { + "english": "Today's topic is \"the problem of Japanese people abducted by North Korea\".", + "kanji": "今日のトピックは「北朝鮮による日本人拉致問題」です。", + "kana": "きょうのトピックは「きたちょうせんによるにほんじんらちもんだい」です。", + "pieces": [ + { + "lifted": "きょう", + "unlifted": "今日" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "", + "unlifted": "トピック" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "きたちょうせん", + "unlifted": "北朝鮮" + }, + { + "lifted": "", + "unlifted": "による" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "らち", + "unlifted": "拉致" + }, + { + "lifted": "もんだい", + "unlifted": "問題" + }, + { + "lifted": "", + "unlifted": "です" + } + ] + }, + { + "english": "Foreign rice is hard and tasteless, and doesn't appeal to the Japanese palate.", + "kanji": "外米はぼそぼそしていて、日本人の口には合わない。", + "kana": "がいまいはぼそぼそしていて、にほんじんのくちにはあわない。", + "pieces": [ + { + "lifted": "がいまい", + "unlifted": "外米" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "ぼそぼそ" + }, + { + "lifted": "", + "unlifted": "していて" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "くち", + "unlifted": "口" + }, + { + "lifted": "", + "unlifted": "には" + }, + { + "lifted": "あ", + "unlifted": "合わない" + } + ] + }, + { + "english": "A number of Japanese people travel abroad every summer.", + "kanji": "毎年、多くの日本人が海外へ旅行する。", + "kana": "まいとし、おおくのにほんじんがかいがいへりょこうする。", + "pieces": [ + { + "lifted": "まいとし", + "unlifted": "毎年" + }, + { + "lifted": "おお", + "unlifted": "多く" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "かいがい", + "unlifted": "海外" + }, + { + "lifted": "", + "unlifted": "へ" + }, + { + "lifted": "りょこう", + "unlifted": "旅行" + }, + { + "lifted": "", + "unlifted": "する" + } + ] + }, + { + "english": "Her father is Japanese.", + "kanji": "彼女の父親は日本人だ。", + "kana": "かのじょのちちおやはにほんじんだ。", + "pieces": [ + { + "lifted": "かのじょ", + "unlifted": "彼女の" + }, + { + "lifted": "ちちおや", + "unlifted": "父親" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "だ" + } + ] + }, + { + "english": "They employ foreigners because Japanese workers are in short supply.", + "kanji": "彼らは日本人労働者が不足しているから外国人を雇う。", + "kana": "かれらはにほんじんろうどうしゃがふそくしているからがいこくじんをやとう。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼ら" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "ろうどうしゃ", + "unlifted": "労働者" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "ふそく", + "unlifted": "不足" + }, + { + "lifted": "", + "unlifted": "している" + }, + { + "lifted": "", + "unlifted": "から" + }, + { + "lifted": "がいこくじん", + "unlifted": "外国人" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "やと", + "unlifted": "雇う" + } + ] + }, + { + "english": "Are they Japanese?", + "kanji": "彼らは日本人ですか。", + "kana": "かれらはにほんじんですか。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼ら" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "ですか" + } + ] + }, + { + "english": "Are they Japanese or Chinese?", + "kanji": "彼らは日本人ですか、それとも中国人ですか。", + "kana": "かれらはにほんじんですか、それともちゅうごくじんですか。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼ら" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "ですか" + }, + { + "lifted": "", + "unlifted": "それとも" + }, + { + "lifted": "ちゅうごくじん", + "unlifted": "中国人" + }, + { + "lifted": "", + "unlifted": "ですか" + } + ] + }, + { + "english": "He is not Japanese.", + "kanji": "彼は日本人ではありません。", + "kana": "かれはにほんじんではありません。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "ではありません" + } + ] + }, + { + "english": "He speaks Japanese as if he were Japanese.", + "kanji": "彼は日本語をまるで日本人であるかのように話す。", + "kana": "かれはにほんごをまるでにほんじんであるかのようにはなす。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "にほんご", + "unlifted": "日本語" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "", + "unlifted": "まるで" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "である" + }, + { + "lifted": "", + "unlifted": "かのように" + }, + { + "lifted": "はな", + "unlifted": "話す" + } + ] + }, + { + "english": "He is a typical Japanese.", + "kanji": "彼は典型的な日本人だ。", + "kana": "かれはてんけいてきなにほんじんだ。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "てんけいてき", + "unlifted": "典型的な" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "だ" + } + ] + }, + { + "english": "He is Japanese by birth.", + "kanji": "彼は生まれは日本人です。", + "kana": "かれはうまれはにほんじんです。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "う", + "unlifted": "生まれ" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "です" + } + ] + }, + { + "english": "He is the first Japanese that traveled in space.", + "kanji": "彼は最初に宇宙旅行をした日本人です。", + "kana": "かれはさいしょにうちゅうりょこうをしたにほんじんです。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "さいしょ", + "unlifted": "最初" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "うちゅうりょこう", + "unlifted": "宇宙旅行" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "", + "unlifted": "した" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "です" + } + ] + }, + { + "english": "He is Japanese to the bone.", + "kanji": "彼は骨の髄まで日本人だ。", + "kana": "かれはほねのずいまでにほんじんだ。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "ほねのずい", + "unlifted": "骨の髄まで" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "だ" + } + ] + }, + { + "english": "He speaks Japanese as if he were Japanese.", + "kanji": "彼は、日本語をまるで日本人かのように話す。", + "kana": "かれは、にほんごをまるでにほんじんかのようにはなす。", + "pieces": [ + { + "lifted": "かれ", + "unlifted": "彼" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "にほんご", + "unlifted": "日本語" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "", + "unlifted": "まるで" + }, + { + "lifted": "にほんじん", + "unlifted": "日本人" + }, + { + "lifted": "", + "unlifted": "かのように" + }, + { + "lifted": "はな", + "unlifted": "話す" + } + ] + } + ], + "uri": "http://jisho.org/search/%E6%97%A5%E6%9C%AC%E4%BA%BA%23sentences", + "phrase": "日本人" + } +} \ No newline at end of file diff --git a/test/example_test_cases/2.json b/test/example_test_cases/2.json new file mode 100644 index 0000000..a4ca9dd --- /dev/null +++ b/test/example_test_cases/2.json @@ -0,0 +1,10 @@ +{ + "query": "彼*叩く", + "expectedResult": { + "query": "彼*叩く", + "found": false, + "results": [], + "uri": "http://jisho.org/search/%E5%BD%BC%EF%BC%8A%E5%8F%A9%E3%81%8F%23sentences", + "phrase": "彼*叩く" + } +} \ No newline at end of file diff --git a/test/example_test_cases/3.json b/test/example_test_cases/3.json new file mode 100644 index 0000000..1064459 --- /dev/null +++ b/test/example_test_cases/3.json @@ -0,0 +1,1215 @@ +{ + "query": "皆", + "expectedResult": { + "query": "皆", + "found": true, + "results": [ + { + "english": "The total solar eclipse can be observed next year on June 22nd.", + "kanji": "来年6月22日に観測される皆既日食。", + "kana": "らいねん6月22にちにかんそくされるかいきにっしょく。", + "pieces": [ + { + "lifted": "らいねん", + "unlifted": "来年" + }, + { + "lifted": "", + "unlifted": "6月" + }, + { + "lifted": "にち", + "unlifted": "日" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "かんそく", + "unlifted": "観測" + }, + { + "lifted": "", + "unlifted": "される" + }, + { + "lifted": "かいきにっしょく", + "unlifted": "皆既日食" + } + ] + }, + { + "english": "Do you all place great importance on morals?", + "kanji": "皆さんは、モラルを大切にしていますか。", + "kana": "みなさんは、モラルをたいせつにしていますか。", + "pieces": [ + { + "lifted": "みな", + "unlifted": "皆さん" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "モラル" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "たいせつ", + "unlifted": "大切に" + }, + { + "lifted": "", + "unlifted": "しています" + }, + { + "lifted": "", + "unlifted": "か" + } + ] + }, + { + "english": "Will everyone please stick with it to the last moment.", + "kanji": "どうぞ、皆様も最後の一瞬まで粘り抜いてください。", + "kana": "どうぞ、みなさまもさいごのいっしゅんまでねばりぬいてください。", + "pieces": [ + { + "lifted": "", + "unlifted": "どうぞ" + }, + { + "lifted": "みなさま", + "unlifted": "皆様" + }, + { + "lifted": "", + "unlifted": "も" + }, + { + "lifted": "さいご", + "unlifted": "最後" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "いっしゅん", + "unlifted": "一瞬" + }, + { + "lifted": "", + "unlifted": "まで" + }, + { + "lifted": "ねばりぬ", + "unlifted": "粘り抜いて" + }, + { + "lifted": "", + "unlifted": "ください" + } + ] + }, + { + "english": "We were all pleased to be so cheaply quit of him.", + "kanji": "これだけで厄介払いできたら安いもので、みな大喜びした。", + "kana": "これだけでやっかいばらいできたらやすいもので、みなおおよろこびした。", + "pieces": [ + { + "lifted": "", + "unlifted": "これだけ" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "やっかいばら", + "unlifted": "厄介払い" + }, + { + "lifted": "", + "unlifted": "できたら" + }, + { + "lifted": "やす", + "unlifted": "安い" + }, + { + "lifted": "", + "unlifted": "もの" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "", + "unlifted": "みな" + }, + { + "lifted": "おおよろこ", + "unlifted": "大喜び" + }, + { + "lifted": "", + "unlifted": "した" + } + ] + }, + { + "english": "For my part, having you lot with me is more reassuring than the police or anything!", + "kanji": "僕には警察よりも何よりもみんながいてくれることの方が心強いのですよ。", + "kana": "ぼくにはけいさつよりもなによりもみんながいてくれることのほうがこころづよいのですよ。", + "pieces": [ + { + "lifted": "ぼく", + "unlifted": "僕" + }, + { + "lifted": "", + "unlifted": "には" + }, + { + "lifted": "けいさつ", + "unlifted": "警察" + }, + { + "lifted": "", + "unlifted": "よりも" + }, + { + "lifted": "なに", + "unlifted": "何" + }, + { + "lifted": "", + "unlifted": "よりも" + }, + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "いて" + }, + { + "lifted": "", + "unlifted": "くれる" + }, + { + "lifted": "", + "unlifted": "こと" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ほう", + "unlifted": "方" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "こころづよ", + "unlifted": "心強い" + }, + { + "lifted": "", + "unlifted": "のです" + }, + { + "lifted": "", + "unlifted": "よ" + } + ] + }, + { + "english": "With your ability it should be a doddle, but please don't be prideful of that but first apply yourself dilligently with everyone in your class.", + "kanji": "君の実力なら楽勝だとは思うが、それに驕らず、まずはクラスのみんなと切磋琢磨していって欲しい。", + "kana": "きみのじつりょくなららくしょうだとはおもうが、それにおごらず、まずはクラスのみんなとせっさたくましていってほしい。", + "pieces": [ + { + "lifted": "きみ", + "unlifted": "君の" + }, + { + "lifted": "じつりょく", + "unlifted": "実力" + }, + { + "lifted": "", + "unlifted": "なら" + }, + { + "lifted": "らくしょう", + "unlifted": "楽勝" + }, + { + "lifted": "", + "unlifted": "だ" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "おも", + "unlifted": "思う" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "それ" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "おご", + "unlifted": "驕らず" + }, + { + "lifted": "", + "unlifted": "まず" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "クラス" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "せっさたくま", + "unlifted": "切磋琢磨" + }, + { + "lifted": "", + "unlifted": "して" + }, + { + "lifted": "", + "unlifted": "いって" + }, + { + "lifted": "ほ", + "unlifted": "欲しい" + } + ] + }, + { + "english": "What programming language does everybody like?", + "kanji": "皆さんはどんなプログラミング言語が好きですか?", + "kana": "みなさんはどんなプログラミングげんごがすきですか?", + "pieces": [ + { + "lifted": "みな", + "unlifted": "皆さん" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "どんな" + }, + { + "lifted": "プログラミングげんご", + "unlifted": "プログラミング言語" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "す", + "unlifted": "好き" + }, + { + "lifted": "", + "unlifted": "ですか" + } + ] + }, + { + "english": "I'm teaching basic participial constructions now, but, with regard to those below, what different ways of translating them would everybody use?", + "kanji": "今、基本的な分詞構文を教えているのですが、皆さんは以下の分詞構文の訳については、どのように異なる訳し方をされますか?", + "kana": "いま、きほんてきなぶんしこうぶんをおしええているのですが、みなさんはいかのぶんしこうぶんのやくについては、どのようにことなるやくしかたをされますか?", + "pieces": [ + { + "lifted": "いま", + "unlifted": "今" + }, + { + "lifted": "きほんてき", + "unlifted": "基本的な" + }, + { + "lifted": "ぶんしこうぶん", + "unlifted": "分詞構文" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "おしえ", + "unlifted": "教えている" + }, + { + "lifted": "", + "unlifted": "のです" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "みな", + "unlifted": "皆さん" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "いか", + "unlifted": "以下" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ぶんしこうぶん", + "unlifted": "分詞構文" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "やく", + "unlifted": "訳" + }, + { + "lifted": "", + "unlifted": "について" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "どのように" + }, + { + "lifted": "こと", + "unlifted": "異なる" + }, + { + "lifted": "やく", + "unlifted": "訳し" + }, + { + "lifted": "かた", + "unlifted": "方" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "", + "unlifted": "されます" + }, + { + "lifted": "", + "unlifted": "か" + } + ] + }, + { + "english": "What's different from Japan is that the doctors of Singapore generally all know each other.", + "kanji": "シンガポールの医師は殆どの場合皆お互いを知っている、というのが日本と異なります。", + "kana": "シンガポールのいしはほとんどのばあいみんなおたがいをしっている、というのがにほんとことなります。", + "pieces": [ + { + "lifted": "", + "unlifted": "シンガポール" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "いし", + "unlifted": "医師" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "ほとん", + "unlifted": "殆ど" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ばあい", + "unlifted": "場合" + }, + { + "lifted": "みんな", + "unlifted": "皆" + }, + { + "lifted": "おたが", + "unlifted": "お互い" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "し", + "unlifted": "知っている" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "", + "unlifted": "いう" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "にほん", + "unlifted": "日本" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "こと", + "unlifted": "異なります" + } + ] + }, + { + "english": "Everyone, please keep to netiquette.", + "kanji": "皆さんネチケットはしっかり。", + "kana": "みなさんネチケットはしっかり。", + "pieces": [ + { + "lifted": "みな", + "unlifted": "皆さん" + }, + { + "lifted": "", + "unlifted": "ネチケット" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "しっかり" + } + ] + }, + { + "english": "The example is a past progressive tense sentence. How was everybody taught when they were learning about progressive tense?", + "kanji": "例文は過去進行形の文です。皆さんは進行形を学習するとき、どのように教わりましたか?", + "kana": "れいぶんはかこしんこうけいのぶんです。みなさんはしんこうけいをがくしゅうするとき、どのようにおそわりましたか?", + "pieces": [ + { + "lifted": "れいぶん", + "unlifted": "例文" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "かこしんこうけい", + "unlifted": "過去進行形" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ぶん", + "unlifted": "文" + }, + { + "lifted": "", + "unlifted": "です" + }, + { + "lifted": "みな", + "unlifted": "皆さん" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "しんこうけい", + "unlifted": "進行形" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "がくしゅう", + "unlifted": "学習" + }, + { + "lifted": "", + "unlifted": "する" + }, + { + "lifted": "", + "unlifted": "とき" + }, + { + "lifted": "", + "unlifted": "どのように" + }, + { + "lifted": "おそ", + "unlifted": "教わりました" + }, + { + "lifted": "", + "unlifted": "か" + } + ] + }, + { + "english": "Oh, that's a secret, OK? Because slipping out of the dorm in the night is severely punished.", + "kanji": "あ、みんなには内緒だよ?寮を夜中に抜け出すのは厳罰だからね?", + "kana": "あ、みんなにはないしょだよ?りょうをよなかにぬけだすのはげんばつだからね?", + "pieces": [ + { + "lifted": "", + "unlifted": "あ" + }, + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "", + "unlifted": "には" + }, + { + "lifted": "ないしょ", + "unlifted": "内緒" + }, + { + "lifted": "", + "unlifted": "だ" + }, + { + "lifted": "", + "unlifted": "よ" + }, + { + "lifted": "りょう", + "unlifted": "寮" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "よなか", + "unlifted": "夜中" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "ぬけだ", + "unlifted": "抜け出す" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "げんばつ", + "unlifted": "厳罰" + }, + { + "lifted": "", + "unlifted": "だ" + }, + { + "lifted": "", + "unlifted": "から" + }, + { + "lifted": "", + "unlifted": "ね" + } + ] + }, + { + "english": "\"I've heard about it, Koichi\" \"You don't need to say anything more, I know. It's the summer festival incident at the shrine, right?\"", + "kanji": "「聞いたよ、光一」「まあ皆までいうなって。分かってる。神社の夏祭りの一件でしょ?」", + "kana": "「きいたよ、光一」「まあみなまでいうなって。わかかってる。じんじゃの夏祭りのいっけんでしょ?」", + "pieces": [ + { + "lifted": "き", + "unlifted": "聞いた" + }, + { + "lifted": "", + "unlifted": "よ" + }, + { + "lifted": "", + "unlifted": "まあ" + }, + { + "lifted": "みな", + "unlifted": "皆までいうな" + }, + { + "lifted": "", + "unlifted": "って" + }, + { + "lifted": "わか", + "unlifted": "分かってる" + }, + { + "lifted": "じんじゃ", + "unlifted": "神社" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "", + "unlifted": "夏祭り" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "いっけん", + "unlifted": "一件" + }, + { + "lifted": "", + "unlifted": "でしょ" + } + ] + }, + { + "english": "We plan to elicit opinions from the public.", + "kanji": "市民の皆様の御意見をちょうだいする予定です。", + "kana": "しみんのみなさまのごいけんをちょうだいするよていです。", + "pieces": [ + { + "lifted": "しみん", + "unlifted": "市民" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "みなさま", + "unlifted": "皆様" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ご", + "unlifted": "御" + }, + { + "lifted": "いけん", + "unlifted": "意見" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "", + "unlifted": "ちょうだい" + }, + { + "lifted": "", + "unlifted": "する" + }, + { + "lifted": "よてい", + "unlifted": "予定" + }, + { + "lifted": "", + "unlifted": "です" + } + ] + }, + { + "english": "Having scattered the enemy before me and triumphantly returned, this is how they would herald me.", + "kanji": "敵を蹴散らし、凱旋した俺はみなにこう呼ばれるんだ!", + "kana": "てきをけちらし、がいせんしたおれはみなにこうよばれるんだ!", + "pieces": [ + { + "lifted": "てき", + "unlifted": "敵" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "けち", + "unlifted": "蹴散らし" + }, + { + "lifted": "がいせん", + "unlifted": "凱旋" + }, + { + "lifted": "", + "unlifted": "した" + }, + { + "lifted": "おれ", + "unlifted": "俺" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "みな" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "", + "unlifted": "こう" + }, + { + "lifted": "よ", + "unlifted": "呼ばれる" + }, + { + "lifted": "", + "unlifted": "んだ" + } + ] + }, + { + "english": "Quiet! Everybody stay where they are, there will now be a possessions check.", + "kanji": "静かに!みんなその場を動かないで。これから持ち物検査をはじめます。", + "kana": "しずかに!みんなそのばをうごかないで。これからもちものけんさをはじめます。", + "pieces": [ + { + "lifted": "しず", + "unlifted": "静かに" + }, + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "そのば", + "unlifted": "その場" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "うご", + "unlifted": "動かないで" + }, + { + "lifted": "", + "unlifted": "これ" + }, + { + "lifted": "", + "unlifted": "から" + }, + { + "lifted": "もちものけんさ", + "unlifted": "持ち物検査" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "", + "unlifted": "はじめます" + } + ] + }, + { + "english": "Even if that's alright with you nobody else will accept it. I'll get shouted at afterwards so...", + "kanji": "恵子さんが良くてもみんなが納得しないんです。後で俺がドヤされるんだから。", + "kana": "恵子さんがよくてもみんながなっとくしないんです。あとでおれがドヤされるんだから。", + "pieces": [ + { + "lifted": "", + "unlifted": "さん" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "よ", + "unlifted": "良くて" + }, + { + "lifted": "", + "unlifted": "も" + }, + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "なっとく", + "unlifted": "納得" + }, + { + "lifted": "", + "unlifted": "しない" + }, + { + "lifted": "", + "unlifted": "んです" + }, + { + "lifted": "あと", + "unlifted": "後" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "おれ", + "unlifted": "俺" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "ドヤされる" + }, + { + "lifted": "", + "unlifted": "ん" + }, + { + "lifted": "", + "unlifted": "だから" + } + ] + }, + { + "english": "At home, because of his reddish hair and freckles, his mother scornfully named him \"carrot\" and had everybody else call him that.", + "kanji": "家では赤味がかった髪とそばかすのせいで、母が侮蔑を込めて「にんじん」と名付け、皆にもそう呼ばせています。", + "kana": "いえでは赤味がかったかみとそばかすのせいで、ははがぶべつをこめて「にんじん」となづけ、みんなにもそうよばせています。", + "pieces": [ + { + "lifted": "いえ", + "unlifted": "家" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "赤味がかった" + }, + { + "lifted": "かみ", + "unlifted": "髪" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "", + "unlifted": "そばかす" + }, + { + "lifted": "", + "unlifted": "のせいで" + }, + { + "lifted": "はは", + "unlifted": "母" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "ぶべつ", + "unlifted": "侮蔑" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "こ", + "unlifted": "込めて" + }, + { + "lifted": "", + "unlifted": "にんじん" + }, + { + "lifted": "", + "unlifted": "と" + }, + { + "lifted": "なづ", + "unlifted": "名付け" + }, + { + "lifted": "みんな", + "unlifted": "皆" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "", + "unlifted": "も" + }, + { + "lifted": "", + "unlifted": "そう" + }, + { + "lifted": "よ", + "unlifted": "呼ばせています" + } + ] + }, + { + "english": "All for one, and one for all. That's team play.", + "kanji": "一人はみんなの為に、みんなは一人の為に。それがチームプレイだ。", + "kana": "ひとりはみんなのために、みんなはひとりのために。それがチームプレイだ。", + "pieces": [ + { + "lifted": "ひとり", + "unlifted": "一人" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ため", + "unlifted": "為に" + }, + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "ひとり", + "unlifted": "一人" + }, + { + "lifted": "", + "unlifted": "の" + }, + { + "lifted": "ため", + "unlifted": "為に" + }, + { + "lifted": "", + "unlifted": "それ" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "", + "unlifted": "チームプレイ" + }, + { + "lifted": "", + "unlifted": "だ" + } + ] + }, + { + "english": "Guys, I'll do my utmost to back you up. We'll make this event a success no matter what!", + "kanji": "みんな、俺も全力でフォローする。このイベントかならず成功させるぞ。", + "kana": "みんな、おれもぜんりょくでフォローする。このイベントかならずせいこうさせるぞ。", + "pieces": [ + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "おれ", + "unlifted": "俺" + }, + { + "lifted": "", + "unlifted": "も" + }, + { + "lifted": "ぜんりょく", + "unlifted": "全力" + }, + { + "lifted": "", + "unlifted": "で" + }, + { + "lifted": "", + "unlifted": "フォロー" + }, + { + "lifted": "", + "unlifted": "する" + }, + { + "lifted": "", + "unlifted": "この" + }, + { + "lifted": "", + "unlifted": "イベント" + }, + { + "lifted": "", + "unlifted": "かならず" + }, + { + "lifted": "せいこう", + "unlifted": "成功" + }, + { + "lifted": "", + "unlifted": "させる" + }, + { + "lifted": "", + "unlifted": "ぞ" + } + ] + } + ], + "uri": "http://jisho.org/search/%E7%9A%86%23sentences", + "phrase": "皆" + } +} \ No newline at end of file diff --git a/test/example_test_cases/4.json b/test/example_test_cases/4.json new file mode 100644 index 0000000..f573034 --- /dev/null +++ b/test/example_test_cases/4.json @@ -0,0 +1,10 @@ +{ + "query": "ネガティブ", + "expectedResult": { + "query": "ネガティブ", + "found": false, + "results": [], + "uri": "http://jisho.org/search/%E3%83%8D%E3%82%AC%E3%83%86%E3%82%A3%E3%83%96%23sentences", + "phrase": "ネガティブ" + } +} \ No newline at end of file diff --git a/test/example_test_cases/5.json b/test/example_test_cases/5.json new file mode 100644 index 0000000..9cb94dc --- /dev/null +++ b/test/example_test_cases/5.json @@ -0,0 +1,10 @@ +{ + "query": "grlgmregmneriireg", + "expectedResult": { + "query": "grlgmregmneriireg", + "found": false, + "results": [], + "uri": "http://jisho.org/search/grlgmregmneriireg%23sentences", + "phrase": "grlgmregmneriireg" + } +} \ No newline at end of file diff --git a/test/kanji_test_cases/0.json b/test/kanji_test_cases/0.json new file mode 100644 index 0000000..bd5f1e5 --- /dev/null +++ b/test/kanji_test_cases/0.json @@ -0,0 +1,68 @@ +{ + "query": "車", + "expectedResult": { + "query": "車", + "found": true, + "taughtIn": "grade 1", + "jlptLevel": "N5", + "newspaperFrequencyRank": "333", + "strokeCount": 7, + "meaning": "car", + "kunyomi": [ + "くるま" + ], + "onyomi": [ + "シャ" + ], + "onyomiExamples": [ + { + "example": "車", + "reading": "シャ", + "meaning": "car, vehicle" + }, + { + "example": "車検", + "reading": "シャケン", + "meaning": "vehicle inspection" + }, + { + "example": "見切り発車", + "reading": "ミキリハッシャ", + "meaning": "starting a train (or bus, etc.) before all the passengers are on board, making a snap decision, starting an action without considering objections to it any longer" + }, + { + "example": "軽自動車", + "reading": "ケイジドウシャ", + "meaning": "light motor vehicle (up to 660cc and 64bhp), k-car, kei car" + } + ], + "kunyomiExamples": [ + { + "example": "車", + "reading": "くるま", + "meaning": "car, automobile, vehicle, wheel" + }, + { + "example": "車椅子", + "reading": "くるまいす", + "meaning": "wheelchair, folding push-chair" + }, + { + "example": "火の車", + "reading": "ひのくるま", + "meaning": "fiery chariot (which carries the souls of sinners into hell), desperate financial situation, dire straits" + } + ], + "radical": { + "symbol": "車", + "meaning": "cart, car" + }, + "parts": [ + "車" + ], + "strokeOrderDiagramUri": "http://classic.jisho.org/static/images/stroke_diagrams/36554_frames.png", + "strokeOrderSvgUri": "http://d1w6u4xc3l95km.cloudfront.net/kanji-2015-03/08eca.svg", + "strokeOrderGifUri": "https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/8eca.gif", + "uri": "http://jisho.org/search/%E8%BB%8A%23kanji" + } +} \ No newline at end of file diff --git a/test/kanji_test_cases/1.json b/test/kanji_test_cases/1.json new file mode 100644 index 0000000..afe0914 --- /dev/null +++ b/test/kanji_test_cases/1.json @@ -0,0 +1,127 @@ +{ + "query": "家", + "expectedResult": { + "query": "家", + "found": true, + "taughtIn": "grade 2", + "jlptLevel": "N4", + "newspaperFrequencyRank": "133", + "strokeCount": 10, + "meaning": "house, home, family, professional, expert, performer", + "kunyomi": [ + "いえ", + "や", + "うち" + ], + "onyomi": [ + "カ", + "ケ" + ], + "onyomiExamples": [ + { + "example": "家", + "reading": "カ", + "meaning": "-ist, -er" + }, + { + "example": "家屋", + "reading": "カオク", + "meaning": "house, building" + }, + { + "example": "研究家", + "reading": "ケンキュウカ", + "meaning": "researcher, student (of)" + }, + { + "example": "活動家", + "reading": "カツドウカ", + "meaning": "activist" + }, + { + "example": "家", + "reading": "ケ", + "meaning": "house (e.g. of Tokugawa), family" + }, + { + "example": "家来", + "reading": "ケライ", + "meaning": "retainer, retinue, servant" + }, + { + "example": "本家", + "reading": "ホンケ", + "meaning": "head house (family), birthplace, originator" + }, + { + "example": "公家", + "reading": "クゲ", + "meaning": "court noble, nobility, Imperial Court" + } + ], + "kunyomiExamples": [ + { + "example": "家", + "reading": "いえ", + "meaning": "house, residence, dwelling, family, household, lineage, family name" + }, + { + "example": "家主", + "reading": "やぬし", + "meaning": "landlord, landlady, house owner, home owner, head of the household" + }, + { + "example": "本家", + "reading": "ほんけ", + "meaning": "head house (family), birthplace, originator" + }, + { + "example": "小家", + "reading": "こいえ", + "meaning": "small and simple home" + }, + { + "example": "屋", + "reading": "や", + "meaning": "(something) shop, somebody who sells (something) or works as (something), somebody with a (certain) personality trait, house, roof" + }, + { + "example": "家内", + "reading": "かない", + "meaning": "(my) wife, inside the home, one's family" + }, + { + "example": "長屋", + "reading": "ながや", + "meaning": "tenement house, row house" + }, + { + "example": "本家", + "reading": "ほんけ", + "meaning": "head house (family), birthplace, originator" + }, + { + "example": "家", + "reading": "うち", + "meaning": "house, home (one's own), (one's) family, (one's) household" + }, + { + "example": "家中", + "reading": "うちじゅう", + "meaning": "whole family, all (members of) the family, all over the house, retainer of a daimyo, feudal domain, clan" + } + ], + "radical": { + "symbol": "宀", + "meaning": "roof" + }, + "parts": [ + "宀", + "豕" + ], + "strokeOrderDiagramUri": "http://classic.jisho.org/static/images/stroke_diagrams/23478_frames.png", + "strokeOrderSvgUri": "http://d1w6u4xc3l95km.cloudfront.net/kanji-2015-03/05bb6.svg", + "strokeOrderGifUri": "https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/5bb6.gif", + "uri": "http://jisho.org/search/%E5%AE%B6%23kanji" + } +} \ No newline at end of file diff --git a/test/kanji_test_cases/2.json b/test/kanji_test_cases/2.json new file mode 100644 index 0000000..f883db4 --- /dev/null +++ b/test/kanji_test_cases/2.json @@ -0,0 +1,99 @@ +{ + "query": "楽", + "expectedResult": { + "query": "楽", + "found": true, + "taughtIn": "grade 2", + "jlptLevel": "N4", + "newspaperFrequencyRank": "373", + "strokeCount": 13, + "meaning": "music, comfort, ease", + "kunyomi": [ + "たの.しい", + "たの.しむ", + "この.む" + ], + "onyomi": [ + "ガク", + "ラク", + "ゴウ" + ], + "onyomiExamples": [ + { + "example": "楽団", + "reading": "ガクダン", + "meaning": "orchestra, band" + }, + { + "example": "楽章", + "reading": "ガクショウ", + "meaning": "(musical) movement" + }, + { + "example": "邦楽", + "reading": "ホウガク", + "meaning": "Japanese music (esp. traditional Japanese music)" + }, + { + "example": "室内楽", + "reading": "シツナイガク", + "meaning": "chamber music" + }, + { + "example": "楽", + "reading": "ラク", + "meaning": "comfort, ease, relief, (at) peace, relaxation, easy, simple, without trouble, without hardships, (economically) comfortable, raku pottery" + }, + { + "example": "楽園", + "reading": "ラクエン", + "meaning": "pleasure garden, paradise" + }, + { + "example": "千秋楽", + "reading": "センシュウラク", + "meaning": "concluding festivities, concluding program, concluding programme, final day of a tournament" + }, + { + "example": "行楽", + "reading": "コウラク", + "meaning": "outing, excursion, pleasure trip, going on a picnic" + }, + { + "example": "猿楽", + "reading": "サルガク", + "meaning": "sarugaku (form of theatre popular in Japan during the 11th to 14th centuries), noh, fooling around" + } + ], + "kunyomiExamples": [ + { + "example": "楽しい", + "reading": "たのしい", + "meaning": "enjoyable, fun, pleasant, happy, delightful" + }, + { + "example": "楽しい思い出", + "reading": "たのしいおもいで", + "meaning": "happy memory, sweet memory" + }, + { + "example": "楽しむ", + "reading": "たのしむ", + "meaning": "to enjoy (oneself)" + } + ], + "radical": { + "symbol": "木", + "meaning": "tree" + }, + "parts": [ + "冫", + "木", + "白" + ], + "strokeOrderDiagramUri": "http://classic.jisho.org/static/images/stroke_diagrams/27005_frames.png", + "strokeOrderSvgUri": "http://d1w6u4xc3l95km.cloudfront.net/kanji-2015-03/0697d.svg", + "strokeOrderGifUri": "https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/697d.gif", + "uri": "http://jisho.org/search/%E6%A5%BD%23kanji" + } +} \ No newline at end of file diff --git a/test/kanji_test_cases/3.json b/test/kanji_test_cases/3.json new file mode 100644 index 0000000..8910cea --- /dev/null +++ b/test/kanji_test_cases/3.json @@ -0,0 +1,7 @@ +{ + "query": "極上", + "expectedResult": { + "query": "極上", + "found": false + } +} \ No newline at end of file diff --git a/test/kanji_test_cases/4.json b/test/kanji_test_cases/4.json new file mode 100644 index 0000000..900c53c --- /dev/null +++ b/test/kanji_test_cases/4.json @@ -0,0 +1,52 @@ +{ + "query": "贄", + "expectedResult": { + "query": "贄", + "found": true, + "strokeCount": 18, + "meaning": "offering, sacrifice", + "kunyomi": [ + "にえ" + ], + "onyomi": [ + "シ" + ], + "onyomiExamples": [], + "kunyomiExamples": [ + { + "example": "贄", + "reading": "にえ", + "meaning": "offering (to the gods, emperor, etc.), gift, sacrifice" + }, + { + "example": "早贄", + "reading": "はやにえ", + "meaning": "butcher-bird prey impaled on twigs, thorns, etc. for later consumption, first offering of the season" + }, + { + "example": "百舌の早贄", + "reading": "もずのはやにえ", + "meaning": "butcher-bird prey impaled on twigs, thorns, etc. for later consumption" + } + ], + "radical": { + "symbol": "貝", + "meaning": "shell" + }, + "parts": [ + "ハ", + "丶", + "九", + "亠", + "十", + "目", + "立", + "貝", + "辛" + ], + "strokeOrderDiagramUri": "http://classic.jisho.org/static/images/stroke_diagrams/36100_frames.png", + "strokeOrderSvgUri": "http://d1w6u4xc3l95km.cloudfront.net/kanji-2015-03/08d04.svg", + "strokeOrderGifUri": "https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/8d04.gif", + "uri": "http://jisho.org/search/%E8%B4%84%23kanji" + } +} \ No newline at end of file diff --git a/test/kanji_test_cases/5.json b/test/kanji_test_cases/5.json new file mode 100644 index 0000000..d393d0a --- /dev/null +++ b/test/kanji_test_cases/5.json @@ -0,0 +1,7 @@ +{ + "query": "ネガティブ", + "expectedResult": { + "query": "ネガティブ", + "found": false + } +} \ No newline at end of file diff --git a/test/kanji_test_cases/6.json b/test/kanji_test_cases/6.json new file mode 100644 index 0000000..ae8f5b4 --- /dev/null +++ b/test/kanji_test_cases/6.json @@ -0,0 +1,7 @@ +{ + "query": "wegmwrlgkrgmg", + "expectedResult": { + "query": "wegmwrlgkrgmg", + "found": false + } +} \ No newline at end of file diff --git a/test/kanji_test_cases/7.json b/test/kanji_test_cases/7.json new file mode 100644 index 0000000..3bc2ead --- /dev/null +++ b/test/kanji_test_cases/7.json @@ -0,0 +1,78 @@ +{ + "query": "水", + "expectedResult": { + "query": "水", + "found": true, + "taughtIn": "grade 1", + "jlptLevel": "N5", + "newspaperFrequencyRank": "223", + "strokeCount": 4, + "meaning": "water", + "kunyomi": [ + "みず", + "みず-" + ], + "onyomi": [ + "スイ" + ], + "onyomiExamples": [ + { + "example": "水", + "reading": "スイ", + "meaning": "Wednesday, shaved ice (served with flavored syrup), water (fifth of the five elements)" + }, + { + "example": "水位", + "reading": "スイイ", + "meaning": "water level" + }, + { + "example": "用水", + "reading": "ヨウスイ", + "meaning": "irrigation water, water for fire, city water, cistern water" + }, + { + "example": "浄水", + "reading": "ジョウスイ", + "meaning": "clean water" + } + ], + "kunyomiExamples": [ + { + "example": "水", + "reading": "みず", + "meaning": "water (esp. cool, fresh water, e.g. drinking water), fluid (esp. in an animal tissue), liquid, flood, floodwaters, water offered to wrestlers just prior to a bout, break granted to wrestlers engaged in a prolonged bout" + }, + { + "example": "水揚げ", + "reading": "みずあげ", + "meaning": "landing, unloading (e.g. a ship), catch (of fish), takings, sales (of a shop), defloration (e.g. of a geisha), preservation (of cut flowers, in ikebana)" + }, + { + "example": "飲み水", + "reading": "のみみず", + "meaning": "drinking water, potable water" + }, + { + "example": "呼び水", + "reading": "よびみず", + "meaning": "pump-priming, rousing, stimulation" + } + ], + "radical": { + "symbol": "水", + "forms": [ + "氵", + "氺" + ], + "meaning": "water" + }, + "parts": [ + "水" + ], + "strokeOrderDiagramUri": "http://classic.jisho.org/static/images/stroke_diagrams/27700_frames.png", + "strokeOrderSvgUri": "http://d1w6u4xc3l95km.cloudfront.net/kanji-2015-03/06c34.svg", + "strokeOrderGifUri": "https://raw.githubusercontent.com/mistval/kanji_images/master/gifs/6c34.gif", + "uri": "http://jisho.org/search/%E6%B0%B4%23kanji" + } +} \ No newline at end of file diff --git a/test/phrase_scrape_test_cases/0.json b/test/phrase_scrape_test_cases/0.json new file mode 100644 index 0000000..0fc210c --- /dev/null +++ b/test/phrase_scrape_test_cases/0.json @@ -0,0 +1,100 @@ +{ + "query": "車", + "expectedResult": { + "found": true, + "query": "車", + "uri": "https://jisho.org/word/%E8%BB%8A", + "tags": [ + "Common word", + "JLPT N5", + "Wanikani level 4" + ], + "meanings": [ + { + "seeAlsoTerms": [], + "sentences": [ + { + "english": "You cannot be too careful when you drive a car.", + "japanese": "車を運転する時はいくら注意してもしすぎることはない。", + "pieces": [ + { + "lifted": "くるま", + "unlifted": "車" + }, + { + "lifted": "", + "unlifted": "を" + }, + { + "lifted": "うんてん", + "unlifted": "運転" + }, + { + "lifted": "", + "unlifted": "する" + }, + { + "lifted": "とき", + "unlifted": "時" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "いくら" + }, + { + "lifted": "ちゅうい", + "unlifted": "注意" + }, + { + "lifted": "", + "unlifted": "して" + }, + { + "lifted": "", + "unlifted": "も" + }, + { + "lifted": "", + "unlifted": "しすぎる" + }, + { + "lifted": "", + "unlifted": "こと" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "ない" + } + ] + } + ], + "definition": "car; automobile; vehicle", + "supplemental": [], + "definitionAbstract": "", + "tags": [ + "noun" + ] + }, + { + "seeAlsoTerms": [], + "sentences": [], + "definition": "wheel", + "supplemental": [], + "definitionAbstract": "", + "tags": [ + "noun" + ] + } + ], + "otherForms": [], + "notes": [] + } +} \ No newline at end of file diff --git a/test/phrase_scrape_test_cases/1.json b/test/phrase_scrape_test_cases/1.json new file mode 100644 index 0000000..f67f673 --- /dev/null +++ b/test/phrase_scrape_test_cases/1.json @@ -0,0 +1,40 @@ +{ + "query": "日本人", + "expectedResult": { + "found": true, + "query": "日本人", + "uri": "https://jisho.org/word/%E6%97%A5%E6%9C%AC%E4%BA%BA", + "tags": [ + "Common word" + ], + "meanings": [ + { + "seeAlsoTerms": [], + "sentences": [], + "definition": "Japanese person; Japanese people", + "supplemental": [], + "definitionAbstract": "", + "tags": [ + "noun" + ] + }, + { + "seeAlsoTerms": [], + "sentences": [], + "definition": "Japanese people", + "supplemental": [], + "definitionAbstract": "The Japanese people are a nationality originating in the Japanese archipelago and are the predominant ethnic group of Japan. Worldwide, approximately 130 million people are of Japanese descent; of these, approximately 127 million are residents of Japan. People of Japanese ancestry who live in other countries are referred to as nikkeijin . The term ethnic Japanese may also be used in some contexts to refer to a locus of ethnic groups including the Yamato, Ainu and Ryukyuan people.", + "tags": [ + "wikipedia definition" + ] + } + ], + "otherForms": [ + { + "kanji": "日本人", + "kana": "にっぽんじん" + } + ], + "notes": [] + } +} \ No newline at end of file diff --git a/test/phrase_scrape_test_cases/2.json b/test/phrase_scrape_test_cases/2.json new file mode 100644 index 0000000..f5d463b --- /dev/null +++ b/test/phrase_scrape_test_cases/2.json @@ -0,0 +1,135 @@ +{ + "query": "皆", + "expectedResult": { + "found": true, + "query": "皆", + "uri": "https://jisho.org/word/%E7%9A%86", + "tags": [ + "Common word", + "JLPT N5" + ], + "meanings": [ + { + "seeAlsoTerms": [], + "sentences": [ + { + "english": "The people which were here have all gone.", + "japanese": "ここにいた人々はみんな行ってしまった。", + "pieces": [ + { + "lifted": "", + "unlifted": "ここ" + }, + { + "lifted": "", + "unlifted": "に" + }, + { + "lifted": "", + "unlifted": "いた" + }, + { + "lifted": "ひとびと", + "unlifted": "人々" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "い", + "unlifted": "行って" + }, + { + "lifted": "", + "unlifted": "しまった" + } + ] + } + ], + "definition": "all; everyone; everybody", + "supplemental": [ + "Usually written using kana alone" + ], + "definitionAbstract": "", + "tags": [ + "adverb", + "noun" + ] + }, + { + "seeAlsoTerms": [], + "sentences": [ + { + "english": "All the dinner had been eaten before he came.", + "japanese": "ごちそうはみんな彼が来ないうちに食べられてしまった。", + "pieces": [ + { + "lifted": "", + "unlifted": "ごちそう" + }, + { + "lifted": "", + "unlifted": "は" + }, + { + "lifted": "", + "unlifted": "みんな" + }, + { + "lifted": "かれ", + "unlifted": "彼" + }, + { + "lifted": "", + "unlifted": "が" + }, + { + "lifted": "らい", + "unlifted": "来" + }, + { + "lifted": "", + "unlifted": "ないうちに" + }, + { + "lifted": "た", + "unlifted": "食べられて" + }, + { + "lifted": "", + "unlifted": "しまった" + } + ] + } + ], + "definition": "everything", + "supplemental": [ + "Usually written using kana alone" + ], + "definitionAbstract": "", + "tags": [ + "adverb", + "noun" + ] + } + ], + "otherForms": [ + { + "kanji": "皆んな", + "kana": "みんな" + }, + { + "kanji": "皆", + "kana": "みな" + } + ], + "notes": [ + "皆んな: Irregular okurigana usage." + ] + } +} \ No newline at end of file diff --git a/test/phrase_scrape_test_cases/3.json b/test/phrase_scrape_test_cases/3.json new file mode 100644 index 0000000..c66f9ae --- /dev/null +++ b/test/phrase_scrape_test_cases/3.json @@ -0,0 +1,69 @@ +{ + "query": "ネガティブ", + "expectedResult": { + "found": true, + "query": "ネガティブ", + "uri": "https://jisho.org/word/%E3%83%8D%E3%82%AC%E3%83%86%E3%82%A3%E3%83%96", + "tags": [ + "Common word" + ], + "meanings": [ + { + "seeAlsoTerms": [], + "sentences": [], + "definition": "negative (e.g. thinking)", + "supplemental": [ + "Antonym: ポジティブ" + ], + "definitionAbstract": "", + "tags": [ + "na-adjective" + ] + }, + { + "seeAlsoTerms": [], + "sentences": [], + "definition": "negative (photography)", + "supplemental": [], + "definitionAbstract": "", + "tags": [ + "noun" + ] + }, + { + "seeAlsoTerms": [ + "陰極" + ], + "sentences": [], + "definition": "negative (electrical polarity)", + "supplemental": [], + "definitionAbstract": "", + "tags": [ + "noun" + ] + }, + { + "seeAlsoTerms": [], + "sentences": [], + "definition": "Negative (Finnish band)", + "supplemental": [], + "definitionAbstract": "Negative is a Finnish glam rock band founded at the end of 1997. Members of Negative cite musical influence such as Guns N' Roses, Queen, and Hanoi Rocks. The band itself labels the music as ”emotional rock’n roll”.", + "tags": [ + "wikipedia definition" + ] + } + ], + "otherForms": [ + { + "kanji": "ネガティヴ" + }, + { + "kanji": "ネガチブ" + }, + { + "kanji": "ネガチィブ" + } + ], + "notes": [] + } +} \ No newline at end of file diff --git a/test/phrase_scrape_test_cases/4.json b/test/phrase_scrape_test_cases/4.json new file mode 100644 index 0000000..5139c41 --- /dev/null +++ b/test/phrase_scrape_test_cases/4.json @@ -0,0 +1,7 @@ +{ + "query": "grlgmregmneriireg", + "expectedResult": { + "query": "grlgmregmneriireg", + "found": false + } +} \ No newline at end of file diff --git a/test/unofficial_jisho_api_test.dart b/test/unofficial_jisho_api_test.dart new file mode 100644 index 0000000..9f76635 --- /dev/null +++ b/test/unofficial_jisho_api_test.dart @@ -0,0 +1,60 @@ +import 'dart:io' as io; +import 'package:path/path.dart' as path; +import 'dart:convert'; + +import 'package:unofficial_jisho_api/unofficial_jisho_api.dart'; +import 'package:test/test.dart'; + +final jisho = API(); + +List getFilePaths(String dirname) { + final currentdir = io.Directory.current.path; + final filenames = io.Directory(path.join(currentdir, 'test', dirname)).listSync(); + return filenames.map((filename) => path.join(currentdir, 'test', dirname, filename.path)).toList(); +} + +void runTestCases(testCaseFiles, apiFunction) async { + for (var testCount = 0; testCount < testCaseFiles.length; testCount++) { + final file = await io.File(testCaseFiles[testCount]).readAsString(); + final testCase = jsonDecode(file); + test('Test ${testCount}', () async { + switch(apiFunction) { + case 'searchForKanji': { + final result = await jisho.searchForKanji(testCase.query); + expect(result, testCase.expectedResult); + break; + } + case 'searchForExamples': { + final result = await jisho.searchForExamples(testCase.query); + expect(result, testCase.expectedResult); + break; + } + case 'scrapeForPhrase': { + final result = await jisho.scrapeForPhrase(testCase.query); + expect(result, testCase.expectedResult); + break; + } + throw 'No API function provided'; + } + }); + } +} + +void main() { + + group('Kanji test cases', () { + final filePaths = getFilePaths('kanji_test_cases'); + runTestCases(filePaths, 'searchForKanji'); + }); + + group('Example test cases', () { + final filePaths = getFilePaths('example_test_cases'); + runTestCases(filePaths, 'searchForExamples'); + }); + + group('Phrase scrape test cases', () { + final filePaths = getFilePaths('phrase_scrape_test_cases'); + runTestCases(filePaths, 'scrapeForPhrase'); + }); + +}