refs

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: 7 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.

README

draft/refs

Reads a source's reference list into records a citation can point at, the citation markers in a quote into the records they name, and BibTeX files; refs/resolve decides whether a record names a real work, and refs/support whether the work says what the citing claim says.

Go reference Website

Every field is read from the entry's own text by a fixed rule and is a stretch of that text: a DOI, an arXiv id, a year, a title and a first author are found in the entry or not at all. Nothing is read by a model.

Contents

Install

go get github.com/sebastienrousseau/draft@latest
import (
	"github.com/sebastienrousseau/draft/refs"
	"github.com/sebastienrousseau/draft/refs/resolve"
)

Quick start

list := refs.Parse(`Lu, C., Lange, R. (2024). The AI scientist. arXiv:2408.06292.
Yamada, Y. (2025). The AI scientist v2. arXiv:2504.08066.`, "paper.pdf")

// The IDs of the entries a quote's markers name.
ids := refs.Cited("v1 (Lu et al., 2024) drafted papers", list)

// Whether an entry names a real work: no lookups, no network, no answer.
r := &resolve.Resolver{Lookups: []resolve.Lookup{
	&resolve.ArXiv{Fetcher: &resolve.Fetcher{UserAgent: "my-tool/1.0"}},
}}
res := r.Resolve(ctx, list[0]) // res.Status is "resolved", res.Work the record

API

Symbol Purpose
Reference One entry: ID, Raw, Source, Label, Key, FirstAuthor, Title, Year, DOI, ArXiv, URL
Parse Reads numbered, labelled, author-year, bullet and \bibitem lists into entries
EntryID An entry's id: r and ten hex digits of the SHA-256 of its normalised text
Markers The citation markers in a text: [3, 7-9], \cite{a,b}, (Lu et al., 2024), Lu et al. (2024)
Cited The IDs of the entries a text's markers name; a marker that names none, or several, links nothing
FromBibTeX BibTeX entries as references
bibtex.Parse Reads a .bib file: entries, fields, @string, @comment, @preamble, braced and quoted values, #
resolve.Resolver Runs lookups in order until one decides
resolve.Match The fixed rule deciding whether a work is the entry
resolve.Crossref Lookup by DOI, else by the entry's text, in Crossref's public API
resolve.ArXiv Lookup by arXiv id in arXiv's public API
resolve.BibFile Lookup in BibTeX records the user vouches for, without the network
resolve.Fetcher HTTP with a per-source rate, bounded retries that honour Retry-After, a response cache and size limits
resolve.OpenAlex Lookup by DOI, else by title, in OpenAlex: abstracts and open-access PDFs, no key
resolve.SemanticScholar Lookup by DOI, arXiv id or title; its API key goes in a header, never a URL or log
resolve.Zotero A local Zotero library as records, read with sqlite3; stored PDFs are full texts
Complete Fills an entry's missing fields from another reader, keeping only stretches of it
support.Decide Whether a model's quote from a cited work verifies and carries the citing claim
support.Passages The passages of a cited work most relevant to a claim, by BM25, never joined

Resolution

Match never trusts a source's ranking. A work is the entry when:

  • its DOI or arXiv id is the entry's and its first author is the entry's or its title is in the entry; or
  • the entry's year is within one of the work's, its first author is the work's, and 85% of the work's title words are in the entry (or the title, squashed of spaces and punctuation, is in the squashed entry), or the work's volume and first page are.

One match resolves, two are ambiguous, none is not_found. A lookup that could not be asked makes the reference unavailable, and no lookups at all leave it offline_unchecked: neither is ever taken as valid or invented. A real DOI attached to the wrong paper does not resolve.

Support

A resolved reference names a real work; refs/support decides whether the work says what the citing claim says. A model proposes a quote from the work, and the citation is supported only when the quote is found within one passage and carries every number the claim states (claims.Verify). Each verdict records the tier of text read: only a full_text that fails makes a citation unsupported; an abstract that fails leaves it unconfirmed, and no text leaves it unchecked.

Parse, Markers, bibtex.Parse and support.Decide are fuzzed, and refs, refs/bibtex, refs/resolve and refs/support are held to 100% mutation efficacy by make mutation.

License

Licensed under either of Apache License 2.0 or MIT License, at your option. © Sebastien Rousseau.

Back to top ↑

Documentation

Overview

Package refs reads a source's reference list into records a citation can point at, and the citation markers in a quote into the records they name.

Every field is read from the entry's own text by a fixed rule, never by a model, and every field is a stretch of that text: a DOI, an arXiv id, a year, a title and a first author are found in Raw or not at all. That is the quote gate's principle applied to references. Whether a reference exists is a separate question, answered by a resolver (refs/resolve).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cited

