1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-21 13:37:29 +01:00

Add storage entities

This commit is contained in:
Oystein Kristoffer Tveit 2021-12-01 23:10:07 +01:00
parent 8811cef864
commit a0c608ccca
5 changed files with 353 additions and 63 deletions

View File

@ -0,0 +1,13 @@
import 'package:objectbox/objectbox.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho;
@Entity()
class ExampleSentencePiece {
int id = 0;
String? lifted;
String unlifted;
ExampleSentencePiece.fromJishoObject(jisho.ExampleSentencePiece object) :
lifted = object.lifted,
unlifted = object.unlifted;
}

View File

@ -0,0 +1,36 @@
import 'package:objectbox/objectbox.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho;
import 'common.dart';
@Entity()
class ExampleResultData {
String kanji;
String kana;
String english;
List<ExampleSentencePiece> pieces;
ExampleResultData.fromJishoObject(jisho.ExampleResultData object)
: kanji = object.kanji,
kana = object.kana,
english = object.english,
pieces = object.pieces
.map((p) => ExampleSentencePiece.fromJishoObject(p))
.toList();
}
@Entity()
class ExampleResults {
String query;
bool found;
String uri;
List<ExampleResultData> results;
ExampleResults.fromJishoObject(jisho.ExampleResults object)
: query = object.query,
found = object.found,
uri = object.uri,
results = object.results
.map((r) => ExampleResultData.fromJishoObject(r))
.toList();
}

View File

@ -0,0 +1,86 @@
import 'package:objectbox/objectbox.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho;
@Entity()
class YomiExample {
int id = 0;
String example;
String reading;
String meaning;
YomiExample.fromJishoObject(jisho.YomiExample object)
: example = object.example,
reading = object.reading,
meaning = object.meaning;
}
@Entity()
class Radical {
int id = 0;
String symbol;
List<String> forms;
String meaning;
Radical.fromJishoObject(jisho.Radical object)
: symbol = object.symbol,
forms = object.forms,
meaning = object.meaning;
}
@Entity()
class KanjiResult {
int id = 0;
String query;
bool found;
KanjiResultData? data;
KanjiResult.fromJishoObject(jisho.KanjiResult object)
: query = object.query,
found = object.found,
data = (object.data == null)
? null
: KanjiResultData.fromJishoObject(object.data!);
}
@Entity()
class KanjiResultData {
int id = 0;
String? taughtIn;
String? jlptLevel;
int? newspaperFrequencyRank;
int strokeCount;
String meaning;
List<String> kunyomi;
List<String> onyomi;
List<YomiExample> kunyomiExamples;
List<YomiExample> onyomiExamples;
Radical? radical;
List<String> parts;
String strokeOrderDiagramUri;
String strokeOrderSvgUri;
String strokeOrderGifUri;
String uri;
KanjiResultData.fromJishoObject(jisho.KanjiResultData object)
: taughtIn = object.taughtIn,
jlptLevel = object.jlptLevel,
newspaperFrequencyRank = object.newspaperFrequencyRank,
strokeCount = object.strokeCount,
meaning = object.meaning,
kunyomi = object.kunyomi,
onyomi = object.onyomi,
kunyomiExamples = object.kunyomiExamples
.map((k) => YomiExample.fromJishoObject(k))
.toList(),
onyomiExamples = object.onyomiExamples
.map((o) => YomiExample.fromJishoObject(o))
.toList(),
radical = (object.radical == null)
? null
: Radical.fromJishoObject(object.radical!),
parts = object.parts,
strokeOrderDiagramUri = object.strokeOrderDiagramUri,
strokeOrderSvgUri = object.strokeOrderSvgUri,
strokeOrderGifUri = object.strokeOrderGifUri,
uri = object.uri;
}

View File

@ -0,0 +1,101 @@
import 'package:objectbox/objectbox.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho;
import 'common.dart';
@Entity()
class PhraseScrapeSentence {
int id = 0;
String english;
String japanese;
List<ExampleSentencePiece> pieces;
PhraseScrapeSentence.fromJishoObject(jisho.PhraseScrapeSentence object)
: english = object.english,
japanese = object.japanese,
pieces = object.pieces
.map((p) => ExampleSentencePiece.fromJishoObject(p))
.toList();
}
@Entity()
class PhraseScrapeMeaning {
int id = 0;
List<String> seeAlsoTerms;
List<PhraseScrapeSentence> sentences;
String definition;
List<String> supplemental;
String? definitionAbstract;
List<String> tags;
PhraseScrapeMeaning.fromJishoObject(jisho.PhraseScrapeMeaning object)
: seeAlsoTerms = object.seeAlsoTerms,
sentences = object.sentences
.map((s) => PhraseScrapeSentence.fromJishoObject(s))
.toList(),
definition = object.definition,
supplemental = object.supplemental,
definitionAbstract = object.definitionAbstract,
tags = object.tags;
}
@Entity()
class KanjiKanaPair {
int id = 0;
String kanji;
String? kana;
KanjiKanaPair.fromJishoObject(jisho.KanjiKanaPair object)
: kanji = object.kanji,
kana = object.kana;
}
@Entity()
class PhrasePageScrapeResult {
int id = 0;
bool found;
String query;
PhrasePageScrapeResultData? data;
PhrasePageScrapeResult.fromJishoObject(jisho.PhrasePageScrapeResult object)
: found = object.found,
query = object.query,
data = (object.data == null)
? null
: PhrasePageScrapeResultData.fromJishoObject(object.data!);
}
@Entity()
class AudioFile {
int id = 0;
String uri;
String mimetype;
AudioFile.fromJishoObject(jisho.AudioFile object)
: uri = object.uri,
mimetype = object.mimetype;
}
@Entity()
class PhrasePageScrapeResultData {
int id = 0;
String uri;
List<String> tags;
List<PhraseScrapeMeaning> meanings;
List<KanjiKanaPair> otherForms;
List<AudioFile> audio;
List<String> notes;
PhrasePageScrapeResultData.fromJishoObject(
jisho.PhrasePageScrapeResultData object,
) : uri = object.uri,
tags = object.tags,
meanings = object.meanings
.map((m) => PhraseScrapeMeaning.fromJishoObject(m))
.toList(),
otherForms = object.otherForms
.map((f) => KanjiKanaPair.fromJishoObject(f))
.toList(),
audio = object.audio.map((a) => AudioFile.fromJishoObject(a)).toList(),
notes = object.notes;
}

