universe

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package universe reads the universe register of spec 18.3 and counts the outcomes of each scope.

The universe is the set of all source items of programming knowledge. Each card of cards/ and each node of nodes/ is a universe item with the outcome card or node, so the register does not repeat them. The files registers/universe/<source>.jsonl hold the other rows: the items that are aliases, sections, merged, on another site, out of scope, not an item, or still pending.

Index

Constants

This section is empty.

Variables

View Source
var Outcomes = []string{"node", "card", "alias", "section", "merged", "disambiguation", "elsewhere:algorithm", "elsewhere:math2", "out-of-scope", "not-an-item", "pending"}

Outcomes are the outcomes of spec 18.3. The outcomes node and card come from nodes and cards, but a row may also use them to record a source name that maps to a node or card with another id.

View Source
var Reasons = []string{"not-programming", "product-marketing", "personal", "too-small"}

Reasons are the reason codes of the outcome out-of-scope.

View Source
var Scopes = []string{"languages", "releases", "concepts", "features", "api", "diagnostics", "proposals", "tasks", "patterns", "weaknesses", "tools", "libraries", "formats", "licences", "people", "terms"}

Scopes are the scopes of spec 18.4.

Functions

func Gate

func Gate(counts []Count, max float64, strict []string) error

Gate tells if the counts meet the exit criteria of M1 (spec 21): less than max of all items pending, and no pending item in the strict scopes. It returns the reasons when they are not met.

func ReadRules

func ReadRules(root string) (map[string]ScopeRule, error)

ReadRules reads registers/scope-rules.yaml. A missing file gives no rules.

func ScopeOfKind

func ScopeOfKind(kind string) string

ScopeOfKind returns the scope of the nodes and cards of a kind, or "" for a kind that is not a universe item, such as area.

func Targeted

func Targeted(outcome string) bool

Targeted tells if an outcome needs a target that is a node or a card of this site.

Types

type Count

type Count struct {
	Scope     string         `json:"scope"`
	Total     int            `json:"total"`
	Pending   int            `json:"pending"`
	ByOutcome map[string]int `json:"by_outcome"`
}

Count holds the outcomes of one scope.

func Report

func Report(c *node.Corpus, rows []Row) []Count

Report counts the items of each scope: the nodes and cards of c by kind, and the rows. A row with the outcome node or card that points to a node or card is not counted again. The last Count has the scope "all".

func (Count) Share

func (n Count) Share() float64

Share is the part of the items of the scope that is pending, from 0 to 1.

type Problem

type Problem struct {
	Rule string
	Msg  string
}

Problem is one problem of a row, with the check rule that finds it.

func Problems

func Problems(c *node.Corpus, rules map[string]ScopeRule, r Row) []Problem

Problems returns the problems of one row: U01 for an unknown scope or outcome, U02 for a missing reason or target, U03 for a target that is not a node or card of c, and U04 for a reason too-small without a rule of rules.

type Row

type Row struct {
	// Source is the id of the source, such as pldb or cwe. An empty source takes the name of the file.
	Source string `json:"source,omitempty"`
	// ID is the id of the item in the source, and Name is the name that the source gives it.
	ID   string `json:"id"`
	Name string `json:"name,omitempty"`
	// Scope is one of Scopes.
	Scope string `json:"scope"`
	// Outcome is one of Outcomes.
	Outcome string `json:"outcome"`
	// Target is the slug of the node or card that the row points to, or the tag on the other site for elsewhere outcomes.
	Target string `json:"target,omitempty"`
	// Reason says why the row has its outcome. Out of scope needs a reason code.
	Reason string `json:"reason,omitempty"`
	// Rule is the id of the rule of registers/scope-rules.yaml for the reason too-small.
	Rule string `json:"rule,omitempty"`

	File string `json:"-"`
	Line int    `json:"-"`
}

Row is one row of registers/universe/<source>.jsonl.

func Read

func Read(root string) ([]Row, []error)

Read reads every registers/universe/*.jsonl file under root. A missing directory gives no rows. Errors are the rows that cannot be read.

type ScopeRule

type ScopeRule struct {
	ID    string `yaml:"id"`
	Scope string `yaml:"scope"`
	Rule  string `yaml:"rule"`
}

ScopeRule is one rule of registers/scope-rules.yaml. A row with the reason too-small names the id of a rule, so that a person approves the rule and not each row.

Jump to

Keyboard shortcuts

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