func Cited(text string, list []Reference) []string

Cited is the IDs of the references the markers in text name, in order and without repeats. A marker that names no reference, or more than one for one author-year pair, links nothing: a citation is either certain or it is left out.

func EntryID

func EntryID(raw string) string

EntryID names a reference entry by its text.

func Incomplete added in v0.0.55

func Incomplete(ref Reference) bool

Incomplete reports whether ref lacks a field resolution reads.

func StripMarkers added in v0.0.55

func StripMarkers(text string) string

StripMarkers is text without its citation markers, and without the space each leaves before punctuation: "Routing helps (Lu et al., 2024)." is "Routing helps.".

Types

type AuthorYear

type AuthorYear struct {
	Author string
	Year   int
	// Letter is "a" in "Lu et al., 2025a"; empty when there is none.
	Letter string
}

AuthorYear is one author-year citation: "Lu et al., 2024" is {Lu, 2024}.

type Marker

type Marker struct {
	Text   string
	Labels []string
	Keys   []string
	Cites  []AuthorYear
}

Marker is one in-text citation: the text that makes it and the entries it names, as labels, keys or author-year pairs.

func Markers

func Markers(text string) []Marker

Markers finds the citation markers in a stretch of text, in order.

func (Marker) Entries added in v0.0.56

func (m Marker) Entries(list []Reference) []Reference

Entries is the references m names in list, each part of it resolved to the one entry that matches.

func (Marker) Unresolved added in v0.0.56

func (m Marker) Unresolved(list []Reference) []string

Unresolved is the parts of m that name no single entry of list: a label, key or author-year citation that matches none of them, or several. A citation naming nothing is the commonest sign of a reference list edited after the text, or a citation made up.

type Reference

type Reference struct {
	// ID is "r" and the first ten hex digits of the SHA-256 of the
	// normalised entry, so the same entry is named the same way in every
	// run and anyone holding the entry can recompute it.
	ID string `json:"id"`
	// Raw is the entry as the list gives it, line breaks folded to spaces.
	Raw string `json:"raw"`
	// Source names the file the list came from.
	Source string `json:"source"`
	// Label is the entry's marker without its brackets: "12" for "[12]"
	// or "12.", "AJMV98" for "[AJMV98]", "" in an author-year list.
	Label string `json:"label,omitempty"`
	// Key is the BibTeX or \bibitem key, when the list comes from LaTeX.
	Key string `json:"key,omitempty"`
	// FirstAuthor is the first author's surname, or the first words of a
	// corporate author.
	FirstAuthor string `json:"first_author,omitempty"`
	Title       string `json:"title,omitempty"`
	// Year is the year of publication, 0 when none is found.
	Year int `json:"year,omitempty"`
	// YearLetter tells one author's works of a year apart: "a" in
	// "2025a". Empty when the list gives none.
	YearLetter string `json:"year_letter,omitempty"`
	DOI        string `json:"doi,omitempty"`
	ArXiv      string `json:"arxiv,omitempty"`
	URL        string `json:"url,omitempty"`
	// Abstract and File come from a BibTeX entry's abstract and file
	// fields: what the user's own library holds of the work. They are not
	// part of the entry's identity, and are not stored.
	Abstract string `json:"-"`
	File     string `json:"-"`
}

Reference is one entry of a source's reference list.

func Complete added in v0.0.55

func Complete(ref Reference, firstAuthor, title, year string) Reference

Complete fills the fields ref lacks from fields another reader proposed, as a model reading the entry does. A field is kept only when it is a stretch of the entry's own text: a title or first author found in Raw, a year written in it. A field ref already has is never replaced, so the fixed rules decide wherever they can.

func FromBibTeX

func FromBibTeX(entries []bibtex.Entry, source string) []Reference

FromBibTeX reads BibTeX entries as references. Raw is the entry written out as a plain citation ("Author. Title. Venue, Year."), so it names the entry the way a reference list would and its ID is stable however the file is formatted.

func Parse

func Parse(list, source string) []Reference

Parse reads a reference list into references, in list order. It reads numbered lists ("[12]", "12."), labelled lists ("[AJMV98]"), author-year lists, Markdown bullet lists and \bibitem lists. An entry that carries no year and no identifier is still returned: a resolver may find it by its title, and leaving it out would hide it from the run summary.

Directories

Path Synopsis
Package bibtex reads BibTeX files: the entries, their keys and their fields, as written.
Package bibtex reads BibTeX files: the entries, their keys and their fields, as written.
Package resolve finds out whether a reference names a real work, and which.
Package resolve finds out whether a reference names a real work, and which.
Package support decides whether a cited work says what the citing claim says it does.
Package support decides whether a cited work says what the citing claim says it does.

Jump to

Keyboard shortcuts

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