Query more detailed information about langauge source

This commit is contained in:
2025-05-14 17:12:30 +02:00
parent 9038119eb7
commit 59e8db5add
3 changed files with 45 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ import 'package:jadb/models/jmdict/jmdict_dialect.dart';
import 'package:jadb/models/jmdict/jmdict_field.dart';
import 'package:jadb/models/jmdict/jmdict_misc.dart';
import 'package:jadb/models/jmdict/jmdict_pos.dart';
import 'package:jadb/models/word_search/word_search_sense_language_source.dart';
import 'package:jadb/models/word_search/word_search_xref_entry.dart';
class WordSearchSense {
@@ -38,7 +39,7 @@ class WordSearchSense {
// TODO: there is a lot more info to collect in the languageSource data
/// Information about the the origin of the word, if loaned from another language.
final List<String> languageSource;
final List<WordSearchSenseLanguageSource> languageSource;
// TODO: add example sentences
@@ -106,6 +107,8 @@ class WordSearchSense {
misc:
(json['misc'] as List).map((e) => JMdictMisc.fromJson(e)).toList(),
info: List<String>.from(json['info']),
languageSource: List<String>.from(json['languageSource']),
languageSource: (json['languageSource'] as List)
.map((e) => WordSearchSenseLanguageSource.fromJson(e))
.toList(),
);
}

View File

@@ -0,0 +1,30 @@
/// A reference to a foreign language where this sense originates from.
class WordSearchSenseLanguageSource {
final String language;
final String? phrase;
final bool fullyDescribesSense;
final bool constructedFromSmallerWords;
const WordSearchSenseLanguageSource({
required this.language,
this.phrase,
this.fullyDescribesSense = true,
this.constructedFromSmallerWords = false,
});
Map<String, Object?> toJson() => {
'language': language,
'phrase': phrase,
'fullyDescribesSense': fullyDescribesSense,
'constructedFromSmallerWords': constructedFromSmallerWords,
};
factory WordSearchSenseLanguageSource.fromJson(Map<String, dynamic> json) =>
WordSearchSenseLanguageSource(
language: json['language'],
phrase: json['phrase'],
fullyDescribesSense: json['fullyDescribesSense'] ?? true,
constructedFromSmallerWords:
json['constructedFromSmallerWords'] ?? false,
);
}

View File

@@ -8,6 +8,7 @@ import 'package:jadb/models/jmdict/jmdict_reading_info.dart';
import 'package:jadb/models/word_search/word_search_result.dart';
import 'package:jadb/models/word_search/word_search_ruby.dart';
import 'package:jadb/models/word_search/word_search_sense.dart';
import 'package:jadb/models/word_search/word_search_sense_language_source.dart';
import 'package:jadb/models/word_search/word_search_sources.dart';
import 'package:jadb/models/word_search/word_search_xref_entry.dart';
import 'package:jadb/util/sqlite_utils.dart';
@@ -492,8 +493,15 @@ List<WordSearchSense> _regroup_senses({
.toList(),
misc: miscs.map((e) => JMdictMisc.fromId(e['misc'] as String)).toList(),
info: infos.map((e) => e['info'] as String).toList(),
languageSource:
languageSources.map((e) => e['language'] as String).toList(),
languageSource: languageSources
.map((e) => WordSearchSenseLanguageSource(
language: e['language'] as String,
phrase: e['phrase'] as String?,
fullyDescribesSense: e['fullyDescribesSense'] == 1,
constructedFromSmallerWords:
e['constructedFromSmallerWords'] == 1,
))
.toList(),
);
result.add(resultSense);