lib/_data_ingestion: add xref exception list for jmdict
Build and test / build (push) Successful in 7m30s
Build and test / build (push) Successful in 7m30s
This commit is contained in:
@@ -45,9 +45,7 @@ class KanjiElement extends Element {
|
||||
});
|
||||
|
||||
@override
|
||||
Map<String, Object?> get sqlValue => {
|
||||
...super.sqlValue,
|
||||
};
|
||||
Map<String, Object?> get sqlValue => {...super.sqlValue};
|
||||
}
|
||||
|
||||
class ReadingElement extends Element {
|
||||
@@ -129,6 +127,19 @@ class XRefParts {
|
||||
'readingRef': readingRef,
|
||||
'senseOrderNum': senseOrderNum,
|
||||
};
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is XRefParts &&
|
||||
other.kanjiRef == kanjiRef &&
|
||||
other.readingRef == readingRef &&
|
||||
other.senseOrderNum == senseOrderNum;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(kanjiRef, readingRef, senseOrderNum);
|
||||
}
|
||||
|
||||
class XRef {
|
||||
@@ -168,9 +179,7 @@ class Sense extends SQLWritable {
|
||||
});
|
||||
|
||||
@override
|
||||
Map<String, Object?> get sqlValue => {
|
||||
'senseId': senseId,
|
||||
};
|
||||
Map<String, Object?> get sqlValue => {'senseId': senseId};
|
||||
|
||||
bool get isEmpty =>
|
||||
antonyms.isEmpty &&
|
||||
|
||||
@@ -15,6 +15,12 @@ class ResolvedXref {
|
||||
const ResolvedXref(this.entry, this.ambiguous);
|
||||
}
|
||||
|
||||
// A constant map of xref parts to jmdict id for unresolvable xrefs.
|
||||
final xrefExceptions = {
|
||||
// NOTE: see https://www.edrdg.org/jmwsgi/entr.py?svc=jmdict&g=2870981.1~2369718 for details
|
||||
XRefParts(kanjiRef: 'プレストレスト', readingRef: 'コンクリート'): 2472380,
|
||||
};
|
||||
|
||||
/// Resolves an xref (pair of kanji, optionally reading, and optionally sense number) to an a specific
|
||||
/// JMdict entry, if possible.
|
||||
///
|
||||
@@ -28,6 +34,27 @@ ResolvedXref resolveXref(
|
||||
XRefParts xref,
|
||||
) {
|
||||
late List<Entry> candidateEntries;
|
||||
|
||||
if (xrefExceptions.containsKey(xref)) {
|
||||
final exceptionEntryId = xrefExceptions[xref]!;
|
||||
// NOTE: this is slow, but we have few exceptions. Let's wait for JMdict XML-NG to be released so we can delete this :)
|
||||
final exceptionEntry =
|
||||
entriesByKanji.values
|
||||
.expand((set) => set)
|
||||
.firstWhereOrNull((entry) => entry.entryId == exceptionEntryId) ??
|
||||
entriesByReading.values
|
||||
.expand((set) => set)
|
||||
.firstWhereOrNull((entry) => entry.entryId == exceptionEntryId);
|
||||
|
||||
if (exceptionEntry != null) {
|
||||
return ResolvedXref(exceptionEntry, false);
|
||||
} else {
|
||||
throw Exception(
|
||||
'Xref $xref matches an exception entry ID $exceptionEntryId, but that entry was not found among the candidates.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
switch ((xref.kanjiRef, xref.readingRef)) {
|
||||
case (null, null):
|
||||
throw Exception('Xref $xref has no kanji or reading reference');
|
||||
|
||||
Reference in New Issue
Block a user