check

package
v0.0.56 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0, MIT Imports: 19 Imported by: ? 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 check verifies a manuscript draft did not write: that its references name real works, its citations point at entries, and the works it cites say what it cites them for.

Every finding comes from a fixed rule over the manuscript's own text and what the lookups return; a model is asked only to propose a quote for the support check, and the quote is then held to the verbatim gate (refs/support). A reference no lookup could ask about is never reported as clean: Report.Unavailable says the check is incomplete.

Index

Constants

View Source
const (
	Error = "error"
	Warn  = "warn"
)

The severities a finding can have.

View Source
const (
	RefFabricated   = "REF-FABRICATED"
	RefMismatch     = "REF-MISMATCH"
	RefAmbiguous    = "REF-AMBIGUOUS"
	RefRetracted    = "REF-RETRACTED"
	RefUnverifiable = "REF-UNVERIFIABLE"
	RefUncited      = "REF-UNCITED"
	CiteDangling    = "CITE-DANGLING"
	CiteUnsupported = "CITE-UNSUPPORTED"
	CiteWeak        = "CITE-WEAK"
	NumUnsourced    = "NUM-UNSOURCED"
	HedgeUpgrade    = "HEDGE-UPGRADE"
	QuoteUnsourced  = "QUOTE-UNSOURCED"
	Injection       = "INJECTION"
)

The finding codes. Each is documented with its rule in docs/check-report.md.

View Source
const (
	FailFabricated  = "fabricated"
	FailUnsupported = "unsupported" // every error, and CITE-UNSUPPORTED
	FailAny         = "any"
)

The --fail-on levels.

View Source
const (
	ExitClean       = 0
	ExitFindings    = 1
	ExitUsage       = 2
	ExitUnavailable = 3
)

The exit codes of `draft check`.

View Source
const SARIFSchema = "https://json.schemastore.org/sarif-2.1.0.json"

SARIFSchema is the schema the SARIF report names.

View Source
const Schema = "draft.check-report/v1"

Schema names the report format, a stable contract (docs/check-report.md).

Variables

View Source
var Rules = map[string]string{
	RefFabricated:   "A reference whose own identifier is false: a DOI no registration agency issued, or an arXiv id with no paper",
	RefMismatch:     "A reference whose DOI or arXiv id names a different work",
	RefAmbiguous:    "A reference two records match",
	RefRetracted:    "A reference to a retracted work",
	RefUnverifiable: "A reference no lookup has a record of, without a false identifier",
	RefUncited:      "A reference-list entry no citation names",
	CiteDangling:    "A citation that names no entry of the reference list",
	CiteUnsupported: "A citation whose work's full text had no passage the model found to state the sentence; check by hand",
	CiteWeak:        "A citation whose work's abstract does not state the sentence; its full text was not read",
	NumUnsourced:    "A number in no cited work, or not in the data file",
	HedgeUpgrade:    "A sentence that states as settled what the cited work hedges",
	QuoteUnsourced:  "A quotation not found in the cited work",
	Injection:       "Invisible characters, or text addressed to a model reading the manuscript",
}

Rules describes every finding code, as the SARIF report and the docs name it.

Functions

func ReadPDF

func ReadPDF(ctx context.Context, body []byte, extract func(context.Context, string) (string, error)) (string, error)

ReadPDF writes body to a temporary file and reads its text with extract; body must be a PDF, so a login page or an error page is refused rather than read as the work.

func ValidFailOn

func ValidFailOn(level string) bool

ValidFailOn reports whether level is a --fail-on level.

func WriteSARIF

func WriteSARIF(w io.Writer, version string, reports ...Report) error

WriteSARIF writes the reports as one SARIF 2.1.0 log, a run per manuscript, so GitHub code scanning can show the findings on a pull request.

Types

type DOIChecker

type DOIChecker func(ctx context.Context, doi string) (bool, error)

DOIChecker asks whether a DOI was ever registered (resolve.Fetcher.DOIExists).

type Finding

type Finding struct {
	Code     string `json:"code"`
	Severity string `json:"severity"`
	// Line is the line of the extracted text the finding is on, from 1; 0
	// when it concerns the reference list as a whole.
	Line     int    `json:"line,omitempty"`
	Sentence string `json:"sentence,omitempty"`
	// Reference is the entry concerned, as the list gives it.
	Reference string `json:"reference,omitempty"`
	Reason    string `json:"reason"`
	// Evidence is what the finding rests on: a record's address, a quote.
	Evidence string `json:"evidence,omitempty"`
}

Finding is one thing wrong with the manuscript.

