do not use language detector model on dev mode.

because it's slow.
This commit is contained in:
fiatjaf
2023-12-31 17:50:01 -03:00
parent d1d172b96c
commit 91a0ea768b
3 changed files with 28 additions and 21 deletions

View File

@@ -115,6 +115,7 @@ type ScriptRange struct {
func initializeImageDrawingStuff() error {
// language detector
if !s.SkipLanguageModel {
detector = lingua.NewLanguageDetectorBuilder().FromLanguages(
lingua.Japanese,
lingua.Persian,
@@ -126,6 +127,7 @@ func initializeImageDrawingStuff() error {
lingua.Hindi,
lingua.Korean,
).WithLowAccuracyMode().Build()
}
// script detector material
for _, srange := range language.ScriptRanges {
@@ -252,12 +254,16 @@ gotScriptIndex:
direction := directionMap[idx]
lng := language.Language("en-us")
if detector == nil {
lng = defaultLanguageMap[idx]
} else {
lang, ok := detector.DetectLanguageOf(string(paragraph))
if ok {
lng = language.Language(lang.IsoCode639_1().String())
} else {
lng = defaultLanguageMap[idx]
}
}
return lng, script, direction, face
}

View File

@@ -1,7 +1,7 @@
export PATH := "./node_modules/.bin:" + env_var('PATH')
dev:
TAILWIND_DEBUG=true go build -o /tmp/njump && /tmp/njump
TAILWIND_DEBUG=true SKIP_LANGUAGE_MODEL=true go build -o /tmp/njump && /tmp/njump
check-samples:
#!/usr/bin/env xonsh

View File

@@ -24,6 +24,7 @@ type Settings struct {
DiskCachePath string `envconfig:"DISK_CACHE_PATH" default:"/tmp/njump-internal"`
EventStorePath string `envconfig:"EVENT_STORE_PATH" default:"/tmp/njump-db"`
TailwindDebug bool `envconfig:"TAILWIND_DEBUG"`
SkipLanguageModel bool `envconfig:"SKIP_LANGUAGE_MODEL"`
}
//go:embed static/*