1

Add verification logic for date entry in JMdict

Very old versions of JMdict and unofficial versions are unlikely to
have the publication date entry at the end of the file.
This commit is contained in:
stephenmk 2023-01-30 13:26:26 -06:00
parent 74de4ce9e5
commit b826dbf264
No known key found for this signature in database
GPG Key ID: B6DA730DB06235F1

View File

@ -63,10 +63,20 @@ func doDisplaySenseNumberTag(headword headword, entry jmdict.JmdictEntry, meta j
}
func jmdictPublicationDate(dictionary jmdict.Jmdict) string {
if len(dictionary.Entries) == 0 {
return "unknown"
}
dateEntry := dictionary.Entries[len(dictionary.Entries)-1]
if len(dateEntry.Sense) == 0 || len(dateEntry.Sense[0].Glossary) == 0 {
return "unknown"
}
r := regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)
jmdictDate := r.FindString(dateEntry.Sense[0].Glossary[0].Content)
return jmdictDate
if jmdictDate != "" {
return jmdictDate
} else {
return "unknown"
}
}
func createFormsTerm(headword headword, entry jmdict.JmdictEntry, meta jmdictMetadata) (dbTerm, bool) {