Documentation
¶
Overview ¶
Package validate enforces the house article rules before a draft is saved: required structure, length, banned vocabulary, emoji, truncation, and faithfulness to the verified claim ledger.
Index ¶
- func ContainsEmoji(s string) bool
- func DuplicateParagraphIndexes(article string) []int
- func EndsSentence(tail string) bool
- func Errors(md string) []string
- func ErrorsWithStyle(md string, style rules.Style) []string
- func Faithfulness(article string, records []claims.Record) (errs, warnings []string)
- func FaithfulnessWithOptions(article string, records []claims.Record, opts Options) (errs, warnings []string)
- func LimitationCounts(article string, given []claims.Record) (total, kept int)
- func LimitationRetention(article string, given []claims.Record) (errs, warnings []string)
- func LooksLikeArticle(s string) bool
- func Paragraphs(article string) []string
- func UnsafeMarkup(md string) []string
- func WordCount(s string) int
- type Options
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsEmoji ¶
ContainsEmoji reports whether s contains a pictographic or symbol emoji.
func DuplicateParagraphIndexes ¶
DuplicateParagraphIndexes returns the indexes, within Paragraphs(article), of paragraphs that nearly duplicate an earlier one. Headings and short paragraphs are never reported: a repeated heading is structure, and short runs of shared words are not evidence of duplication.
func EndsSentence ¶
EndsSentence reports whether the trailing text closes on sentence-ending punctuation. It decodes the final rune (not the final byte) so multibyte closers — smart quotes, apostrophe, ellipsis — are recognised rather than mistaken for a truncated fragment.
func Errors ¶
Errors reports the house-rule violations in a finished body under the default house style. See ErrorsWithStyle for the per-style variant.
Example ¶
package main
import (
"fmt"
"github.com/sebastienrousseau/draft/validate"
)
func main() {
fmt.Println(validate.Errors("not a valid article")[0])
}
Output: body-only mode must start with a Markdown H1
func ErrorsWithStyle ¶
ErrorsWithStyle checks a body against a specific editorial style: the word band and banned vocabulary come from the style, the structural rules do not, because an H1, a lead aside, an executive summary and section headings are the shape of a grounded article rather than a matter of taste.
The default style takes the fast path — a package-level regex compiled once — so the common case pays nothing for the configurability. A custom style compiles its banned-word matcher on demand.
func Faithfulness ¶
Faithfulness cross-checks a draft against the verified claim ledger with the default policy. Hard errors (returned first) block a save; warnings are advisory.
func FaithfulnessWithOptions ¶
func FaithfulnessWithOptions(article string, records []claims.Record, opts Options) (errs, warnings []string)
FaithfulnessWithOptions is Faithfulness with an explicit policy.
func LimitationCounts ¶ added in v0.0.52
LimitationCounts is how many limitations the writer was given and how many the draft carries, for the provenance record.
func LimitationRetention ¶ added in v0.0.52
LimitationRetention checks that the draft carries the limitations its writer was given: given is the ledger the writing prompt held (see claims.SelectForPrompt), not the whole extraction. A draft that keeps none of them is an error; each one dropped is a warning.
"Carries" means what --verify reports: an article sentence attributed to the claim by provenance.Attribute. The floor is one, not all, because the measured rate is far below all: thirteen published articles carried 103 of the 310 limitations their ledgers held, and a writer given a long ledger cannot fit every caveat into one article. A draft with none, though, is presenting a source's results without the limits the source states.
func LooksLikeArticle ¶
LooksLikeArticle reports whether s resembles a Markdown article body, used to decide whether a failed draft is still worth saving for manual review.
func Paragraphs ¶
Paragraphs splits an article on blank lines, the unit the duplicate check works in. Exported so a repair pass can address the same paragraphs the check complains about, rather than re-deriving the split and drifting.
func UnsafeMarkup ¶ added in v0.0.49
UnsafeMarkup lists the constructs in md that would run script or load foreign content once a Markdown site renders it: dangerous elements, event handler attributes (in HTML or a kramdown attribute list), and javascript:, vbscript: or data: URLs in a link, image, reference definition, autolink or URL attribute. Each kind is listed once, in the order first found, so a caller can compare two drafts. An empty result means none was found.
Code spans and fences are not exempt. A renderer escapes them, but the article's text also feeds frontmatter and excerpts that strip the backticks, and an article that needs a live payload in code is not one draft writes.
func WordCount ¶
WordCount counts the words of prose a reader sees: whitespace-separated tokens that contain a letter or a digit, after HTML comments, tags and link targets are removed. "3,000", "FCA's" and "AI-driven" are one word each, and a lone "##" or dash is none. Splitting at every non-letter instead counted numbers, contractions, hyphenations and the lead aside's attributes as extra words, and put real drafts up to 171 words over their prose length.
Types ¶
type Options ¶
type Options struct {
// StrictNumbers makes a number that appears in the article and in no
// claim block the save instead of merely warning.
//
// A fabricated number is the clearest possible sign of invention, and for
// a tool whose promise is that every sentence is grounded, letting one
// reach disk with a line on stderr is hard to defend. It is opt-in for
// one release because the naive check is noisy — see ungroundedNumbers —
// so the real false-positive rate can be measured on a corpus before it
// becomes the default.
StrictNumbers bool
// StrictQuotes makes a quotation that no verified source quote contains
// block the save instead of merely warning. See unsourcedQuotations.
StrictQuotes bool
}
Options tunes the checks whose strictness is a policy choice rather than a correctness one.