228 lines
4.8 KiB
Dart
228 lines
4.8 KiB
Dart
import 'package:jadb/_data_ingestion/sql_writable.dart';
|
|
|
|
abstract class Element extends SQLWritable {
|
|
final String reading;
|
|
final int? news;
|
|
final int? ichi;
|
|
final int? spec;
|
|
final int? gai;
|
|
final int? nf;
|
|
const Element({
|
|
required this.reading,
|
|
this.news,
|
|
this.ichi,
|
|
this.spec,
|
|
this.gai,
|
|
this.nf,
|
|
});
|
|
|
|
Map<String, Object?> get sqlValue => {
|
|
'reading': reading,
|
|
'news': news,
|
|
'ichi': ichi,
|
|
'spec': spec,
|
|
'gai': gai,
|
|
'nf': nf,
|
|
};
|
|
}
|
|
|
|
class KanjiElement extends Element {
|
|
int orderNum;
|
|
List<String> info;
|
|
|
|
KanjiElement({
|
|
this.info = const [],
|
|
required this.orderNum,
|
|
required String reading,
|
|
int? news,
|
|
int? ichi,
|
|
int? spec,
|
|
int? gai,
|
|
int? nf,
|
|
}) : super(
|
|
reading: reading,
|
|
news: news,
|
|
ichi: ichi,
|
|
spec: spec,
|
|
gai: gai,
|
|
nf: nf,
|
|
);
|
|
|
|
@override
|
|
Map<String, Object?> get sqlValue => {
|
|
...super.sqlValue,
|
|
'orderNum': orderNum,
|
|
};
|
|
}
|
|
|
|
class ReadingElement extends Element {
|
|
int orderNum;
|
|
bool readingDoesNotMatchKanji;
|
|
List<String> info;
|
|
List<String> restrictions;
|
|
|
|
ReadingElement({
|
|
required this.orderNum,
|
|
required this.readingDoesNotMatchKanji,
|
|
this.info = const [],
|
|
this.restrictions = const [],
|
|
required String reading,
|
|
int? news,
|
|
int? ichi,
|
|
int? spec,
|
|
int? gai,
|
|
int? nf,
|
|
}) : super(
|
|
reading: reading,
|
|
news: news,
|
|
ichi: ichi,
|
|
spec: spec,
|
|
gai: gai,
|
|
nf: nf,
|
|
);
|
|
|
|
@override
|
|
Map<String, Object?> get sqlValue => {
|
|
...super.sqlValue,
|
|
'orderNum': orderNum,
|
|
'readingDoesNotMatchKanji': readingDoesNotMatchKanji,
|
|
};
|
|
}
|
|
|
|
class LanguageSource extends SQLWritable {
|
|
final String language;
|
|
final String? phrase;
|
|
final bool fullyDescribesSense;
|
|
final bool constructedFromSmallerWords;
|
|
|
|
const LanguageSource({
|
|
required this.language,
|
|
this.phrase,
|
|
this.fullyDescribesSense = true,
|
|
this.constructedFromSmallerWords = false,
|
|
});
|
|
|
|
@override
|
|
Map<String, Object?> get sqlValue => {
|
|
'language': language,
|
|
'phrase': phrase,
|
|
'fullyDescribesSense': fullyDescribesSense,
|
|
'constructedFromSmallerWords': constructedFromSmallerWords,
|
|
};
|
|
}
|
|
|
|
class Glossary extends SQLWritable {
|
|
final String language;
|
|
final String phrase;
|
|
final String? type;
|
|
|
|
const Glossary({
|
|
required this.language,
|
|
required this.phrase,
|
|
this.type,
|
|
});
|
|
|
|
Map<String, Object?> get sqlValue => {
|
|
'language': language,
|
|
'phrase': phrase,
|
|
'type': type,
|
|
};
|
|
}
|
|
|
|
final kanaRegex =
|
|
RegExp(r'^[\p{Script=Katakana}\p{Script=Hiragana}ー]+$', unicode: true);
|
|
|
|
class XRefParts {
|
|
final String? kanjiRef;
|
|
final String? readingRef;
|
|
final int? senseOrderNum;
|
|
|
|
const XRefParts({
|
|
this.kanjiRef,
|
|
this.readingRef,
|
|
this.senseOrderNum,
|
|
}) : assert(kanjiRef != null || readingRef != null);
|
|
|
|
Map<String, Object?> toJson() => {
|
|
'kanjiRef': kanjiRef,
|
|
'readingRef': readingRef,
|
|
'senseOrderNum': senseOrderNum,
|
|
};
|
|
}
|
|
|
|
class XRef {
|
|
final String entryId;
|
|
final String reading;
|
|
|
|
const XRef({
|
|
required this.entryId,
|
|
required this.reading,
|
|
});
|
|
}
|
|
|
|
class Sense extends SQLWritable {
|
|
final int id;
|
|
final int orderNum;
|
|
final List<XRefParts> antonyms;
|
|
final List<String> dialects;
|
|
final List<String> fields;
|
|
final List<String> info;
|
|
final List<LanguageSource> languageSource;
|
|
final List<Glossary> glossary;
|
|
final List<String> misc;
|
|
final List<String> pos;
|
|
final List<String> restrictedToKanji;
|
|
final List<String> restrictedToReading;
|
|
final List<XRefParts> seeAlso;
|
|
|
|
const Sense({
|
|
required this.id,
|
|
required this.orderNum,
|
|
this.antonyms = const [],
|
|
this.dialects = const [],
|
|
this.fields = const [],
|
|
this.info = const [],
|
|
this.languageSource = const [],
|
|
this.glossary = const [],
|
|
this.misc = const [],
|
|
this.pos = const [],
|
|
this.restrictedToKanji = const [],
|
|
this.restrictedToReading = const [],
|
|
this.seeAlso = const [],
|
|
});
|
|
|
|
@override
|
|
Map<String, Object?> get sqlValue => {
|
|
'id': id,
|
|
'orderNum': orderNum,
|
|
};
|
|
|
|
bool get isEmpty => antonyms.isEmpty &&
|
|
dialects.isEmpty &&
|
|
fields.isEmpty &&
|
|
info.isEmpty &&
|
|
languageSource.isEmpty &&
|
|
glossary.isEmpty &&
|
|
misc.isEmpty &&
|
|
pos.isEmpty &&
|
|
restrictedToKanji.isEmpty &&
|
|
restrictedToReading.isEmpty &&
|
|
seeAlso.isEmpty;
|
|
}
|
|
|
|
class Entry extends SQLWritable {
|
|
final int id;
|
|
final List<KanjiElement> kanji;
|
|
final List<ReadingElement> readings;
|
|
final List<Sense> senses;
|
|
|
|
const Entry({
|
|
required this.id,
|
|
required this.kanji,
|
|
required this.readings,
|
|
required this.senses,
|
|
});
|
|
|
|
Map<String, Object?> get sqlValue => {'id': id};
|
|
}
|