import '../common.dart'; import '../objects.dart'; class TableNames { static const String entry = 'JMdict_Entry'; static const String entryByKana = 'JMdict_EntryByKana'; static const String entryByEnglish = 'JMdict_EntryByEnglish'; static const String kanjiElement = 'JMdict_KanjiElement'; static const String kanjiInfo = 'JMdict_KanjiElementInfo'; static const String readingElement = 'JMdict_ReadingElement'; static const String readingInfo = 'JMdict_ReadingElementInfo'; static const String readingRestriction = 'JMdict_ReadingElementRestriction'; static const String sense = 'JMdict_Sense'; static const String senseAntonyms = 'JMdict_SenseAntonym'; static const String senseDialect = 'JMdict_SenseDialect'; static const String senseField = 'JMdict_SenseField'; static const String senseGlossary = 'JMdict_SenseGlossary'; static const String senseInfo = 'JMdict_SenseInfo'; static const String senseLanguageSource = 'JMdict_SenseLanguageSource'; static const String senseMisc = 'JMdict_SenseMisc'; static const String sensePOS = 'JMdict_SensePOS'; static const String senseRestrictedToKanji = 'JMdict_SenseRestrictedToKanji'; static const String senseRestrictedToReading = 'JMdict_SenseRestrictedToReading'; static const String senseSeeAlso = 'JMdict_SenseSeeAlso'; } 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 get sqlValue => { 'reading': reading, 'news': news, 'ichi': ichi, 'spec': spec, 'gai': gai, 'nf': nf, }; } class KanjiElement extends Element { List info; KanjiElement({ this.info = 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, ); } class ReadingElement extends Element { List info; List restrictions; ReadingElement({ 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, ); } 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 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 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? senseNum; const XRefParts({ this.kanjiRef, this.readingRef, this.senseNum, }) : assert(kanjiRef != null || readingRef != null); factory XRefParts.fromString(String s) { final parts = s.split('・'); if (parts.length == 1) { if (parts[0].contains(kanaRegex)) { return XRefParts(readingRef: parts[0]); } return XRefParts(kanjiRef: parts[0]); } else if (parts.length == 2) { if (int.tryParse(parts[1]) != null) { if (parts[0].contains(kanaRegex)) { return XRefParts(readingRef: parts[0], senseNum: int.parse(parts[1])); } return XRefParts(kanjiRef: parts[0], senseNum: int.parse(parts[1])); } return XRefParts(kanjiRef: parts[0], readingRef: parts[1]); } else if (parts.length == 3) { return XRefParts( kanjiRef: parts[0], readingRef: parts[1], senseNum: int.parse(parts[2]), ); } return XRefParts(); } } class XRef { final String entryId; final String reading; const XRef({ required this.entryId, required this.reading, }); } class Sense extends SQLWritable { final int id; final List antonyms; final List dialects; final List fields; final List info; final List languageSource; final List glossary; final List misc; final List pos; final List restrictedToKanji; final List restrictedToReading; final List seeAlso; const Sense({ required this.id, 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 get sqlValue => {}; } class Entry extends SQLWritable { final int id; final List kanji; final List readings; final List senses; const Entry({ required this.id, required this.kanji, required this.readings, required this.senses, }); Map get sqlValue => {'id': id}; }