match

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package match is the canonical term-overlap primitive: it scores how much of a new text another record already holds, by the words the two share, and classifies a likely double as `duplicates` (near-identical) or `refines` (narrower). It is a lexical HEURISTIC and says so on every result it returns (Heuristic): no model is consulted, nothing semantic is claimed, and a match is a proposal a person confirms or removes (itd-2609212137116617).

It is the one home of the overlap score (the one-canonical-primitive rule): the filing-time match of `capture` and of the quoted-text `intent` create call it, and any later ranking by shared terms (the embark ranking the reflect spec names) calls it rather than growing a copy. It sits below the record dispatcher rather than inside it because the dispatcher reads the capture and intent stores, and both of those call this package; a leaf package is what lets every caller reach it without an import cycle.

The scorer reads nothing, writes nothing and never prints; the one read in the package is LoadConfig, through the layered configuration reader. Its callers gather the candidate texts under their own locks and write the links.

Index

Constants

View Source
const (
	// FieldIssueBody is an open or resolved issue's markdown body.
	FieldIssueBody = "issue.body"
	// FieldIntentTitle is an intent's H1.
	FieldIntentTitle = "intent.title"
	// FieldIntentPressRelease is an intent's `## Press Release` section.
	FieldIntentPressRelease = "intent.press_release"
)

The compared fields: which text of each candidate family the match reads. The set is closed; a name outside it is refused, never ignored.

View Source
const (
	// DefaultThreshold is the weighted share of the new text's terms a
	// candidate must hold for a link to be written. It was read off this
	// repository's own ledger on 2026-09-26: each of the 449 open issues was
	// matched against the other 1,660 issues and intents, and 14 cleared 0.6.
	// Most of those were the same finding filed twice or a narrower follow-up
	// of an earlier one; the false ones shared a relocation footer rather than
	// a finding. Below 0.6 the best pairs stop being the same finding.
	DefaultThreshold = 0.6
	// MinTerms is the fewest distinct terms a new text needs before it is
	// compared at all. Below it the overlap of a line or two is chance, so the
	// record is filed without matching and the outcome says so (the intent's
	// scope condition).
	MinTerms = 8
	// MaxLinks caps the links one filing writes. A text that clears the
	// threshold against more candidates than this links the highest scorers;
	// the rest are still listed, so nothing is hidden.
	MaxLinks = 3
	// NearMissLimit caps how many below-threshold candidates an outcome lists.
	NearMissLimit = 5
)

