diff --git a/lib/_data_ingestion/jmdict/seed_data.dart b/lib/_data_ingestion/jmdict/seed_data.dart index 3f8a510..ef07fd5 100644 --- a/lib/_data_ingestion/jmdict/seed_data.dart +++ b/lib/_data_ingestion/jmdict/seed_data.dart @@ -27,15 +27,44 @@ ResolvedXref resolveXref( SplayTreeMap> entriesByReading, XRefParts xref, ) { - List candidateEntries = switch ((xref.kanjiRef, xref.readingRef)) { - (null, null) => throw Exception( - 'Xref $xref has no kanji or reading reference', - ), - (final String k, null) => entriesByKanji[k]!.toList(), - (null, final String r) => entriesByReading[r]!.toList(), - (final String k, final String r) => - entriesByKanji[k]!.intersection(entriesByReading[r]!).toList(), - }; + late List candidateEntries; + switch ((xref.kanjiRef, xref.readingRef)) { + case (null, null): + throw Exception('Xref $xref has no kanji or reading reference'); + + case (final String k, null): + if (!entriesByKanji.containsKey(k)) { + throw Exception( + 'Xref $xref has kanji reference "$k" but no entries found with that kanji', + ); + } + candidateEntries = entriesByKanji[k]!.toList(); + break; + + case (null, final String r): + if (!entriesByReading.containsKey(r)) { + throw Exception( + 'Xref $xref has reading reference "$r" but no entries found with that reading', + ); + } + candidateEntries = entriesByReading[r]!.toList(); + break; + + case (final String k, final String r): + if (!entriesByKanji.containsKey(k)) { + throw Exception( + 'Xref $xref has kanji reference "$k" but no entries found with that kanji', + ); + } + if (!entriesByReading.containsKey(r)) { + throw Exception( + 'Xref $xref has reading reference "$r" but no entries found with that reading', + ); + } + candidateEntries = entriesByKanji[k]! + .intersection(entriesByReading[r]!) + .toList(); + } // Filter out entries that don't have the number of senses specified in the xref if (xref.senseOrderNum != null) {