word_search_result: add romanization getters
This commit is contained in:
@@ -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<WordSearchMatchSpan>? matchSpans;
|
||||
|
||||
/// All contents of [japanese], transliterated to romaji
|
||||
List<String> 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<WordSearchRuby> 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<WordSearchMatchSpan>? 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
|
||||
|
||||
Reference in New Issue
Block a user