Bundled defaults. The threshold is configuration (the layered resolver's match.threshold); the rest are declared constants of the heuristic.

View Source
const Heuristic = "lexical term overlap, weighted by how rare each term is across the candidates; a heuristic, not a judgement"

Heuristic names the method on every outcome, so a surface never renders a score as more than it is.

Variables

DefaultFields is the bundled match.fields: every field in the set.

Functions

func Overlap

func Overlap(a, b []string, w Weights) (forward, reverse float64, shared []string)

Overlap is THE overlap score: the weighted share of a's terms that b holds (forward), the weighted share of b's terms that a holds (reverse), and the shared terms, rarest first. Both inputs are sorted term sets (Terms).

func Short

func Short(text string) bool

Short reports whether text carries fewer distinct terms than MinTerms, so a caller can file it without gathering any candidates: Rank would compare nothing anyway.

func Terms

func Terms(text string) []string

Terms is the canonical tokeniser: lower-cased runs of letters and digits, at least three runes long, neither a stop word nor all digits (a count, a date or a record number says nothing about what a finding is), each once, sorted.

Types

type Candidate

type Candidate struct {
	ID   string
	Text string
}

Candidate is one existing record's comparable text.

type Config

type Config struct {
	Threshold       float64  `json:"threshold"`
	ThresholdOrigin string   `json:"threshold_origin"`
	Fields          []string `json:"fields"`
	FieldsOrigin    string   `json:"fields_origin"`
}

Config is the resolved match configuration, with the origin of each value (the layered resolver's: "bundled", a file, or a flag), so a surface can say where a threshold came from.

func Bundled

func Bundled() Config

Bundled is the configuration when nothing is configured.

func LoadConfig

func LoadConfig(r layered.Roots) (Config, error)

LoadConfig resolves match.threshold and match.fields through the one layered configuration reader (.abcd/config.json, then ~/.abcd.noindex/config.json, then the bundled defaults). It claims the `match` namespace, so a misspelt key is refused rather than letting a default apply unannounced, and a value outside its range or set is refused naming its file, never replaced by the default.

func (Config) Compares

func (c Config) Compares(field string) bool

Compares reports whether the configuration reads field.

type Outcome

type Outcome struct {
	Heuristic string  `json:"heuristic"`
	Threshold float64 `json:"threshold"`
	// Terms is the number of distinct terms the new text carries.
	Terms    int `json:"terms"`
	MinTerms int `json:"min_terms"`
	// Compared is the number of candidates scored.
	Compared int `json:"compared"`
	// Skipped says why no candidate was compared; empty when matching ran.
	Skipped string `json:"skipped,omitempty"`
	// Matches are the candidates at or above the threshold, best first.
	Matches []Score `json:"matches"`
	// NearMisses are the best candidates below it, with their scores.
	NearMisses []Score `json:"near_misses"`
}

Outcome is one text matched against a candidate set.

func Rank

func Rank(text string, cands []Candidate, threshold float64) Outcome

Rank matches text against every candidate. A threshold outside (0, 1] is the caller's fault and reads as the bundled default, so a matcher can never be configured into linking everything or nothing by accident; the layered reader refuses such a value before it gets here.

func Skip

func Skip(threshold float64, reason string) Outcome

Skip is the outcome of a match that compared nothing, for the reason given: the filing goes ahead, and the reason is what a surface says.

func Unread

func Unread(threshold float64, err error) Outcome

Unread is the outcome of a match whose candidate set could not be read: the record is filed without matching, and the reason travels with the outcome rather than refusing the write.

func (o Outcome) Links() map[Relation][]string

Links returns the typed links an outcome writes, relation → ids, best first.

type Relation

type Relation string

Relation is the typed link a match writes. The vocabulary is the itd-84 discipline's (supersedes / reverses / duplicates / refines); a lexical score can only ever propose the two below. A reversal or a supersession is a judgement about meaning, which the discipline keeps advisory and human, so this package never proposes either.

const (
	// Duplicates: the two texts hold each other's terms, both ways.
	Duplicates Relation = "duplicates"
	// Refines: the candidate holds the new text's terms, and carries a good
	// deal more besides — the new record is the narrower of the two.
	Refines Relation = "refines"
)

type Score

type Score struct {
	ID string `json:"id"`
	// Score is the weighted share of the NEW text's terms this candidate holds,
	// in [0, 1] and rounded to three places. It is what the threshold compares.
	Score float64 `json:"score"`
	// Reverse is the weighted share of the CANDIDATE's terms the new text
	// holds: high both ways is a duplicate, high one way a refinement.
	Reverse float64 `json:"reverse"`
	// Relation is set on a match above the threshold, and empty on a near miss.
	Relation Relation `json:"relation,omitempty"`
	// Linked is true when the writer wrote this match onto the record: every
	// match up to MaxLinks.
	Linked bool `json:"linked"`
	// Shared are the rarest terms the two have in common, the evidence a person
	// reads before confirming or removing the link.
	Shared []string `json:"shared_terms"`
}

Score is one candidate's result.

type Weights

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

Weights is the rarity weight of every term across a candidate set: a term few candidates carry says more about a text than one most of them carry. A term no candidate carries takes the highest weight.

func NewWeights

func NewWeights(sets [][]string) Weights

NewWeights counts, per term, how many of the term sets carry it.

func (Weights) Of

func (w Weights) Of(term string) float64

Of is a term's weight: a smoothed inverse document frequency, always > 0.

Jump to

Keyboard shortcuts

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