Documentation
¶
Overview ¶
Package moderation provides AI-powered content analysis using AWS Comprehend and Rekognition for automated content moderation.
Index ¶
- Constants
- Variables
- func ValidateIPPattern(pattern string, patternType IPPatternType) error
- func ValidateURLPattern(pattern string, patternType URLPatternType) error
- type AIAnalysisResult
- type AIAnalyzer
- type ActionType
- type AdvancedFilterEngine
- type AgeRange
- type CacheConfig
- type CacheStatistics
- type CachedPattern
- type Category
- type ConsensusConfig
- type ConsensusEngine
- func (e *ConsensusEngine) CalculateConsensus(ctx context.Context, event *ModerationEvent, reviews []*Review) (*ModerationDecision, error)
- func (e *ConsensusEngine) CheckTimeouts(ctx context.Context) error
- func (e *ConsensusEngine) GetConsensusStats(_ context.Context, _, _ time.Time) (*ConsensusStats, error)
- func (e *ConsensusEngine) ProcessReview(ctx context.Context, eventID string, review *Review) (*ModerationDecision, error)
- type ConsensusStats
- type ContentContext
- type ContentSubmission
- type ContentToModerate
- type Emotion
- type EnhancedIPMatcher
- type EnhancedPatternMatch
- type EnhancedPatternRepository
- type EnhancedURLMatcher
- type EntityDetection
- type EventType
- type Evidence
- type FaceDetection
- type FilterRepository
- type FilterResult
- type IPPatternType
- type ImageAnalysis
- type ImageContent
- type ImageLabel
- type KeyPhrase
- type ModerationDecision
- type ModerationEvent
- type ModerationFilter
- type ModerationHistory
- type ModerationLabel
- type ModerationPattern
- type ModerationQueueItem
- type ModerationResult
- type ModerationReview
- type ModerationStorage
- type Moderator
- func (m *Moderator) GetModerationQueue(ctx context.Context, filter *ModerationFilter) ([]*ModerationQueueItem, error)
- func (m *Moderator) ModerateContent(ctx context.Context, content *ContentSubmission) (*ModerationResult, error)
- func (m *Moderator) ReviewModerationDecision(ctx context.Context, review *ModerationReview) error
- type OptimizationSuggestion
- type PIIEntity
- type PatternAnalysis
- type PatternCacheManager
- func (c *PatternCacheManager) GetCompiledPattern(ctx context.Context, patternID, patternContent, patternType string) (*CachedPattern, error)
- func (c *PatternCacheManager) GetStatistics() *CacheStatistics
- func (c *PatternCacheManager) InvalidatePattern(ctx context.Context, patternID, patternContent, patternType string) error
- func (c *PatternCacheManager) MatchIP(ctx context.Context, ipStr string, ...) (bool, *models.EnhancedModerationPattern, error)
- func (c *PatternCacheManager) MatchURL(ctx context.Context, urlStr string, ...) (bool, *models.EnhancedModerationPattern, error)
- func (c *PatternCacheManager) ResetStatistics()
- type PatternEffectivenessReport
- type PatternFeedback
- type PatternManager
- func (pm *PatternManager) AnalyzePatternEffectiveness(ctx context.Context) (*PatternEffectivenessReport, error)
- func (pm *PatternManager) CreateEnhancedPattern(ctx context.Context, pattern *models.EnhancedModerationPattern) error
- func (pm *PatternManager) CreatePattern(ctx context.Context, pattern *ModerationPattern) error
- func (pm *PatternManager) DeleteEnhancedPattern(ctx context.Context, patternID string) error
- func (pm *PatternManager) GetActiveEnhancedPatterns(ctx context.Context, limit int) ([]*models.EnhancedModerationPattern, error)
- func (pm *PatternManager) GetCacheStatistics() *CacheStatistics
- func (pm *PatternManager) GetEnhancedPattern(ctx context.Context, patternID string) (*models.EnhancedModerationPattern, error)
- func (pm *PatternManager) GetPatternStatistics(ctx context.Context) (map[string]interface{}, error)
- func (pm *PatternManager) GetPatterns(ctx context.Context, active bool, severity string, limit int) ([]*ModerationPattern, error)
- func (pm *PatternManager) IsEnhancedEnabled() bool
- func (pm *PatternManager) MatchContent(ctx context.Context, content *ContentToModerate) ([]*PatternMatch, error)
- func (pm *PatternManager) MatchContentEnhanced(ctx context.Context, content *ContentToModerate) ([]*EnhancedPatternMatch, error)
- func (pm *PatternManager) OptimizePatterns(ctx context.Context) ([]*PatternOptimization, error)
- func (pm *PatternManager) UpdateEnhancedPattern(ctx context.Context, pattern *models.EnhancedModerationPattern) error
- func (pm *PatternManager) UpdatePatternStats(ctx context.Context, patternID string, wasMatch bool, wasFalsePositive bool) error
- func (pm *PatternManager) ValidateEnhancedPattern(ctx context.Context, pattern *models.EnhancedModerationPattern) (*ValidationResult, error)
- type PatternMatch
- type PatternOptimization
- type PatternRepository
- type PatternStorage
- type PatternValidator
- type QueueItem
- type Review
- type ReviewWithTrust
- type SecurityTestConfig
- type SemanticMatcher
- type SentimentAnalysis
- type Severity
- type StorageInterface
- type TextAnalysis
- type TextContent
- type TimelineEntry
- type URLPatternType
- type ValidationResult
Constants ¶
const ( // URLPatternExact represents exact URL matching URLPatternExact URLPatternType = "exact" // Exact match // URLPatternDomain represents domain and all subdomain matching URLPatternDomain URLPatternType = "domain" // Domain and all subdomains // URLPatternSubdomain represents specific subdomain pattern matching URLPatternSubdomain URLPatternType = "subdomain" // Specific subdomain pattern // URLPatternPath represents path-based URL matching URLPatternPath URLPatternType = "path" // Path-based matching // URLPatternQuery represents query parameter URL matching URLPatternQuery URLPatternType = "query" // Query parameter matching // URLPatternRegex represents regular expression URL matching URLPatternRegex URLPatternType = "regex" // Regular expression // URLPatternExactStr represents the string for exact URL pattern validation URLPatternExactStr = "url_exact" // URLPatternDomainStr represents the string for domain URL pattern validation URLPatternDomainStr = "url_domain" // URLPatternSubdomainStr represents the string for subdomain URL pattern validation URLPatternSubdomainStr = "url_subdomain" // URLPatternPathStr represents the string for path URL pattern validation URLPatternPathStr = "url_path" // URLPatternQueryStr represents the string for query URL pattern validation URLPatternQueryStr = "url_query" // URLPatternRegexStr represents the string for regex URL pattern validation URLPatternRegexStr = "url_regex" )
const ( // IPPatternSingle represents single IP address matching IPPatternSingle IPPatternType = "single" // Single IP address // IPPatternCIDR represents CIDR block matching IPPatternCIDR IPPatternType = "cidr" // CIDR block // IPPatternRange represents IP range matching IPPatternRange IPPatternType = "range" // IP range // IPPatternRegex represents regular expression IP matching IPPatternRegex IPPatternType = "regex" // Regular expression // IPPatternSingleStr represents the string for single IP pattern validation IPPatternSingleStr = "ip_single" // IPPatternCIDRStr represents the string for CIDR IP pattern validation IPPatternCIDRStr = "ip_cidr" // IPPatternRangeStr represents the string for IP range pattern validation IPPatternRangeStr = "ip_range" // IPPatternRegexStr represents the string for IP regex pattern validation IPPatternRegexStr = "ip_regex" )
const (
MatchModeKeyword = "keyword"
)
Filter match mode constants
Variables ¶
var ( ErrInvalidPattern = errors.PatternValidationFailed("invalid pattern") ErrInvalidRegexPattern = errors.PatternValidationFailed("invalid regex pattern") ErrInvalidPatternType = errors.PatternValidationFailed("invalid pattern type") ErrInvalidSeverity = errors.NewValidationError("severity", "invalid") )
Pattern validation errors
var ( ErrFailedToGetPatterns = errors.PatternQueryFailed(stdErrors.New("failed to get patterns")) ErrFailedToGetPattern = errors.FailedToGet("pattern", stdErrors.New("failed to get pattern")) ErrFailedToGetEnhancedPatterns = errors.FailedToGet("enhanced patterns", stdErrors.New("failed to get enhanced patterns")) )
Pattern retrieval errors
var ( ErrEnhancedPatternsNotAvailable = errors.ServiceUnavailable("enhanced patterns") ErrEnhancedPatternValidationNotAvailable = errors.ServiceUnavailable("enhanced pattern validation") ErrEnhancedPatternStatisticsNotAvailable = errors.ServiceUnavailable("enhanced pattern statistics") )
Enhanced pattern functionality errors
var ( ErrUnsupportedURLPatternType = errors.NewValidationError("validation", "unsupported URL pattern type") ErrUnsupportedIPPatternType = errors.NewValidationError("validation", "unsupported IP pattern type") ErrUnsupportedPatternType = errors.NewValidationError("validation", "unsupported pattern type") // URL processing errors ErrFailedToNormalizeURL = errors.NewValidationError("validation", "failed to normalize URL") ErrFailedToParseURL = errors.NewValidationError("validation", "failed to parse URL") ErrInvalidIPAddress = errors.NewValidationError("validation", "invalid IP address") ErrFailedToNormalizePattern = errors.NewValidationError("validation", "failed to normalize pattern") // Domain pattern errors ErrInvalidDomainPattern = errors.NewValidationError("validation", "invalid domain pattern") ErrFailedToCompileDomainRegex = errors.NewValidationError("validation", "failed to compile domain regex") ErrInvalidURLInDomainPattern = errors.NewValidationError("validation", "invalid URL in domain pattern") ErrInvalidHostPortFormat = errors.NewValidationError("validation", "invalid host:port format") ErrInvalidCharacterInDomain = errors.NewValidationError("validation", "invalid character in domain") ErrDomainPartHyphenRule = errors.NewValidationError("validation", "domain part cannot start or end with hyphen") // Pattern compilation errors ErrFailedToCompileSubdomainRegex = errors.NewValidationError("validation", "failed to compile subdomain regex") ErrFailedToCompilePathRegex = errors.NewValidationError("validation", "failed to compile path regex") ErrFailedToCompileQueryRegex = errors.NewValidationError("validation", "failed to compile query regex") ErrFailedToCompileURLRegex = errors.NewValidationError("validation", "failed to compile URL regex") ErrFailedToCompileIPRegex = errors.NewValidationError("validation", "failed to compile IP regex") // IP pattern errors ErrInvalidCIDRBlock = errors.NewValidationError("validation", "invalid CIDR block") ErrInvalidIPRangeFormat = errors.NewValidationError("validation", "invalid IP range format, expected start-end") ErrInvalidIPAddressesInRange = errors.NewValidationError("validation", "invalid IP addresses in range") ErrIPRangeMixedVersions = errors.NewValidationError("validation", "IP range must use same IP version") ErrInvalidIPRangeOrder = errors.NewValidationError("validation", "invalid IP range, start must be <= end") // Security errors ErrUnsafeRegexPattern = errors.NewValidationError("validation", "potentially unsafe regex pattern detected") ErrTooManyWildcards = errors.NewValidationError("validation", "too many wildcards in pattern") // Path pattern errors ErrPathMustStartWithSlash = errors.NewValidationError("validation", "path pattern must start with /") ErrPathTraversalNotAllowed = errors.NewValidationError("validation", "path traversal not allowed in patterns") // Query pattern errors ErrSpacesNotAllowedInQuery = errors.NewValidationError("validation", "spaces not allowed in query patterns") )
Enhanced pattern matching errors - URL patterns
var ( // Consensus validation errors ErrInsufficientReviewers = errors.NewValidationError("validation", "insufficient reviewers") ErrInsufficientTrustWeight = errors.NewValidationError("validation", "insufficient trust weight") ErrConsensusNotReached = errors.NewValidationError("validation", "insufficient consensus") ErrInsufficientConsensus = errors.NewValidationError("validation", "insufficient consensus for critical action") // Vote processing errors ErrVoteProcessingFailed = errors.NewValidationError("validation", "failed to process vote") ErrConsensusCalculationFailed = errors.NewValidationError("validation", "consensus calculation failed") // Storage operation errors for consensus ErrModerationEventRetrievalFailed = errors.NewValidationError("validation", "failed to get moderation event") ErrModerationReviewAddFailed = errors.NewValidationError("validation", "failed to add review") ErrModerationReviewsRetrievalFailed = errors.NewValidationError("validation", "failed to get reviews") ErrModerationDecisionStorageFailed = errors.NewValidationError("validation", "failed to store decision") ErrModerationQueueRetrievalFailed = errors.NewValidationError("validation", "failed to get moderation queue") )
Consensus-related errors
var ( // Content moderation process errors ErrPatternModerationFailed = errors.PatternAnalysisFailed(stdErrors.New("pattern moderation failed")) ErrAIAnalysisFailed = errors.ProcessingFailed("AI analysis", stdErrors.New("AI analysis failed")) ErrTextAnalysisFailed = errors.ProcessingFailed("text analysis", stdErrors.New("text analysis failed")) ErrImageAnalysisFailed = errors.ProcessingFailed("image analysis", stdErrors.New("image analysis failed")) ErrModerationDecisionFailed = errors.ProcessingFailed("moderation decision", stdErrors.New("moderation decision failed")) // Content assessment errors ErrContentViolatesPolicy = errors.ContentNotAllowed("unknown", "policy violation") ErrInsufficientModerationData = errors.NewValidationError("moderation_data", "insufficient") ErrModerationRuleNotFound = errors.NewAppError(errors.CodeNotFound, errors.CategoryBusiness, "moderation rule not found") // Storage and persistence errors // Moderation Decision storage errors ErrFailedToUpdateModerationDecision = errors.FailedToUpdate("moderation decision", stdErrors.New("failed to update moderation decision")) ErrFailedToStoreModerationDecision = errors.FailedToStore("moderation decision", stdErrors.New("failed to store moderation decision")) ErrFailedToRetrieveModerationQueue = errors.FailedToGet("moderation queue", stdErrors.New("failed to retrieve moderation queue")) )
Core moderation errors
var (
ErrPatternValidationFailed = errors.PatternValidationFailed("unknown reason")
)
Pattern validation errors
Functions ¶
func ValidateIPPattern ¶
func ValidateIPPattern(pattern string, patternType IPPatternType) error
ValidateIPPattern validates an IP pattern before compilation
func ValidateURLPattern ¶
func ValidateURLPattern(pattern string, patternType URLPatternType) error
ValidateURLPattern validates a URL pattern before compilation
Types ¶
type AIAnalysisResult ¶
type AIAnalysisResult struct {
TextAnalysis *TextAnalysis `json:"text_analysis,omitempty"`
ImageAnalysis *ImageAnalysis `json:"image_analysis,omitempty"`
}
AIAnalysisResult represents AI analysis results for moderation
type AIAnalyzer ¶
type AIAnalyzer struct {
// contains filtered or unexported fields
}
AIAnalyzer provides AI-powered content analysis for moderation
func NewAIAnalyzer ¶
func NewAIAnalyzer(cfg aws.Config) *AIAnalyzer
NewAIAnalyzer creates a new AI analyzer
func (*AIAnalyzer) AnalyzeImage ¶
func (ai *AIAnalyzer) AnalyzeImage(ctx context.Context, content *ImageContent) (*ImageAnalysis, error)
AnalyzeImage analyzes image content for moderation using AWS Rekognition
func (*AIAnalyzer) AnalyzeText ¶
func (ai *AIAnalyzer) AnalyzeText(ctx context.Context, content *TextContent) (*TextAnalysis, error)
AnalyzeText analyzes text content for moderation using AWS Comprehend
type ActionType ¶
type ActionType string
ActionType represents the action to take
const ( // ActionTypeNone represents no action taken ActionTypeNone ActionType = "none" // ActionTypeWarning represents a warning action ActionTypeWarning ActionType = "warning" // ActionTypeSilence represents a silence action ActionTypeSilence ActionType = "silence" // ActionTypeSuspend represents a suspend action ActionTypeSuspend ActionType = "suspend" // ActionTypeRemove represents a remove action ActionTypeRemove ActionType = "remove" )
type AdvancedFilterEngine ¶
type AdvancedFilterEngine struct {
// contains filtered or unexported fields
}
AdvancedFilterEngine provides enhanced content filtering capabilities
func NewAdvancedFilterEngine ¶
func NewAdvancedFilterEngine(logger *zap.Logger) *AdvancedFilterEngine
NewAdvancedFilterEngine creates a new advanced filter engine
func (*AdvancedFilterEngine) EvaluateContent ¶
func (afe *AdvancedFilterEngine) EvaluateContent( ctx context.Context, content string, filters []*models.Filter, contentCtx *ContentContext, ) ([]*FilterResult, error)
EvaluateContent evaluates content against user filters with advanced matching
func (*AdvancedFilterEngine) SetFilterRepository ¶
func (afe *AdvancedFilterEngine) SetFilterRepository(repo FilterRepository)
SetFilterRepository sets the filter repository for accessing filter data
type CacheConfig ¶
type CacheConfig struct {
MaxMemoryPatterns int `json:"max_memory_patterns"` // Maximum patterns in memory
MemoryCacheTimeout time.Duration `json:"memory_cache_timeout"` // How long to keep patterns in memory
PersistentCacheTimeout time.Duration `json:"persistent_cache_timeout"` // How long to keep in DynamoDB
PreloadActivePatterns bool `json:"preload_active_patterns"` // Preload active patterns on startup
EnableStatistics bool `json:"enable_statistics"` // Track cache statistics
CleanupInterval time.Duration `json:"cleanup_interval"` // How often to cleanup cache
EnablePersistentCache bool `json:"enable_persistent_cache"` // Enable DynamoDB caching
}
CacheConfig defines cache behavior parameters
func DefaultCacheConfig ¶
func DefaultCacheConfig() *CacheConfig
DefaultCacheConfig returns default cache configuration
type CacheStatistics ¶
type CacheStatistics struct {
MemoryHits int64 `json:"memory_hits"`
MemoryMisses int64 `json:"memory_misses"`
PersistentHits int64 `json:"persistent_hits"`
PersistentMisses int64 `json:"persistent_misses"`
CompilationCount int64 `json:"compilation_count"`
CacheEvictions int64 `json:"cache_evictions"`
TotalLookups int64 `json:"total_lookups"`
AverageCompileTime float64 `json:"average_compile_time"`
AverageRetrievalTime float64 `json:"average_retrieval_time"`
LastReset time.Time `json:"last_reset"`
// contains filtered or unexported fields
}
CacheStatistics tracks cache performance metrics
type CachedPattern ¶
type CachedPattern struct {
PatternID string `json:"pattern_id"`
PatternContent string `json:"pattern_content"`
PatternType string `json:"pattern_type"`
CompiledData interface{} `json:"compiled_data"`
CompilationHash string `json:"compilation_hash"`
CachedAt time.Time `json:"cached_at"`
LastUsed time.Time `json:"last_used"`
HitCount int64 `json:"hit_count"`
CompileTime float64 `json:"compile_time"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
CachedPattern represents a cached compiled pattern with metadata
type Category ¶
type Category string
Category represents the category of moderation
const ( // CategorySpam represents spam content category CategorySpam Category = "spam" // CategoryHateSpeech represents hate speech content category CategoryHateSpeech Category = "hate_speech" // CategoryHarassment represents harassment content category CategoryHarassment Category = "harassment" // CategoryMisinformation represents misinformation content category CategoryMisinformation Category = "misinformation" // CategoryNSFW represents NSFW content category CategoryNSFW Category = "nsfw" // CategoryViolence represents violence-related content CategoryViolence Category = "violence" // CategoryOther represents other content categories CategoryOther Category = "other" )
type ConsensusConfig ¶
type ConsensusConfig struct {
MinReviewers int `json:"min_reviewers"` // Minimum number of reviewers
MinTrustWeight float64 `json:"min_trust_weight"` // Minimum total trust weight
ConsensusThreshold float64 `json:"consensus_threshold"` // Percentage agreement required
CriticalThreshold float64 `json:"critical_threshold"` // Higher threshold for critical actions
EscalationThreshold float64 `json:"escalation_threshold"` // When to escalate for review
ReviewTimeoutHours int `json:"review_timeout_hours"` // Hours before auto-decision
}
ConsensusConfig represents the configuration for consensus calculation
func DefaultConsensusConfig ¶
func DefaultConsensusConfig() *ConsensusConfig
DefaultConsensusConfig returns the default consensus configuration
type ConsensusEngine ¶
type ConsensusEngine struct {
// contains filtered or unexported fields
}
ConsensusEngine handles consensus calculation for moderation decisions
func NewConsensusEngine ¶
func NewConsensusEngine(storage StorageInterface, config *ConsensusConfig) *ConsensusEngine
NewConsensusEngine creates a new consensus engine
func (*ConsensusEngine) CalculateConsensus ¶
func (e *ConsensusEngine) CalculateConsensus(ctx context.Context, event *ModerationEvent, reviews []*Review) (*ModerationDecision, error)
CalculateConsensus calculates consensus from reviews with trust weighting
func (*ConsensusEngine) CheckTimeouts ¶
func (e *ConsensusEngine) CheckTimeouts(ctx context.Context) error
CheckTimeouts checks for events that have timed out without consensus
func (*ConsensusEngine) GetConsensusStats ¶
func (e *ConsensusEngine) GetConsensusStats(_ context.Context, _, _ time.Time) (*ConsensusStats, error)
GetConsensusStats returns statistics about consensus decisions
func (*ConsensusEngine) ProcessReview ¶
func (e *ConsensusEngine) ProcessReview(ctx context.Context, eventID string, review *Review) (*ModerationDecision, error)
ProcessReview processes a new review and checks if consensus is reached
type ConsensusStats ¶
type ConsensusStats struct {
TotalDecisions int
AverageConsensus float64
AverageReviewers float64
ActionBreakdown map[ActionType]int
TimeToDecision time.Duration // Average time from event to decision
}
ConsensusStats represents statistics about consensus decisions
type ContentContext ¶
type ContentContext struct {
Type string `json:"type"` // home, notifications, public, thread, account
AuthorID string `json:"author_id"` // ID of content author
Timestamp time.Time `json:"timestamp"` // When content was created
IsReply bool `json:"is_reply"` // Whether content is a reply
HasMedia bool `json:"has_media"` // Whether content has media attachments
Language string `json:"language"` // Content language
Visibility string `json:"visibility"` // public, unlisted, private, direct
}
ContentContext represents the context in which content is being filtered
type ContentSubmission ¶
type ContentSubmission struct {
ID string `json:"id"`
Type string `json:"type"` // post/comment/message/profile
Text string `json:"text,omitempty"`
ImageURL string `json:"image_url,omitempty"`
ImageBytes []byte `json:"-"`
Author string `json:"author"`
SubmittedAt time.Time `json:"submitted_at"`
Metadata map[string]any `json:"metadata,omitempty"`
}
ContentSubmission represents content submitted for moderation
type ContentToModerate ¶
type ContentToModerate struct {
ID string `json:"id"`
Text string `json:"text"`
ImageHash string `json:"image_hash,omitempty"`
TextHash string `json:"text_hash,omitempty"`
Author string `json:"author"`
Type string `json:"type"` // post/comment/message/profile
Metadata map[string]any `json:"metadata,omitempty"`
}
ContentToModerate represents content to be checked against patterns
type EnhancedIPMatcher ¶
type EnhancedIPMatcher struct {
// contains filtered or unexported fields
}
EnhancedIPMatcher provides advanced IP pattern matching capabilities
func NewEnhancedIPMatcher ¶
func NewEnhancedIPMatcher() *EnhancedIPMatcher
NewEnhancedIPMatcher creates a new enhanced IP matcher
func (*EnhancedIPMatcher) CompileIPPattern ¶
func (m *EnhancedIPMatcher) CompileIPPattern(pattern string, patternType IPPatternType) error
CompileIPPattern compiles an IP pattern for efficient matching
type EnhancedPatternMatch ¶
type EnhancedPatternMatch struct {
PatternID string `json:"pattern_id"`
PatternName string `json:"pattern_name"`
PatternType string `json:"pattern_type"`
Category string `json:"category"`
Severity string `json:"severity"`
Action string `json:"action"`
Priority int `json:"priority"`
Confidence float64 `json:"confidence"`
MatchedText string `json:"matched_text"`
MatchTime float64 `json:"match_time"` // Time taken to match in milliseconds
MatchedAt time.Time `json:"matched_at"`
Effectiveness float64 `json:"effectiveness"` // Pattern effectiveness score
}
EnhancedPatternMatch represents a match from enhanced pattern matching
type EnhancedPatternRepository ¶
type EnhancedPatternRepository interface {
CreatePattern(ctx context.Context, pattern *models.EnhancedModerationPattern) error
GetPattern(ctx context.Context, patternID string) (*models.EnhancedModerationPattern, error)
UpdatePattern(ctx context.Context, pattern *models.EnhancedModerationPattern) error
DeletePattern(ctx context.Context, patternID string) error
GetActivePatterns(ctx context.Context, limit int) ([]*models.EnhancedModerationPattern, error)
RecordMatch(ctx context.Context, patternID string, isMatch bool, isTruePositive bool, matchTime float64) error
GetPatternStatistics(ctx context.Context) (map[string]interface{}, error)
// Include cache operations for the interface
GetPatternCache(ctx context.Context, patternID, patternType string) (*models.PatternCache, error)
SetPatternCache(ctx context.Context, cache *models.PatternCache) error
InvalidatePatternCache(ctx context.Context, patternID, patternType string) error
}
EnhancedPatternRepository defines the interface for enhanced pattern operations
type EnhancedURLMatcher ¶
type EnhancedURLMatcher struct {
// contains filtered or unexported fields
}
EnhancedURLMatcher provides advanced URL pattern matching capabilities
func NewEnhancedURLMatcher ¶
func NewEnhancedURLMatcher() *EnhancedURLMatcher
NewEnhancedURLMatcher creates a new enhanced URL matcher
func (*EnhancedURLMatcher) CompileURLPattern ¶
func (m *EnhancedURLMatcher) CompileURLPattern(pattern string, patternType URLPatternType) error
CompileURLPattern compiles a URL pattern for efficient matching
type EntityDetection ¶
type EntityDetection struct {
Text string `json:"text"`
Type string `json:"type"`
Score float32 `json:"score"`
BeginOffset int32 `json:"begin_offset"`
EndOffset int32 `json:"end_offset"`
}
EntityDetection represents a detected entity in text
type EventType ¶
type EventType string
EventType represents the type of moderation event
const ( // EventTypeFlagged represents a flagged content event EventTypeFlagged EventType = "flagged" // EventTypeReviewed represents a reviewed content event EventTypeReviewed EventType = "reviewed" // EventTypeAppealed represents an appealed content event EventTypeAppealed EventType = "appealed" // EventTypeExpired represents an expired content event EventTypeExpired EventType = "expired" )
type Evidence ¶
type Evidence struct {
Type string `json:"type"` // ai_detection, user_report, pattern_match, etc.
Score float64 `json:"score"` // Confidence score 0.0-1.0
Description string `json:"description"` // Human-readable description
Metadata map[string]any `json:"metadata,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
Evidence represents supporting evidence for a moderation event
type FaceDetection ¶
type FaceDetection struct {
Confidence float32 `json:"confidence"`
AgeRange *AgeRange `json:"age_range,omitempty"`
Emotions []*Emotion `json:"emotions,omitempty"`
}
FaceDetection represents a detected face in an image
type FilterRepository ¶
type FilterRepository interface {
GetFilterKeywords(ctx context.Context, filterID string) ([]*models.FilterKeyword, error)
}
FilterRepository defines the interface for accessing filter data
type FilterResult ¶
type FilterResult struct {
Matched bool `json:"matched"`
Action string `json:"action"`
Severity string `json:"severity"`
MatchScore float64 `json:"match_score"`
MatchedRules []string `json:"matched_rules"`
Filter *models.Filter `json:"filter,omitempty"`
Keywords []*models.FilterKeyword `json:"keywords,omitempty"`
}
FilterResult represents the result of filter evaluation
type ImageAnalysis ¶
type ImageAnalysis struct {
ContentID string `json:"content_id"`
ImageURL string `json:"image_url"`
ModerationLabels []*ModerationLabel `json:"moderation_labels,omitempty"`
Labels []*ImageLabel `json:"labels,omitempty"`
DetectedText []string `json:"detected_text,omitempty"`
Faces []*FaceDetection `json:"faces,omitempty"`
TextAnalysis *TextAnalysis `json:"text_analysis,omitempty"`
ModerationScore float64 `json:"moderation_score"`
RiskLevel string `json:"risk_level"`
Recommendations []string `json:"recommendations"`
AnalyzedAt time.Time `json:"analyzed_at"`
}
ImageAnalysis represents the result of image content analysis
type ImageContent ¶
type ImageContent struct {
ID string `json:"id"`
URL string `json:"url"`
ImageBytes []byte `json:"-"`
}
ImageContent represents image content to be analyzed
type ImageLabel ¶
type ImageLabel struct {
Name string `json:"name"`
Confidence float32 `json:"confidence"`
Instances int `json:"instances"`
}
ImageLabel represents a label detected in an image
type KeyPhrase ¶
type KeyPhrase struct {
Text string `json:"text"`
Score float32 `json:"score"`
BeginOffset int32 `json:"begin_offset"`
EndOffset int32 `json:"end_offset"`
}
KeyPhrase represents a detected key phrase in text
type ModerationDecision ¶
type ModerationDecision struct {
ID string `json:"id"`
EventID string `json:"event_id"`
ObjectID string `json:"object_id"`
Action ActionType `json:"action"`
Reason string `json:"reason,omitempty"` // Reason for the decision
ConsensusScore float64 `json:"consensus_score"` // Agreement percentage
ReviewerCount int `json:"reviewer_count"` // Number of reviewers
TrustWeightTotal float64 `json:"trust_weight_total"` // Total trust weight
Reviews []*Review `json:"reviews"`
Decided time.Time `json:"decided"`
AppliedAt *time.Time `json:"applied_at,omitempty"`
AppealedAt *time.Time `json:"appealed_at,omitempty"`
}
ModerationDecision represents the consensus decision
type ModerationEvent ¶
type ModerationEvent struct {
ID string `json:"id"`
EventType EventType `json:"event_type"`
ObjectID string `json:"object_id"` // ID of content being moderated
ObjectType string `json:"object_type"` // status, account, media
ActorID string `json:"actor_id"` // Who triggered this event
Category Category `json:"category"`
Severity Severity `json:"severity"`
ConfidenceScore float64 `json:"confidence_score"` // 0.0-1.0
Evidence []Evidence `json:"evidence"`
Reason string `json:"reason,omitempty"` // Human-provided reason
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
TTL int64 `json:"ttl,omitempty"` // Unix timestamp for expiration
}
ModerationEvent represents a moderation event in the system
type ModerationFilter ¶
type ModerationFilter struct {
Action string `json:"action,omitempty"`
MinScore float64 `json:"min_score,omitempty"`
MaxScore float64 `json:"max_score,omitempty"`
StartTime time.Time `json:"start_time,omitempty"`
EndTime time.Time `json:"end_time,omitempty"`
ContentType string `json:"content_type,omitempty"`
Limit int `json:"limit,omitempty"`
}
ModerationFilter represents filters for querying moderation results
type ModerationHistory ¶
type ModerationHistory struct {
ObjectID string `json:"object_id"`
Events []ModerationEvent `json:"events"`
Decisions []ModerationDecision `json:"decisions"`
CurrentStatus string `json:"current_status"`
Timeline []TimelineEntry `json:"timeline"`
}
ModerationHistory represents the complete history for an object
type ModerationLabel ¶
type ModerationLabel struct {
Name string `json:"name"`
Confidence float32 `json:"confidence"`
ParentName string `json:"parent_name,omitempty"`
}
ModerationLabel represents a moderation label detected in content
type ModerationPattern ¶
type ModerationPattern struct {
ID string `json:"id" dynamodbav:"id"`
Name string `json:"name" dynamodbav:"name"`
Description string `json:"description" dynamodbav:"description"`
Type string `json:"type" dynamodbav:"type"` // keyword/regex/phrase/domain/ip/hash
Content string `json:"content" dynamodbav:"content"`
Severity string `json:"severity" dynamodbav:"severity"` // low/medium/high/critical
Action string `json:"action" dynamodbav:"action"` // flag/hide/block/escalate
Active bool `json:"active" dynamodbav:"active"`
MatchCount int64 `json:"match_count" dynamodbav:"match_count"`
FalsePositiveCount int64 `json:"false_positive_count" dynamodbav:"false_positive_count"`
Effectiveness float64 `json:"effectiveness" dynamodbav:"effectiveness"`
LastMatch time.Time `json:"last_match" dynamodbav:"last_match"`
CreatedAt time.Time `json:"created_at" dynamodbav:"created_at"`
CreatedBy string `json:"created_by" dynamodbav:"created_by"`
UpdatedAt time.Time `json:"updated_at" dynamodbav:"updated_at"`
Tags []string `json:"tags,omitempty" dynamodbav:"tags,omitempty"`
}
ModerationPattern represents a pattern for content moderation
type ModerationQueueItem ¶
type ModerationQueueItem struct {
ContentID string `json:"content_id"`
ContentType string `json:"content_type"`
Action string `json:"action"`
Score float64 `json:"score"`
Confidence float64 `json:"confidence"`
FlaggedAt time.Time `json:"flagged_at"`
Priority string `json:"priority"`
}
ModerationQueueItem represents an item in the moderation queue
type ModerationResult ¶
type ModerationResult struct {
ContentID string `json:"content_id"`
ContentType string `json:"content_type"`
Action string `json:"action"` // allow/flag/hide/escalate/block
Score float64 `json:"score"`
Confidence float64 `json:"confidence"`
Reasons []string `json:"reasons"`
Recommendations []string `json:"recommendations"`
PatternMatches []*PatternMatch `json:"pattern_matches,omitempty"`
AIAnalysis *AIAnalysisResult `json:"ai_analysis,omitempty"`
SubmittedAt time.Time `json:"submitted_at"`
ProcessedAt time.Time `json:"processed_at"`
}
ModerationResult represents the result of content moderation
type ModerationReview ¶
type ModerationReview struct {
ContentID string `json:"content_id"`
ReviewerID string `json:"reviewer_id"`
Decision string `json:"decision"` // approve/reject/modify
Action string `json:"action,omitempty"`
Comments string `json:"comments,omitempty"`
PatternFeedback map[string]*PatternFeedback `json:"pattern_feedback,omitempty"`
ReviewedAt time.Time `json:"reviewed_at"`
}
ModerationReview represents a human review of moderated content
type ModerationStorage ¶
type ModerationStorage interface {
StoreModerationDecision(ctx context.Context, decision *ModerationResult) error
UpdateModerationDecision(ctx context.Context, contentID string, review *ModerationReview) error
GetModerationHistory(ctx context.Context, contentID string) ([]*ModerationResult, error)
GetModerationQueue(ctx context.Context, filter *ModerationFilter) ([]*ModerationQueueItem, error)
}
ModerationStorage defines storage operations needed by the moderator
type Moderator ¶
type Moderator struct {
// contains filtered or unexported fields
}
Moderator provides comprehensive content moderation
func NewModerator ¶
func NewModerator(store ModerationStorage, aiAnalyzer *AIAnalyzer) *Moderator
NewModerator creates a new moderator instance
func (*Moderator) GetModerationQueue ¶
func (m *Moderator) GetModerationQueue(ctx context.Context, filter *ModerationFilter) ([]*ModerationQueueItem, error)
GetModerationQueue retrieves items that need manual review
func (*Moderator) ModerateContent ¶
func (m *Moderator) ModerateContent(ctx context.Context, content *ContentSubmission) (*ModerationResult, error)
ModerateContent performs comprehensive content moderation
func (*Moderator) ReviewModerationDecision ¶
func (m *Moderator) ReviewModerationDecision(ctx context.Context, review *ModerationReview) error
ReviewModerationDecision allows moderators to review and update decisions
type OptimizationSuggestion ¶
type OptimizationSuggestion struct {
Type string `json:"type"` // specificity/relevance/precision/performance
Description string `json:"description"`
Impact string `json:"impact"` // low/medium/high
}
OptimizationSuggestion represents a suggested optimization for a pattern
type PIIEntity ¶
type PIIEntity struct {
Type string `json:"type"`
Score float32 `json:"score"`
BeginOffset int32 `json:"begin_offset"`
EndOffset int32 `json:"end_offset"`
}
PIIEntity represents a detected personally identifiable information entity
type PatternAnalysis ¶
type PatternAnalysis struct {
PatternID string `json:"pattern_id"`
PatternType string `json:"pattern_type"`
Severity string `json:"severity"`
MatchCount int64 `json:"match_count"`
FalsePositiveCount int64 `json:"false_positive_count"`
Effectiveness float64 `json:"effectiveness"`
TruePositiveRate float64 `json:"true_positive_rate"`
Performance string `json:"performance"` // poor/moderate/good
LastMatch time.Time `json:"last_match"`
CreatedAt time.Time `json:"created_at"`
Recommendations []string `json:"recommendations"`
}
PatternAnalysis represents detailed analysis of a pattern
type PatternCacheManager ¶
type PatternCacheManager struct {
// contains filtered or unexported fields
}
PatternCacheManager manages in-memory and persistent pattern caching for performance
func NewPatternCacheManager ¶
func NewPatternCacheManager(repository PatternRepository, config *CacheConfig, logger *zap.Logger) *PatternCacheManager
NewPatternCacheManager creates a new pattern cache manager
func (*PatternCacheManager) GetCompiledPattern ¶
func (c *PatternCacheManager) GetCompiledPattern(ctx context.Context, patternID, patternContent, patternType string) (*CachedPattern, error)
GetCompiledPattern retrieves a compiled pattern from cache or compiles it
func (*PatternCacheManager) GetStatistics ¶
func (c *PatternCacheManager) GetStatistics() *CacheStatistics
GetStatistics returns cache performance statistics
func (*PatternCacheManager) InvalidatePattern ¶
func (c *PatternCacheManager) InvalidatePattern(ctx context.Context, patternID, patternContent, patternType string) error
InvalidatePattern removes a pattern from all caches
func (*PatternCacheManager) MatchIP ¶
func (c *PatternCacheManager) MatchIP(ctx context.Context, ipStr string, patterns []*models.EnhancedModerationPattern) (bool, *models.EnhancedModerationPattern, error)
MatchIP matches an IP using cached patterns
func (*PatternCacheManager) MatchURL ¶
func (c *PatternCacheManager) MatchURL(ctx context.Context, urlStr string, patterns []*models.EnhancedModerationPattern) (bool, *models.EnhancedModerationPattern, error)
MatchURL matches a URL using cached patterns
func (*PatternCacheManager) ResetStatistics ¶
func (c *PatternCacheManager) ResetStatistics()
ResetStatistics resets cache statistics
type PatternEffectivenessReport ¶
type PatternEffectivenessReport struct {
GeneratedAt time.Time `json:"generated_at"`
TotalPatterns int `json:"total_patterns"`
AverageEffectiveness float64 `json:"average_effectiveness"`
OverallFalsePositiveRate float64 `json:"overall_false_positive_rate"`
InefficientPatterns int `json:"inefficient_patterns"`
PatternAnalysis []*PatternAnalysis `json:"pattern_analysis"`
Recommendations []string `json:"recommendations"`
}
PatternEffectivenessReport represents a report on pattern effectiveness
type PatternFeedback ¶
type PatternFeedback struct {
WasMatch bool `json:"was_match"`
WasFalsePositive bool `json:"was_false_positive"`
}
PatternFeedback represents feedback on pattern match accuracy
type PatternManager ¶
type PatternManager struct {
// contains filtered or unexported fields
}
PatternManager manages moderation patterns and their effectiveness
func NewEnhancedPatternManager ¶
func NewEnhancedPatternManager(storage PatternStorage, enhancedRepo EnhancedPatternRepository, logger *zap.Logger) *PatternManager
NewEnhancedPatternManager creates a pattern manager with enhanced capabilities
func NewPatternManager ¶
func NewPatternManager() *PatternManager
NewPatternManager creates a new pattern manager
func (*PatternManager) AnalyzePatternEffectiveness ¶
func (pm *PatternManager) AnalyzePatternEffectiveness(ctx context.Context) (*PatternEffectivenessReport, error)
AnalyzePatternEffectiveness analyzes the effectiveness of patterns
func (*PatternManager) CreateEnhancedPattern ¶
func (pm *PatternManager) CreateEnhancedPattern(ctx context.Context, pattern *models.EnhancedModerationPattern) error
CreateEnhancedPattern creates a new enhanced moderation pattern
func (*PatternManager) CreatePattern ¶
func (pm *PatternManager) CreatePattern(ctx context.Context, pattern *ModerationPattern) error
CreatePattern creates a new moderation pattern
func (*PatternManager) DeleteEnhancedPattern ¶
func (pm *PatternManager) DeleteEnhancedPattern(ctx context.Context, patternID string) error
DeleteEnhancedPattern deletes an enhanced pattern
func (*PatternManager) GetActiveEnhancedPatterns ¶
func (pm *PatternManager) GetActiveEnhancedPatterns(ctx context.Context, limit int) ([]*models.EnhancedModerationPattern, error)
GetActiveEnhancedPatterns retrieves all active enhanced patterns
func (*PatternManager) GetCacheStatistics ¶
func (pm *PatternManager) GetCacheStatistics() *CacheStatistics
GetCacheStatistics returns pattern cache statistics
func (*PatternManager) GetEnhancedPattern ¶
func (pm *PatternManager) GetEnhancedPattern(ctx context.Context, patternID string) (*models.EnhancedModerationPattern, error)
GetEnhancedPattern retrieves an enhanced pattern by ID
func (*PatternManager) GetPatternStatistics ¶
func (pm *PatternManager) GetPatternStatistics(ctx context.Context) (map[string]interface{}, error)
GetPatternStatistics returns enhanced pattern statistics
func (*PatternManager) GetPatterns ¶
func (pm *PatternManager) GetPatterns(ctx context.Context, active bool, severity string, limit int) ([]*ModerationPattern, error)
GetPatterns retrieves patterns based on criteria
func (*PatternManager) IsEnhancedEnabled ¶
func (pm *PatternManager) IsEnhancedEnabled() bool
IsEnhancedEnabled returns whether enhanced pattern matching is enabled
func (*PatternManager) MatchContent ¶
func (pm *PatternManager) MatchContent(ctx context.Context, content *ContentToModerate) ([]*PatternMatch, error)
MatchContent matches content against all active patterns
func (*PatternManager) MatchContentEnhanced ¶
func (pm *PatternManager) MatchContentEnhanced(ctx context.Context, content *ContentToModerate) ([]*EnhancedPatternMatch, error)
MatchContentEnhanced matches content against enhanced patterns
func (*PatternManager) OptimizePatterns ¶
func (pm *PatternManager) OptimizePatterns(ctx context.Context) ([]*PatternOptimization, error)
OptimizePatterns suggests optimizations for pattern performance
func (*PatternManager) UpdateEnhancedPattern ¶
func (pm *PatternManager) UpdateEnhancedPattern(ctx context.Context, pattern *models.EnhancedModerationPattern) error
UpdateEnhancedPattern updates an enhanced pattern
func (*PatternManager) UpdatePatternStats ¶
func (pm *PatternManager) UpdatePatternStats(ctx context.Context, patternID string, wasMatch bool, wasFalsePositive bool) error
UpdatePatternStats updates statistics for a pattern
func (*PatternManager) ValidateEnhancedPattern ¶
func (pm *PatternManager) ValidateEnhancedPattern(ctx context.Context, pattern *models.EnhancedModerationPattern) (*ValidationResult, error)
ValidateEnhancedPattern validates an enhanced pattern
type PatternMatch ¶
type PatternMatch struct {
PatternID string `json:"pattern_id"`
PatternName string `json:"pattern_name"`
PatternType string `json:"pattern_type"`
Severity string `json:"severity"`
Confidence float64 `json:"confidence"`
MatchedText string `json:"matched_text"`
Action string `json:"action"`
MatchedAt time.Time `json:"matched_at"`
}
PatternMatch represents a matched pattern in content
type PatternOptimization ¶
type PatternOptimization struct {
PatternID string `json:"pattern_id"`
PatternName string `json:"pattern_name"`
CurrentEffectiveness float64 `json:"current_effectiveness"`
Suggestions []OptimizationSuggestion `json:"suggestions"`
}
PatternOptimization represents optimization recommendations for patterns
type PatternRepository ¶
type PatternRepository interface {
GetPatternCache(ctx context.Context, patternID, patternType string) (*models.PatternCache, error)
SetPatternCache(ctx context.Context, cache *models.PatternCache) error
InvalidatePatternCache(ctx context.Context, patternID, patternType string) error
}
PatternRepository defines the interface for pattern storage operations needed by the cache
type PatternStorage ¶
type PatternStorage interface {
CreateModerationPattern(ctx context.Context, pattern *ModerationPattern) error
GetModerationPattern(ctx context.Context, patternID string) (*ModerationPattern, error)
GetModerationPatterns(ctx context.Context, active bool, severity string, limit int) ([]*ModerationPattern, error)
UpdateModerationPattern(ctx context.Context, pattern *ModerationPattern) error
UpdatePatternStats(ctx context.Context, patternID string, matched bool, falsePositive bool) error
RecordPatternMatch(ctx context.Context, patternID string, matched bool, timestamp time.Time) error
}
PatternStorage defines storage operations needed by pattern manager
type PatternValidator ¶
type PatternValidator struct {
// contains filtered or unexported fields
}
PatternValidator provides comprehensive validation and testing for moderation patterns
func NewPatternValidator ¶
func NewPatternValidator(logger *zap.Logger) *PatternValidator
NewPatternValidator creates a new pattern validator
func (*PatternValidator) CreateTestResult ¶
func (v *PatternValidator) CreateTestResult(pattern *models.EnhancedModerationPattern, validationResult *ValidationResult, testType string, runBy string) *models.PatternTestResult
CreateTestResult creates a test result record for storage
func (*PatternValidator) ValidatePattern ¶
func (v *PatternValidator) ValidatePattern(_ context.Context, pattern *models.EnhancedModerationPattern, config *SecurityTestConfig) (*ValidationResult, error)
ValidatePattern performs comprehensive validation of a moderation pattern
type QueueItem ¶
type QueueItem struct {
Event *ModerationEvent `json:"event"`
Priority float64 `json:"priority"` // Calculated based on severity and confidence
ReviewCount int `json:"review_count"`
LastReviewedAt *time.Time `json:"last_reviewed_at,omitempty"`
}
QueueItem represents an item in the moderation queue
type Review ¶
type Review struct {
ID string `json:"id"`
EventID string `json:"event_id"`
ReviewerID string `json:"reviewer_id"`
Action ActionType `json:"action"`
Category Category `json:"category"`
Severity Severity `json:"severity"`
Confidence float64 `json:"confidence"` // 0.0-1.0
Notes string `json:"notes,omitempty"`
Weight float64 `json:"weight"` // Trust-weighted value
Created time.Time `json:"created"`
}
Review represents a moderation review by a reviewer
type ReviewWithTrust ¶
type ReviewWithTrust struct {
Review *Review
Trust *models.TrustScore
Weight float64
}
ReviewWithTrust combines a review with trust information
type SecurityTestConfig ¶
type SecurityTestConfig struct {
TestReDoSVulnerability bool `json:"test_redos_vulnerability"`
TestInjectionAttacks bool `json:"test_injection_attacks"`
TestPatternComplexity bool `json:"test_pattern_complexity"`
TestResourceConsumption bool `json:"test_resource_consumption"`
MaxAllowedComplexity int `json:"max_allowed_complexity"`
MaxExecutionTimeMs float64 `json:"max_execution_time_ms"`
DangerousPatterns []string `json:"dangerous_patterns"`
TestInputs []string `json:"test_inputs"`
}
SecurityTestConfig defines security testing parameters
func DefaultSecurityTestConfig ¶
func DefaultSecurityTestConfig() *SecurityTestConfig
DefaultSecurityTestConfig returns default security test configuration
type SemanticMatcher ¶
type SemanticMatcher struct {
}
SemanticMatcher provides AI-powered semantic content analysis
func NewSemanticMatcher ¶
func NewSemanticMatcher() *SemanticMatcher
NewSemanticMatcher creates a new semantic matcher
func (*SemanticMatcher) AnalyzeContent ¶
func (sm *SemanticMatcher) AnalyzeContent(content string) (score float64, categories []string)
AnalyzeContent analyzes content for semantic patterns
type SentimentAnalysis ¶
type SentimentAnalysis struct {
Sentiment string `json:"sentiment"`
PositiveScore float32 `json:"positive_score"`
NegativeScore float32 `json:"negative_score"`
NeutralScore float32 `json:"neutral_score"`
MixedScore float32 `json:"mixed_score"`
}
SentimentAnalysis represents sentiment analysis results
type Severity ¶
type Severity int
Severity represents the severity level
const ( // SeverityLow represents low severity level SeverityLow Severity = 1 // SeverityMedium represents medium severity level SeverityMedium Severity = 2 // SeverityHigh represents high severity level SeverityHigh Severity = 3 // SeverityCritical represents critical severity level SeverityCritical Severity = 4 )
type StorageInterface ¶
type StorageInterface interface {
GetModerationEvent(ctx context.Context, eventID string) (*ModerationEvent, error)
AddModerationReview(ctx context.Context, review *Review) error
GetModerationReviews(ctx context.Context, eventID string) ([]*Review, error)
CreateModerationDecision(ctx context.Context, decision *ModerationDecision) error
GetModerationQueue(ctx context.Context, limit int, cursor string) ([]*QueueItem, string, error)
GetTrustScore(ctx context.Context, actorID, category string) (*models.TrustScore, error)
RecordTrustUpdate(ctx context.Context, update *models.TrustUpdate) error
}
StorageInterface defines the storage operations needed by the consensus engine
type TextAnalysis ¶
type TextAnalysis struct {
ContentID string `json:"content_id"`
Text string `json:"text"`
Language string `json:"language"`
Sentiment *SentimentAnalysis `json:"sentiment,omitempty"`
Entities []*EntityDetection `json:"entities,omitempty"`
KeyPhrases []*KeyPhrase `json:"key_phrases,omitempty"`
PIIEntities []*PIIEntity `json:"pii_entities,omitempty"`
ModerationScore float64 `json:"moderation_score"`
RiskLevel string `json:"risk_level"`
Recommendations []string `json:"recommendations"`
AnalyzedAt time.Time `json:"analyzed_at"`
}
TextAnalysis represents the result of text content analysis
type TextContent ¶
TextContent represents text content to be analyzed
type TimelineEntry ¶
type TimelineEntry struct {
Timestamp time.Time `json:"timestamp"`
Type string `json:"type"` // event, review, decision, appeal
ActorID string `json:"actor_id"`
Description string `json:"description"`
Metadata map[string]any `json:"metadata,omitempty"`
}
TimelineEntry represents an entry in the moderation timeline
type ValidationResult ¶
type ValidationResult struct {
Valid bool `json:"valid"`
Score float64 `json:"score"` // 0.0-1.0
SecurityScore float64 `json:"security_score"`
PerformanceScore float64 `json:"performance_score"`
AccuracyScore float64 `json:"accuracy_score"`
Errors []string `json:"errors,omitempty"`
Warnings []string `json:"warnings,omitempty"`
Recommendations []string `json:"recommendations,omitempty"`
TestResults map[string]interface{} `json:"test_results"`
CompilationTime float64 `json:"compilation_time"` // milliseconds
EstimatedMatchTime float64 `json:"estimated_match_time"` // milliseconds per match
}
ValidationResult represents the result of pattern validation