data_ingestion/jmdict: throw proper errors on invalid xrefs
This commit is contained in:
@@ -27,15 +27,44 @@ ResolvedXref resolveXref(
|
||||
SplayTreeMap<String, Set<Entry>> entriesByReading,
|
||||
XRefParts xref,
|
||||
) {
|
||||
List<Entry> 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<Entry> 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) {
|
||||
|
||||
Reference in New Issue
Block a user