type Labelled

type Labelled struct {
	ID         string `json:"id"`
	Fabricated bool   `json:"fabricated"`
}

Labelled is a reference whose truth is known: Fabricated when it was made up, as the evaluation set marks it.

type Metrics

type Metrics struct {
	TruePositives  int     `json:"true_positives"`
	FalsePositives int     `json:"false_positives"`
	FalseNegatives int     `json:"false_negatives"`
	Precision      float64 `json:"precision"`
	Recall         float64 `json:"recall"`
}

Metrics are how well REF-FABRICATED separates made-up references from real ones on a labelled set (plan WP-E3.4).

func FabricationMetrics

func FabricationMetrics(labels []Labelled, flagged map[string]bool) Metrics

FabricationMetrics scores the references flagged as fabricated against the labels. A reference with no label is not counted.

type Options

type Options struct {
	// Lookups resolve the references. None means every reference is
	// unchecked.
	Lookups []resolve.Lookup
	// Offline says the lookups are local only, so a reference they do not
	// know is unchecked, not unavailable.
	Offline bool
	// Bib is a bibliography the author vouches for; its entries join the
	// manuscript's own list for citation markers.
	Bib []refs.Reference
	// Supporter and Texts run the support check; without both it is not run.
	Supporter Supporter
	Texts     Texts
	// DOIExists asks the DOI system about a DOI no lookup knows, so a
	// DataCite DOI is not reported as made up. Without it such a DOI is
	// unverifiable.
	DOIExists DOIChecker
	// Data is the text of a data file every stated number must appear in.
	Data string
	// Generator names the program, for the report.
	Generator string
}

Options are what the check may use.

type Report

type Report struct {
	Schema    string    `json:"schema"`
	Source    string    `json:"source"`
	Generator string    `json:"generator"`
	Summary   Summary   `json:"summary"`
	Findings  []Finding `json:"findings"`
	// Unavailable is set when a lookup could not be asked about some
	// reference and the check was not run offline: the report is then
	// incomplete, and is never clean.
	Unavailable bool `json:"unavailable"`
	// Notes say what was not checked and why.
	Notes []string `json:"notes,omitempty"`
}

Report is the outcome of checking one manuscript.

func Check

func Check(ctx context.Context, name, text string, opts Options) Report

Check checks a manuscript's extracted text.

func (Report) Exit

func (rep Report) Exit(level string) int

Exit is the exit code for the report at a --fail-on level: findings at or above it come first; then a check that could not ask about every reference is never clean.

func (Report) WriteJSON

func (rep Report) WriteJSON(w io.Writer) error

WriteJSON writes the report as draft.check-report/v1.

func (Report) WriteText

func (rep Report) WriteText(w io.Writer, level string) error

WriteText writes the report for a person: a verdict, then the findings by severity.

type SourceTexts

type SourceTexts struct {
	// Dir holds local copies of cited works, named by arXiv id
	// ("2306.05685.pdf"), DOI with "/" as "_" ("10.1145_363235.363259.pdf"),
	// BibTeX key or list label ("12.pdf").
	Dir string
	// Extract reads a local file's text (internal/pdf.Extract).
	Extract func(ctx context.Context, path string) (string, error)
	// Download reads a full text at an address, or is nil when the check
	// may not use the network.
	Download func(ctx context.Context, url string) (string, error)
}

SourceTexts reads cited works: a local copy in Dir first, then the full text the work's record points at, then its abstract.

func (SourceTexts) Text

func (s SourceTexts) Text(ctx context.Context, ref refs.Reference, work *resolve.Work) (string, string)

Text is the most of the cited work there is to read, and its tier.

type Summary

type Summary struct {
	References  int `json:"references"`
	Cited       int `json:"cited"`
	Resolved    int `json:"resolved"`
	Unavailable int `json:"unavailable"`
	Unchecked   int `json:"unchecked"`
	Supported   int `json:"supported"`
	Errors      int `json:"errors"`
	Warnings    int `json:"warnings"`
}

Summary counts what was checked.

type Supporter

type Supporter interface {
	Support(ctx context.Context, claim string, passages []string) (string, error)
}

Supporter proposes a quote from a cited work's passages for a claim, as the support check asks (prompt.Support); refs/support decides the answer.

type Texts

type Texts interface {
	Text(ctx context.Context, ref refs.Reference, work *resolve.Work) (text, tier string)
}

Texts gives what can be read of a cited work, and how much of it: its full text, its abstract, or nothing (refs/support tiers).

Jump to

Keyboard shortcuts

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