similarity

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package similarity owns exact, versioned thread similarity policies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeText

func NormalizeText(value string) string

NormalizeText lowercases text, replaces punctuation with spaces, and collapses whitespace.

func Tokens

func Tokens(text string, filterStopWords bool) []string

Tokens returns sorted unique tokens using the duplicate-v1 normalization policy.

func TokensLimited

func TokensLimited(text string, filterStopWords bool, maxWords int) []string

TokensLimited returns sorted unique tokens after processing at most maxWords input words.

Types

type DuplicateRule

type DuplicateRule struct {
	// contains filtered or unexported fields
}

DuplicateRule is the validated duplicate-v1 preparation and scoring policy.

func DefaultDuplicateRule

func DefaultDuplicateRule() DuplicateRule

DefaultDuplicateRule returns the supported duplicate-v1 scoring policy.

func (DuplicateRule) Compare

Compare scores two prepared threads exactly under duplicate-v1.

func (DuplicateRule) Prepare

func (r DuplicateRule) Prepare(thread ThreadText) PreparedDuplicate

Prepare normalizes every field once for repeated exact comparisons.

func (DuplicateRule) Score added in v0.13.0

func (r DuplicateRule) Score(a, b PreparedDuplicate) float64

Score returns the exact duplicate-v1 score without building an explanation.

func (DuplicateRule) Threshold added in v0.13.0

func (DuplicateRule) Threshold() float64

Threshold returns the minimum duplicate-v1 score.

func (DuplicateRule) Valid

func (r DuplicateRule) Valid() bool

Valid reports whether the rule was created by a supported constructor.

func (DuplicateRule) Version

func (DuplicateRule) Version() RuleVersion

Version identifies the exact duplicate scoring semantics.

func (DuplicateRule) VisitCandidatePairs added in v0.13.0

func (r DuplicateRule) VisitCandidatePairs(ctx context.Context, prepared []PreparedDuplicate, visit func(left, right int)) error

VisitCandidatePairs visits every pair that can reach the duplicate-v1 threshold. A pair without an explicit reference or shared title token can score at most 0.15 from body, labels, and author, below the 0.30 threshold.

type DuplicateScore

type DuplicateScore struct {
	Value       float64
	Reason      string
	Signals     DuplicateSignals
	RuleVersion RuleVersion
}

DuplicateScore is an exact duplicate-v1 score with its explanation and version.

type DuplicateSignals

type DuplicateSignals struct {
	ExplicitRef  bool
	TitleJaccard float64
	BodyJaccard  float64
	LabelJaccard float64
	SameAuthor   bool
}

DuplicateSignals are the explainable components of duplicate-v1 scoring.

func (DuplicateSignals) Reason

func (s DuplicateSignals) Reason() string

Reason explains the strongest duplicate-v1 signals.

func (DuplicateSignals) Score

func (s DuplicateSignals) Score() float64

Score returns the weighted duplicate-v1 score.

type PrecedentRule

type PrecedentRule struct{}

PrecedentRule is the exact precedent-v1 lexical Jaccard policy.

func DefaultPrecedentRule

func DefaultPrecedentRule() PrecedentRule

DefaultPrecedentRule returns the supported precedent-v1 scoring policy.

func (PrecedentRule) Compare

func (PrecedentRule) Compare(a, b PreparedLexical) float64

Compare returns exact Jaccard similarity under precedent-v1.

func (PrecedentRule) Prepare

func (PrecedentRule) Prepare(text string) PreparedLexical

Prepare lowercases text and retains unique alphanumeric tokens of at least three bytes.

func (PrecedentRule) Version

func (PrecedentRule) Version() RuleVersion

Version identifies the exact precedent scoring semantics.

type PreparedDuplicate

type PreparedDuplicate struct {
	// contains filtered or unexported fields
}

PreparedDuplicate is an immutable duplicate-v1 representation of a thread.

type PreparedLexical

type PreparedLexical struct {
	// contains filtered or unexported fields
}

PreparedLexical is an immutable precedent-v1 token set.

type RuleVersion

type RuleVersion string

RuleVersion identifies the exact preparation and scoring semantics used for a result.

const (
	// DuplicateV1 is the weighted duplicate-candidate scoring contract.
	DuplicateV1 RuleVersion = "duplicate-v1"
	// PrecedentV1 is the lexical Jaccard precedent scoring contract.
	PrecedentV1 RuleVersion = "precedent-v1"
)

type ThreadRef

type ThreadRef struct {
	Repo   domain.RepoRef
	Kind   domain.ThreadKind
	Number int
}

ThreadRef identifies one issue or pull request for exact similarity scoring.

func ExtractRefs

func ExtractRefs(text string, defaultRepo domain.RepoRef) []ThreadRef

ExtractRefs returns sorted, unique GitHub thread references found in text.

func (ThreadRef) Less

func (r ThreadRef) Less(other ThreadRef) bool

Less reports the canonical ordering of thread references.

type ThreadText

type ThreadText struct {
	Ref    ThreadRef
	Title  string
	Body   string
	Labels []string
	Author string
}

ThreadText contains the exact local fields consumed by a similarity policy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL