1
Fork 0

Hide new JMdict structured content features behind "extra" option

Require `-language=english_extra` to produce the complete version of
the new JMdict dictionary file.

If and when we determine that the all the new features are ready to be
included the dictionary by default, we can remove this logic.
This commit is contained in:
stephenmk 2023-01-29 14:06:50 -06:00
parent abbe183145
commit 8b4b899959
No known key found for this signature in database
GPG Key ID: B6DA730DB06235F1
6 changed files with 30 additions and 17 deletions

View File

@ -1,6 +1,7 @@
package yomichan
import (
"errors"
"os"
"regexp"
"strconv"
@ -48,7 +49,11 @@ func doDisplaySenseNumberTag(headword headword, entry jmdict.JmdictEntry, meta j
// Display sense numbers if the entry has more than one sense
// or if the headword is found in multiple entries.
hash := headword.Hash()
if meta.seqToSenseCount[entry.Sequence] > 1 {
if !meta.extraMode {
return false
} else if meta.language != "eng" {
return false
} else if meta.seqToSenseCount[entry.Sequence] > 1 {
return true
} else if len(meta.headwordHashToSeqs[hash]) > 1 {
return true
@ -68,7 +73,7 @@ func createFormsTerm(headword headword, entry jmdict.JmdictEntry, meta jmdictMet
// Don't add "forms" terms to non-English dictionaries.
// Information would be duplicated if users installed more
// than one version.
if meta.language != "eng" {
if meta.language != "eng" || !meta.extraMode {
return dbTerm{}, false
}
// Don't need a "forms" term for entries with one unique
@ -193,6 +198,10 @@ func extractTerms(headword headword, entry jmdict.JmdictEntry, meta jmdictMetada
}
func jmdExportDb(inputPath string, outputPath string, languageName string, title string, stride int, pretty bool) error {
if _, ok := langNameToCode[languageName]; !ok {
return errors.New("Unrecognized language parameter: " + languageName)
}
reader, err := os.Open(inputPath)
if err != nil {
return err

View File

@ -42,17 +42,18 @@ var ISOtoFlag = map[string]string{
}
var langNameToCode = map[string]string{
"": "eng",
"english": "eng",
"dutch": "dut",
"french": "fre",
"german": "ger",
"hungarian": "hun",
"italian": "ita",
"russian": "rus",
"slovenian": "slv",
"spanish": "spa",
"swedish": "swe",
"": "eng",
"english": "eng",
"english_extra": "eng",
"dutch": "dut",
"french": "fre",
"german": "ger",
"hungarian": "hun",
"italian": "ita",
"russian": "rus",
"slovenian": "slv",
"spanish": "spa",
"swedish": "swe",
}
var glossTypeCodeToName = map[LangCode]string{

View File

@ -210,7 +210,7 @@ func formsExportDb(inputPath, outputPath, languageName, title string, stride int
return err
}
meta := newJmdictMetadata(dictionary, "english")
meta := newJmdictMetadata(dictionary, "")
terms := dbTermList{}
for _, entry := range dictionary.Entries {

View File

@ -287,7 +287,7 @@ func createGlossaryContent(sense jmdict.JmdictSense, meta jmdictMetadata) any {
func createGlossary(sense jmdict.JmdictSense, meta jmdictMetadata) []any {
glossary := []any{}
if needsStructuredContent(sense, meta.language) {
if meta.extraMode && needsStructuredContent(sense, meta.language) {
glossary = append(glossary, createGlossaryContent(sense, meta))
} else {
for _, gloss := range sense.Glossary {

View File

@ -23,6 +23,7 @@ type jmdictMetadata struct {
entryDepth map[sequence]int
hasMultipleForms map[sequence]bool
maxSenseCount int
extraMode bool
}
type senseID struct {
@ -152,6 +153,7 @@ func newJmdictMetadata(dictionary jmdict.Jmdict, languageName string) jmdictMeta
entryDepth: make(map[sequence]int),
hasMultipleForms: make(map[sequence]bool),
maxSenseCount: 0,
extraMode: languageName == "english_extra",
}
for _, entry := range dictionary.Entries {

View File

@ -17,10 +17,11 @@ function refresh_source () {
}
refresh_source "JMdict_e_examp"
yomichan -language="english" -title="JMdict" src/JMdict_e_examp dst/jmdict_english_with_examples.zip
yomichan -language="english_extra" -title="JMdict" src/JMdict_e_examp dst/jmdict_english_extra_with_examples.zip
refresh_source "JMdict"
yomichan -language="english" -title="JMdict" src/JMdict dst/jmdict_english.zip
yomichan -language="english_extra" -title="JMdict" src/JMdict dst/jmdict_english_extra.zip
yomichan -language="english" -title="JMdict (English)" src/JMdict dst/jmdict_english.zip
yomichan -language="dutch" -title="JMdict (Dutch)" src/JMdict dst/jmdict_dutch.zip
yomichan -language="french" -title="JMdict (French)" src/JMdict dst/jmdict_french.zip
yomichan -language="german" -title="JMdict (German)" src/JMdict dst/jmdict_german.zip