Documentation
¶
Overview ¶
Package notes provides community note scoring algorithms and visibility calculations for content annotation.
Index ¶
- Constants
- func CalculateNoteLimit(reputation float64) int
- func CalculateNoteScore(note *CommunityNote, votes []Vote) float64
- func CalculateStats(notes []CommunityNote) map[string]any
- func CalculateVoteWeight(voterRep float64, voteType VoteType) float64
- func GenerateNoteID() string
- type Analysis
- type CommunityNote
- type CreateNoteRequest
- type NotesResponse
- type Service
- func (s *Service) CheckNoteRateLimit(ctx context.Context, userID string, limit int) (bool, int)
- func (s *Service) CheckRateLimit(ctx context.Context, userID string, reputation float64) (bool, int)
- func (s *Service) CreateNote(ctx context.Context, note *CommunityNote) error
- func (s *Service) GetNote(ctx context.Context, noteID string) (*CommunityNote, error)
- func (s *Service) GetNotesByAuthor(ctx context.Context, authorID string, limit int32) ([]CommunityNote, error)
- func (s *Service) GetUserVotes(ctx context.Context, userID string, noteIDs []string) (map[string]Vote, error)
- func (s *Service) GetVisibleNotes(ctx context.Context, objectID string) ([]CommunityNote, error)
- func (s *Service) GetVotesForNote(ctx context.Context, noteID string) ([]Vote, error)
- func (s *Service) RecalculateNoteScore(ctx context.Context, noteID string) error
- func (s *Service) StoreNote(ctx context.Context, note *CommunityNote) error
- func (s *Service) StoreVote(ctx context.Context, vote *Vote) error
- func (s *Service) UpdateNoteScore(ctx context.Context, noteID string, score float64, status VisibilityStatus) error
- func (s *Service) VoteOnNote(ctx context.Context, vote *Vote) error
- type Source
- type VisibilityStatus
- type Vote
- type VoteRequest
- type VoteType
Constants ¶
const ( // Reputation requirements MinReputationToCreateNotes = 100.0 MinReputationToVote = 10.0 // Visibility thresholds VisibilityThreshold = 0.5 // Minimum score to be visible ProminentThreshold = 0.75 // Score for prominent display DisputeThreshold = 0.3 // Below this, mark as disputed FederationThreshold = 0.7 // Minimum score to federate // Federation requirements FederationMinRep = 500.0 // Minimum reputation to accept federated notes // Rate limits (notes per day based on reputation) BaseNoteLimit = 1 MaxNoteLimit = 10 // Content limits MaxNoteLength = 500 MinNoteLength = 10 MaxSources = 5 MaxReasonLength = 200 // TTL NoteTTLDays = 90 )
Constants for thresholds and limits
Variables ¶
This section is empty.
Functions ¶
func CalculateNoteLimit ¶
CalculateNoteLimit determines how many notes a user can create per day
func CalculateNoteScore ¶
func CalculateNoteScore(note *CommunityNote, votes []Vote) float64
CalculateNoteScore computes visibility score based on multiple factors
func CalculateStats ¶
func CalculateStats(notes []CommunityNote) map[string]any
CalculateStats generates statistics for a set of notes
func CalculateVoteWeight ¶
CalculateVoteWeight determines the weight of a vote based on voter reputation
func GenerateNoteID ¶
func GenerateNoteID() string
GenerateNoteID generates a unique ID for a note using enhanced ULID generation
Types ¶
type Analysis ¶
type Analysis struct {
Sentiment float64 `json:"sentiment"`
Objectivity float64 `json:"objectivity"`
HasPII bool `json:"has_pii"`
Language string `json:"language"`
Keywords []string `json:"keywords"`
}
Analysis represents AI analysis results
type CommunityNote ¶
type CommunityNote struct {
// Identity
ID string `json:"id" dynamodbav:"ID"`
ObjectID string `json:"object_id" dynamodbav:"ObjectID"`
ObjectType string `json:"object_type" dynamodbav:"ObjectType"`
// Author
AuthorID string `json:"author_id" dynamodbav:"AuthorID"`
AuthorRep float64 `json:"author_reputation" dynamodbav:"AuthorRep"`
// Content
Content string `json:"content" dynamodbav:"Content"`
Language string `json:"language" dynamodbav:"Language"`
Sources []Source `json:"sources" dynamodbav:"Sources"`
// Scoring
HelpfulVotes int `json:"helpful_votes" dynamodbav:"HelpfulVotes"`
NotHelpfulVotes int `json:"not_helpful_votes" dynamodbav:"NotHelpfulVotes"`
Score float64 `json:"score" dynamodbav:"Score"`
VisibilityStatus VisibilityStatus `json:"visibility_status" dynamodbav:"VisibilityStatus"`
// AI Analysis
Sentiment float64 `json:"sentiment" dynamodbav:"Sentiment"`
Objectivity float64 `json:"objectivity" dynamodbav:"Objectivity"`
SourceQuality float64 `json:"source_quality" dynamodbav:"SourceQuality"`
// Federation
Federated bool `json:"federated" dynamodbav:"Federated"`
FederatedAt *time.Time `json:"federated_at,omitempty" dynamodbav:"FederatedAt,omitempty"`
// Metadata
CreatedAt time.Time `json:"created_at" dynamodbav:"CreatedAt"`
UpdatedAt time.Time `json:"updated_at" dynamodbav:"UpdatedAt"`
TTL int64 `json:"-" dynamodbav:"TTL,omitempty"`
}
CommunityNote represents a fact-checking note on any ActivityPub object
func RankNotesByTrust ¶
func RankNotesByTrust(notes []CommunityNote, _ string, trustScores map[string]float64) []CommunityNote
RankNotesByTrust adjusts note ordering based on viewer's trust relationships
type CreateNoteRequest ¶
type CreateNoteRequest struct {
ObjectID string `json:"object_id" validate:"required"`
ObjectType string `json:"object_type" validate:"required"`
Content string `json:"content" validate:"required,min=10,max=500"`
Language string `json:"language" validate:"required,len=2"`
Sources []Source `json:"sources" validate:"max=5"`
}
CreateNoteRequest represents a request to create a community note
type NotesResponse ¶
type NotesResponse struct {
Notes []CommunityNote `json:"notes"`
Stats map[string]any `json:"stats"`
}
NotesResponse represents a response containing community notes
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides methods for managing community notes
func NewService ¶
func NewService(storage core.RepositoryStorage, logger *zap.Logger) *Service
NewService creates a new notes service
func (*Service) CheckNoteRateLimit ¶
CheckNoteRateLimit checks if a user can create more notes
func (*Service) CheckRateLimit ¶
func (s *Service) CheckRateLimit(ctx context.Context, userID string, reputation float64) (bool, int)
CheckRateLimit checks if a user can create more notes
func (*Service) CreateNote ¶
func (s *Service) CreateNote(ctx context.Context, note *CommunityNote) error
CreateNote creates a new community note
func (*Service) GetNotesByAuthor ¶
func (s *Service) GetNotesByAuthor(ctx context.Context, authorID string, limit int32) ([]CommunityNote, error)
GetNotesByAuthor retrieves notes created by a specific author
func (*Service) GetUserVotes ¶
func (s *Service) GetUserVotes(ctx context.Context, userID string, noteIDs []string) (map[string]Vote, error)
GetUserVotes retrieves a user's votes on specific notes
func (*Service) GetVisibleNotes ¶
GetVisibleNotes retrieves visible notes for an object
func (*Service) GetVotesForNote ¶
GetVotesForNote retrieves all votes for a note
func (*Service) RecalculateNoteScore ¶
RecalculateNoteScore recalculates a note's score based on current votes
func (*Service) StoreNote ¶
func (s *Service) StoreNote(ctx context.Context, note *CommunityNote) error
StoreNote stores a community note
func (*Service) UpdateNoteScore ¶
func (s *Service) UpdateNoteScore(ctx context.Context, noteID string, score float64, status VisibilityStatus) error
UpdateNoteScore updates a note's score and visibility status
type Source ¶
type Source struct {
URL string `json:"url" dynamodbav:"URL"`
Title string `json:"title" dynamodbav:"Title"`
Domain string `json:"domain" dynamodbav:"Domain"`
Reliability float64 `json:"reliability" dynamodbav:"Reliability"`
}
Source represents a reference supporting the note
type VisibilityStatus ¶
type VisibilityStatus string
VisibilityStatus represents the visibility state of a note
const ( // VisibilityPending represents pending visibility status VisibilityPending VisibilityStatus = "pending" // VisibilityVisible represents visible visibility status VisibilityVisible VisibilityStatus = "visible" // VisibilityHidden represents hidden visibility status VisibilityHidden VisibilityStatus = "hidden" // VisibilityDisputed represents disputed visibility status VisibilityDisputed VisibilityStatus = "disputed" )
func DetermineVisibilityStatus ¶
func DetermineVisibilityStatus(score float64) VisibilityStatus
DetermineVisibilityStatus determines if a note should be visible based on score
type Vote ¶
type Vote struct {
NoteID string `json:"note_id" dynamodbav:"NoteID"`
VoterID string `json:"voter_id" dynamodbav:"VoterID"`
VoterRep float64 `json:"voter_reputation" dynamodbav:"VoterRep"`
VoteType VoteType `json:"vote_type" dynamodbav:"VoteType"`
Reason string `json:"reason,omitempty" dynamodbav:"Reason,omitempty"`
Weight float64 `json:"weight" dynamodbav:"Weight"`
CreatedAt time.Time `json:"created_at" dynamodbav:"CreatedAt"`
}
Vote represents a user's vote on a note
type VoteRequest ¶
type VoteRequest struct {
VoteType VoteType `json:"vote_type" validate:"required,oneof=helpful not_helpful neutral"`
Reason string `json:"reason" validate:"max=200"`
}
VoteRequest represents a request to vote on a community note