tercul-backend/models/linguistic.go
Damir Mukimov 4957117cb6 Initial commit: Tercul Go project with comprehensive architecture
- 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
2025-08-13 07:42:32 +02:00

129 lines
4.2 KiB
Go

package models
// ReadabilityScore represents a readability score for a work
type ReadabilityScore struct {
BaseModel
Score float64 `gorm:"type:decimal(5,2)"`
Language string `gorm:"size:50;not null"`
Method string `gorm:"size:50"` // e.g., Flesch-Kincaid, SMOG, etc.
WorkID uint
Work *Work `gorm:"foreignKey:WorkID"`
}
// WritingStyle represents the writing style of a work
type WritingStyle struct {
BaseModel
Name string `gorm:"size:100;not null"`
Description string `gorm:"type:text"`
Language string `gorm:"size:50;not null"`
WorkID uint
Work *Work `gorm:"foreignKey:WorkID"`
}
// LinguisticLayer represents a linguistic layer of analysis
type LinguisticLayer struct {
BaseModel
Name string `gorm:"size:100;not null"`
Description string `gorm:"type:text"`
Language string `gorm:"size:50;not null"`
Type string `gorm:"size:50"` // e.g., morphological, syntactic, semantic, etc.
WorkID uint
Work *Work `gorm:"foreignKey:WorkID"`
Data JSONB `gorm:"type:jsonb;default:'{}'"`
}
// TextBlock represents a fine-grained unit of text
type TextBlock struct {
BaseModel
WorkID *uint
Work *Work `gorm:"foreignKey:WorkID"`
TranslationID *uint
Translation *Translation `gorm:"foreignKey:TranslationID"`
Index int `gorm:"index"`
Type string `gorm:"size:30"` // paragraph|line|stanza|chapter|section
StartOffset int `gorm:"default:0"`
EndOffset int `gorm:"default:0"`
Text string `gorm:"type:text"`
}
// TextMetadata represents metadata about a text
type TextMetadata struct {
BaseModel
Analysis string `gorm:"type:text"`
Language string `gorm:"size:50;not null"`
WordCount int `gorm:"default:0"`
SentenceCount int `gorm:"default:0"`
ParagraphCount int `gorm:"default:0"`
AverageWordLength float64 `gorm:"type:decimal(5,2)"`
AverageSentenceLength float64 `gorm:"type:decimal(5,2)"`
WorkID uint
Work *Work `gorm:"foreignKey:WorkID"`
}
// PoeticAnalysis represents poetic analysis of a work
type PoeticAnalysis struct {
BaseModel
Structure string `gorm:"type:text"`
Language string `gorm:"size:50;not null"`
RhymeScheme string `gorm:"size:100"`
MeterType string `gorm:"size:50"`
StanzaCount int `gorm:"default:0"`
LineCount int `gorm:"default:0"`
WorkID uint
Work *Work `gorm:"foreignKey:WorkID"`
}
// Word represents a word in a work
type Word struct {
BaseModel
Text string `gorm:"size:100;not null"`
Language string `gorm:"size:50;not null"`
PartOfSpeech string `gorm:"size:20"`
Lemma string `gorm:"size:100"`
ConceptID *uint
Concept *Concept `gorm:"foreignKey:ConceptID"`
Works []*Work `gorm:"many2many:work_words"`
}
// WordOccurrence captures a word instance with positions
type WordOccurrence struct {
BaseModel
TextBlockID uint
TextBlock *TextBlock `gorm:"foreignKey:TextBlockID"`
WordID *uint
Word *Word `gorm:"foreignKey:WordID"`
StartOffset int `gorm:"default:0"`
EndOffset int `gorm:"default:0"`
Lemma string `gorm:"size:100"`
PartOfSpeech string `gorm:"size:20"`
}
// Concept represents a semantic concept
type Concept struct {
BaseModel
Name string `gorm:"size:100;not null"`
Description string `gorm:"type:text"`
Words []*Word `gorm:"foreignKey:ConceptID"`
Works []*Work `gorm:"many2many:work_concepts"`
}
// LanguageEntity represents a named entity in a language
type LanguageEntity struct {
BaseModel
Name string `gorm:"size:100;not null"`
Type string `gorm:"size:50"` // e.g., person, location, organization, etc.
Language string `gorm:"size:50;not null"`
Works []*Work `gorm:"many2many:work_language_entities"`
}
// EntityOccurrence captures a named entity mention with positions
type EntityOccurrence struct {
BaseModel
TextBlockID uint
TextBlock *TextBlock `gorm:"foreignKey:TextBlockID"`
LanguageEntityID uint
LanguageEntity *LanguageEntity `gorm:"foreignKey:LanguageEntityID"`
StartOffset int `gorm:"default:0"`
EndOffset int `gorm:"default:0"`
}