mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
This commit addresses several high-priority tasks from the TASKS.md file, including: - **Fix Background Job Panic:** Replaced `log.Fatalf` with `log.Printf` in the `asynq` server to prevent crashes. - **Refactor API Server Setup:** Consolidated the GraphQL Playground and Prometheus metrics endpoints into the main API server. - **Implement `DeleteUser` Mutation:** Implemented the `DeleteUser` resolver. - **Implement `CreateContribution` Mutation:** Implemented the `CreateContribution` resolver and its required application service. Additionally, this commit includes a major refactoring of the configuration management system to fix a broken build. The global `config.Cfg` variable has been removed and replaced with a dependency injection approach, where the configuration object is passed to all components that require it. This change has been applied across the entire codebase, including the test suite, to ensure a stable and testable application.
109 lines
3.0 KiB
Go
109 lines
3.0 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
|
|
}
|
|
|
|
// 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,
|
|
) *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,
|
|
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,
|
|
}
|
|
}
|
|
|
|
// 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
|
|
} |