mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 00:31:35 +00:00
- Core Go application with GraphQL API using gqlgen - Comprehensive data models for literary works, authors, translations - Repository pattern with caching layer - Authentication and authorization system - Linguistics analysis capabilities with multiple adapters - Vector search integration with Weaviate - Docker containerization support - Python data migration and analysis scripts - Clean architecture with proper separation of concerns - Production-ready configuration and middleware - Proper .gitignore excluding vendor/, database files, and build artifacts
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package linguistics
|
|
|
|
import (
|
|
"strings"
|
|
lingua "github.com/pemistahl/lingua-go"
|
|
)
|
|
|
|
// LinguaLanguageDetector implements LanguageDetector using lingua-go
|
|
type LinguaLanguageDetector struct {
|
|
detector lingua.LanguageDetector
|
|
}
|
|
|
|
// NewLinguaLanguageDetector builds a detector for all supported languages
|
|
func NewLinguaLanguageDetector() *LinguaLanguageDetector {
|
|
det := lingua.NewLanguageDetectorBuilder().FromAllLanguages().Build()
|
|
return &LinguaLanguageDetector{detector: det}
|
|
}
|
|
|
|
// DetectLanguage returns a lowercase ISO 639-1 code if possible
|
|
func (l *LinguaLanguageDetector) DetectLanguage(text string) (string, bool) {
|
|
lang, ok := l.detector.DetectLanguageOf(text)
|
|
if !ok {
|
|
return "", false
|
|
}
|
|
// Prefer ISO 639-1 when available else fallback to ISO 639-3
|
|
if s := lang.IsoCode639_1().String(); s != "" {
|
|
return s, true
|
|
}
|
|
if s := lang.IsoCode639_3().String(); s != "" {
|
|
return s, true
|
|
}
|
|
// fallback to language name
|
|
return strings.ToLower(lang.String()), true
|
|
}
|
|
|
|
|