View File

@ -1,72 +1,126 @@
// import 'package:objectbox/objectbox.dart';
// import 'package:unofficial_jisho_api/api.dart' as jisho;
import 'package:objectbox/objectbox.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho;
// @Entity()
// class SearchResult {
// int id = 0;
// final meta = ToOne<JishoResultMeta>();
// final data = ToMany<JishoResult>();
@Entity()
class SearchResult {
int id = 0;
final JishoResultMeta meta;
final ToMany<JishoResult> data = ToMany<JishoResult>();
// // SearchResult(JishoAPIResult result) {
// // this.data = result.data;
// // this.meta = result.meta;
// // }
SearchResult.fromJishoObject(final jisho.JishoAPIResult object)
: meta = JishoResultMeta.fromJishoObject(object.meta) {
data.addAll(
object.data
?.map((r) => JishoResult.fromJishoObject(r)) ??
<JishoResult>[],
);
}
}
// // JishoAPIResult toJishoAPIResult() {
// // return JishoAPIResult(meta: this.meta, data: this.data);
// // }
// }
@Entity()
class JishoResultMeta {
int id = 0;
int status;
// @Entity()
// class JishoResultMeta {
// int id = 0;
// int status;
// }
JishoResultMeta.fromJishoObject(final jisho.JishoResultMeta object)
: status = object.status;
}
// @Entity()
// class JishoResult {
// int id = 0;
// final attribution = ToOne<JishoAttribution>();
// bool is_common;
// final japanese = ToMany<JishoJapaneseWord>();
// List<String> jlpt;
// final senses = ToMany<JishoWordSense>();
// String slug;
// List<String> tags;
// }
@Entity()
class JishoResult {
int id = 0;
JishoAttribution attribution;
bool? is_common;
List<JishoJapaneseWord> japanese;
List<String> jlpt;
List<JishoWordSense> senses;
String slug;
List<String> tags;
// @Entity()
// class JishoAttribution {
// int id = 0;
// String dbpedia;
// String jmdict;
// bool jmnedict;
// }
JishoResult.fromJishoObject(final jisho.JishoResult object)
: attribution = JishoAttribution.fromJishoObject(object.attribution),
is_common = object.isCommon,
japanese = object.japanese
.map((j) => JishoJapaneseWord.fromJishoObject(j))
.toList(),
jlpt = object.jlpt,
senses = object.senses
.map((s) => JishoWordSense.fromJishoObject(s))
.toList(),
slug = object.slug,
tags = object.tags;
}
// @Entity()
// class JishoJapaneseWord {
// int id = 0;
// String reading;
// String word;
// }
@Entity()
class JishoAttribution {
int id = 0;
String? dbpedia;
bool jmdict;
bool jmnedict;
// @Entity()
// class JishoWordSense {
// int id = 0;
// List<String> antonyms;
// List<String> english_definitions;
// List<String> info;
// final links = ToMany<JishoSenseLink>();
// List<String> parts_of_speech;
// List<String> restrictions;
// List<String> see_also;
// List<dynamic> source;
// List<String> tags;
// }
JishoAttribution.fromJishoObject(final jisho.JishoAttribution object)
: dbpedia = object.dbpedia,
jmdict = object.jmdict,
jmnedict = object.jmnedict;
}
// @Entity()
// class JishoSenseLink {
// int id = 0;
// String text;
// String url;
// }
@Entity()
class JishoJapaneseWord {
int id = 0;
String? reading;
String? word;
JishoJapaneseWord.fromJishoObject(final jisho.JishoJapaneseWord object)
: reading = object.reading,
word = object.word;
}
@Entity()
class JishoWordSense {
int id = 0;
List<String> antonyms;
List<String> english_definitions;
List<String> info;
List<JishoSenseLink> links;
List<String> parts_of_speech;
List<String> restrictions;
List<String> see_also;
List<JishoWordSource> source;
List<String> tags;
JishoWordSense.fromJishoObject(final jisho.JishoWordSense object)
: antonyms = object.antonyms,
english_definitions = object.englishDefinitions,
info = object.info,
links =
object.links.map((l) => JishoSenseLink.fromJishoObject(l)).toList(),
parts_of_speech = object.partsOfSpeech,
restrictions = object.restrictions,
see_also = object.seeAlso,
source = object.source
.map((s) => JishoWordSource.fromJishoObject(s))
.toList(),
tags = object.tags;
}
@Entity()
class JishoWordSource {
int id = 0;
String language;
String? word;
JishoWordSource.fromJishoObject(final jisho.JishoWordSource object)
: language = object.language,
word = object.word;
}
@Entity()
class JishoSenseLink {
int id = 0;
String text;
String url;
JishoSenseLink.fromJishoObject(final jisho.JishoSenseLink object)
: text = object.text,
url = object.url;
}