1

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 package yomichan
import ( import (
"errors"
"os" "os"
"regexp" "regexp"
"strconv" "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 // Display sense numbers if the entry has more than one sense
// or if the headword is found in multiple entries. // or if the headword is found in multiple entries.
hash := headword.Hash() 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 return true
} else if len(meta.headwordHashToSeqs[hash]) > 1 { } else if len(meta.headwordHashToSeqs[hash]) > 1 {
return true return true
@ -68,7 +73,7 @@ func createFormsTerm(headword headword, entry jmdict.JmdictEntry, meta jmdictMet
// Don't add "forms" terms to non-English dictionaries. // Don't add "forms" terms to non-English dictionaries.
// Information would be duplicated if users installed more // Information would be duplicated if users installed more
// than one version. // than one version.
if meta.language != "eng" { if meta.language != "eng" || !meta.extraMode {
return dbTerm{}, false return dbTerm{}, false
} }
// Don't need a "forms" term for entries with one unique // 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 { 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) reader, err := os.Open(inputPath)
if err != nil { if err != nil {
return err return err

View File

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

View File

@ -210,7 +210,7 @@ func formsExportDb(inputPath, outputPath, languageName, title string, stride int
return err return err
} }
meta := newJmdictMetadata(dictionary, "english") meta := newJmdictMetadata(dictionary, "")
terms := dbTermList{} terms := dbTermList{}
for _, entry := range dictionary.Entries { 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 { func createGlossary(sense jmdict.JmdictSense, meta jmdictMetadata) []any {
glossary := []any{} glossary := []any{}
if needsStructuredContent(sense, meta.language) { if meta.extraMode && needsStructuredContent(sense, meta.language) {
glossary = append(glossary, createGlossaryContent(sense, meta)) glossary = append(glossary, createGlossaryContent(sense, meta))
} else { } else {
for _, gloss := range sense.Glossary { for _, gloss := range sense.Glossary {

View File

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

View File

@ -17,10 +17,11 @@ function refresh_source () {
} }
refresh_source "JMdict_e_examp" 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" 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="dutch" -title="JMdict (Dutch)" src/JMdict dst/jmdict_dutch.zip
yomichan -language="french" -title="JMdict (French)" src/JMdict dst/jmdict_french.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 yomichan -language="german" -title="JMdict (German)" src/JMdict dst/jmdict_german.zip