From 0b6e21af57acedbfffd5dd6ac9c9845caa202ebe Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sat, 28 Feb 2026 18:46:13 +0900 Subject: [PATCH] word_search_result: add romanization getters --- .../word_search/word_search_result.dart | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/models/word_search/word_search_result.dart b/lib/models/word_search/word_search_result.dart index 658a6c7..9640a88 100644 --- a/lib/models/word_search/word_search_result.dart +++ b/lib/models/word_search/word_search_result.dart @@ -6,6 +6,7 @@ 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_sources.dart'; import 'package:jadb/search/word_search/word_search.dart'; +import 'package:jadb/util/romaji_transliteration.dart'; /// A class representing a single dictionary entry from a word search. class WordSearchResult { @@ -44,6 +45,35 @@ class WordSearchResult { /// the original searchword. List? matchSpans; + /// All contents of [japanese], transliterated to romaji + List get romaji => japanese + .map((word) => transliterateKanaToLatin(word.furigana ?? word.base)) + .toList(); + + /// All contents of [japanase], where the furigana has either been transliterated to romaji, or + /// contains the furigana transliteration of [WordSearchRuby.base]. + List get romajiRubys => japanese + .map( + (word) => WordSearchRuby( + base: word.base, + furigana: word.furigana != null + ? transliterateKanaToLatin(word.furigana!) + : transliterateKanaToLatin(word.base), + ), + ) + .toList(); + + /// The same list of spans as [matchSpans], but the positions have been adjusted for romaji conversion + /// + /// This is mostly useful in conjunction with [romajiRubys]. + List? get romajiMatchSpans { + if (matchSpans == null) { + return null; + } + + throw UnimplementedError('Not yet implemented'); + } + WordSearchResult({ required this.score, required this.entryId, @@ -163,7 +193,7 @@ class WordSearchResult { this.matchSpans = matchSpans; } - String _formatJapaneseWord(WordSearchRuby word) => + static String _formatJapaneseWord(WordSearchRuby word) => word.furigana == null ? word.base : '${word.base} (${word.furigana})'; @override