Files
jadb/lib/_data_ingestion/jmdict/objects.dart

210 lines
4.5 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,
});
@override
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 super.reading,
super.news,
super.ichi,
super.spec,
super.gai,
super.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 super.reading,
super.news,
super.ichi,
super.spec,
super.gai,
super.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,
required 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});
@override
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 senseId;
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.senseId,
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 => {
'senseId': senseId,
'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 entryId;
final List<KanjiElement> kanji;
final List<ReadingElement> readings;
final List<Sense> senses;
const Entry({
required this.entryId,
required this.kanji,
required this.readings,
required this.senses,
});
@override
Map<String, Object?> get sqlValue => {'entryId': entryId};
}