tercul-backend/internal/jobs/linguistics/factory.go
Damir Mukimov d50722dad5
Some checks failed
Test / Integration Tests (push) Successful in 4s
Build / Build Binary (push) Failing after 2m9s
Docker Build / Build Docker Image (push) Failing after 2m32s
Test / Unit Tests (push) Failing after 3m12s
Lint / Go Lint (push) Failing after 1m0s
Refactor ID handling to use UUIDs across the application
- Updated database models and repositories to replace uint IDs with UUIDs.
- Modified test fixtures to generate and use UUIDs for authors, translations, users, and works.
- Adjusted mock implementations to align with the new UUID structure.
- Ensured all relevant functions and methods are updated to handle UUIDs correctly.
- Added necessary imports for UUID handling in various files.
2025-12-27 00:33:34 +01:00

118 lines
3.2 KiB
Go

package linguistics
import (
"tercul/internal/platform/cache"
"tercul/internal/platform/config"
"gorm.io/gorm"
)
// LinguisticsFactory provides easy access to all linguistics components
type LinguisticsFactory struct {
textAnalyzer TextAnalyzer
analysisCache AnalysisCache
analysisRepo AnalysisRepository
workAnalysisService WorkAnalysisService
analyzer Analyzer
sentimentProvider SentimentProvider
cache cache.Cache
concurrency int
cacheEnabled bool
}
// NewLinguisticsFactory creates a new LinguisticsFactory with all components
func NewLinguisticsFactory(
cfg *config.Config,
db *gorm.DB,
cache cache.Cache,
concurrency int,
cacheEnabled bool,
sentimentProvider SentimentProvider,
workAnalyticsDeps WorkAnalyticsDeps,
) *LinguisticsFactory {
// Create text analyzer and wire providers (prefer external libs when available)
textAnalyzer := NewBasicTextAnalyzer()
// Wire sentiment provider
textAnalyzer = textAnalyzer.WithSentimentProvider(sentimentProvider)
// Wire language detector: lingua-go (configurable)
if cfg.NLPUseLingua {
textAnalyzer = textAnalyzer.WithLanguageDetector(NewLinguaLanguageDetector())
}
// Wire keyword provider: lightweight TF-IDF approximation (configurable)
if cfg.NLPUseTFIDF {
textAnalyzer = textAnalyzer.WithKeywordProvider(NewTFIDFKeywordProvider())
}
// Create cache components
memoryCache := NewMemoryAnalysisCache(cfg, cacheEnabled)
redisCache := NewRedisAnalysisCache(cfg, cache, cacheEnabled)
analysisCache := NewCompositeAnalysisCache(memoryCache, redisCache, cacheEnabled)
// Create repository
analysisRepo := NewGORMAnalysisRepository(db)
// Create work analysis service
workAnalysisService := NewWorkAnalysisService(
textAnalyzer,
analysisCache,
analysisRepo,
workAnalyticsDeps,
concurrency,
cacheEnabled,
)
// Create analyzer that combines text analysis and work analysis
analyzer := NewBasicAnalyzer(
textAnalyzer,
workAnalysisService,
cache,
concurrency,
cacheEnabled,
)
return &LinguisticsFactory{
textAnalyzer: textAnalyzer,
analysisCache: analysisCache,
analysisRepo: analysisRepo,
workAnalysisService: workAnalysisService,
analyzer: analyzer,
sentimentProvider: sentimentProvider,
cache: cache,
concurrency: concurrency,
cacheEnabled: cacheEnabled,
}
}
// GetTextAnalyzer returns the text analyzer
func (f *LinguisticsFactory) GetTextAnalyzer() TextAnalyzer {
return f.textAnalyzer
}
// GetAnalysisCache returns the analysis cache
func (f *LinguisticsFactory) GetAnalysisCache() AnalysisCache {
return f.analysisCache
}
// GetAnalysisRepository returns the analysis repository
func (f *LinguisticsFactory) GetAnalysisRepository() AnalysisRepository {
return f.analysisRepo
}
// GetWorkAnalysisService returns the work analysis service
func (f *LinguisticsFactory) GetWorkAnalysisService() WorkAnalysisService {
return f.workAnalysisService
}
// GetAnalyzer returns the analyzer
func (f *LinguisticsFactory) GetAnalyzer() Analyzer {
return f.analyzer
}
// GetSentimentProvider returns the sentiment provider
func (f *LinguisticsFactory) GetSentimentProvider() SentimentProvider {
return f.sentimentProvider
}