lib/search/kanji: add more data to result
This commit is contained in:
@@ -47,6 +47,23 @@ class KanjiSearchResult extends Equatable {
|
||||
/// (e.g. JIS213, JIS208, UCS, etc.)
|
||||
final Map<String, String> codepoints;
|
||||
|
||||
/// The kanji's nanori readings.
|
||||
///
|
||||
/// Nanori readings are special readings of kanji used in names.
|
||||
final List<String> nanori;
|
||||
|
||||
/// How to read this kanji in different languages.
|
||||
final Map<String, List<String>> alternativeLanguageReadings;
|
||||
|
||||
/// Common miscounts of the kanji's strokes.
|
||||
final List<int> strokeMiscounts;
|
||||
|
||||
/// Query codes for looking up this kanji in different indexing systems.
|
||||
final Map<String, List<String>> queryCodes;
|
||||
|
||||
/// References to other dictionaries that contain this kanji.
|
||||
final Map<String, String> dictionaryReferences;
|
||||
|
||||
const KanjiSearchResult({
|
||||
required this.kanji,
|
||||
required this.taughtIn,
|
||||
@@ -61,6 +78,11 @@ class KanjiSearchResult extends Equatable {
|
||||
required this.radical,
|
||||
required this.parts,
|
||||
required this.codepoints,
|
||||
required this.nanori,
|
||||
required this.alternativeLanguageReadings,
|
||||
required this.strokeMiscounts,
|
||||
required this.queryCodes,
|
||||
required this.dictionaryReferences,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -77,6 +99,13 @@ class KanjiSearchResult extends Equatable {
|
||||
// onyomiExamples,
|
||||
radical,
|
||||
parts,
|
||||
codepoints,
|
||||
kanji,
|
||||
nanori,
|
||||
alternativeLanguageReadings,
|
||||
strokeMiscounts,
|
||||
queryCodes,
|
||||
dictionaryReferences,
|
||||
];
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
@@ -97,6 +126,11 @@ class KanjiSearchResult extends Equatable {
|
||||
// 'strokeOrderGifUri': strokeOrderGifUri,
|
||||
// 'uri': uri,
|
||||
'codepoints': codepoints,
|
||||
'nanori': nanori,
|
||||
'alternativeLanguageReadings': alternativeLanguageReadings,
|
||||
'strokeMiscounts': strokeMiscounts,
|
||||
'queryCodes': queryCodes,
|
||||
'dictionaryReferences': dictionaryReferences,
|
||||
};
|
||||
|
||||
factory KanjiSearchResult.fromJson(Map<String, dynamic> json) {
|
||||
@@ -122,6 +156,26 @@ class KanjiSearchResult extends Equatable {
|
||||
codepoints: (json['codepoints'] as Map<String, dynamic>).map(
|
||||
(key, value) => MapEntry(key, value as String),
|
||||
),
|
||||
nanori: (json['nanori'] as List).map((e) => e as String).toList(),
|
||||
alternativeLanguageReadings:
|
||||
(json['alternativeLanguageReadings'] as Map<String, dynamic>).map(
|
||||
(key, value) => MapEntry(
|
||||
key,
|
||||
(value as List).map((e) => e as String).toList(),
|
||||
),
|
||||
),
|
||||
strokeMiscounts:
|
||||
(json['strokeMiscounts'] as List).map((e) => e as int).toList(),
|
||||
queryCodes: (json['queryCodes'] as Map<String, dynamic>).map(
|
||||
(key, value) => MapEntry(
|
||||
key,
|
||||
(value as List).map((e) => e as String).toList(),
|
||||
),
|
||||
),
|
||||
dictionaryReferences:
|
||||
(json['dictionaryReferences'] as Map<String, dynamic>).map(
|
||||
(key, value) => MapEntry(key, value as String),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:jadb/models/kanji_search/kanji_search_radical.dart';
|
||||
import 'package:jadb/models/kanji_search/kanji_search_result.dart';
|
||||
import 'package:sqflite_common/sqflite.dart';
|
||||
@@ -101,12 +102,13 @@ Future<KanjiSearchResult?> searchKanjiWithDbConnection(
|
||||
whereArgs: [kanji],
|
||||
);
|
||||
|
||||
late final List<Map<String, Object?>> variants;
|
||||
final variants_query = connection.query(
|
||||
"KANJIDIC_Variant",
|
||||
where: "KANJIDIC_Variant.kanji = ?",
|
||||
whereArgs: [kanji],
|
||||
);
|
||||
// TODO: add variant data to result
|
||||
// late final List<Map<String, Object?>> variants;
|
||||
// final variants_query = connection.query(
|
||||
// "KANJIDIC_Variant",
|
||||
// where: "KANJIDIC_Variant.kanji = ?",
|
||||
// whereArgs: [kanji],
|
||||
// );
|
||||
|
||||
// TODO: Search for kunyomi and onyomi usage of the characters
|
||||
// from JMDict. We'll need to fuzzy aquery JMDict_KanjiElement for mathces,
|
||||
@@ -131,7 +133,7 @@ Future<KanjiSearchResult?> searchKanjiWithDbConnection(
|
||||
parts_query.then((value) => parts = value),
|
||||
readings_query.then((value) => readings = value),
|
||||
stroke_miscounts_query.then((value) => stroke_miscounts = value),
|
||||
variants_query.then((value) => variants = value),
|
||||
// variants_query.then((value) => variants = value),
|
||||
});
|
||||
|
||||
final entry = characters.first;
|
||||
@@ -148,6 +150,35 @@ Future<KanjiSearchResult?> searchKanjiWithDbConnection(
|
||||
)
|
||||
: null;
|
||||
|
||||
final alternativeLanguageReadings = readings
|
||||
.groupListsBy(
|
||||
(item) => item['type'] as String,
|
||||
)
|
||||
.map(
|
||||
(key, value) => MapEntry(
|
||||
key,
|
||||
value.map((item) => item['reading'] as String).toList(),
|
||||
),
|
||||
);
|
||||
|
||||
// TODO: Add `SKIPMisclassification` to the entries
|
||||
final queryCodes = query_codes
|
||||
.groupListsBy(
|
||||
(item) => item['type'] as String,
|
||||
)
|
||||
.map(
|
||||
(key, value) => MapEntry(
|
||||
key,
|
||||
value.map((item) => item['code'] as String).toList(),
|
||||
),
|
||||
);
|
||||
|
||||
// TODO: Add `volume` and `page` to the entries
|
||||
final dictionaryReferences = {
|
||||
for (final entry in dictionary_references)
|
||||
entry['type'] as String: entry['ref'] as String,
|
||||
};
|
||||
|
||||
final String? grade = {
|
||||
1: 'grade 1',
|
||||
2: 'grade 2',
|
||||
@@ -184,5 +215,11 @@ Future<KanjiSearchResult?> searchKanjiWithDbConnection(
|
||||
for (final codepoint in codepoints)
|
||||
codepoint['type'] as String: codepoint['codepoint'] as String,
|
||||
},
|
||||
nanori: nanoris.map((item) => item['nanori'] as String).toList(),
|
||||
alternativeLanguageReadings: alternativeLanguageReadings,
|
||||
strokeMiscounts:
|
||||
stroke_miscounts.map((item) => item['strokeCount'] as int).toList(),
|
||||
queryCodes: queryCodes,
|
||||
dictionaryReferences: dictionaryReferences,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user