entitytext

package
v0.1.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package entitytext says which of an entity's values are its text, for every component that reads text from the graph: graph-embedding embeds it, and a word index splits it into a name and a body. It also reads an entity's offloaded body from its store, under a deadline. It imports no NATS client: a store is reached only through the storage interfaces.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoStore = errors.New("entitytext: no store is registered for the storage instance")

ErrNoStore says no store is registered under a body's storage instance. A missing object is storage.ErrObjectNotFound; any other failure wraps neither.

Functions

func DefaultSuffixes

func DefaultSuffixes() []string

DefaultSuffixes returns the predicate suffixes a Rule uses when it is given none.

func ReadBody

func ReadBody(ctx context.Context, stores Stores, ref message.StorageReference, maxLen int) (string, error)

ReadBody reads the offloaded body ref points to from the store registered under its instance, and no other, reading at most enough bytes to hold maxLen characters; the caller cuts it to the cap. The read runs under a context derived from ctx that ends 10 seconds after it begins.

When the store fails and that context has ended by then, the error wraps the context's error, context.DeadlineExceeded for the deadline, whatever the store's error was: a store may answer its deadline with an error of its own that wraps no context error. A body the store returns whole is used even if the context ended meanwhile. A store that ignores its context is not bounded by the deadline. A nil ctx is refused before any store is asked.

func Truncate

func Truncate(text string, maxLen int) string

Truncate cuts text to at most maxLen characters (runes), preferring the last Unicode whitespace boundary in the back half of the cap. It never splits a multibyte rune, so the result is valid UTF-8. A maxLen of 0 or less returns text unchanged.

Types

type Document

type Document struct {
	Name string
	Body string
	Cut  bool
}

Document is an entity's text split in two. Name holds the values that name the entity; Body holds the rest, then the offloaded body. Cut reports that Body was cut at the rule's cap.

type Rule

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

Rule says which of an entity's values are its text. A value is text when it is a non-empty string, is not a relationship, and its predicate, lower-cased, ends in one of the rule's suffixes. The zero Rule selects nothing; build one with New.

func New

func New(suffixes []string, maxLen int) Rule

New returns the rule for suffixes, or DefaultSuffixes when suffixes is empty. maxLen is the most characters Document's Body holds; 0 or less means no cap. The vocabulary's label predicates are read once, here, as the name index reads them, so a product registers its own before it builds the components that read text.

func (Rule) Document

func (r Rule) Document(state *graph.EntityState, body string) Document

Document splits the entity's text into a name and a body. Name is every string value of a vocabulary label predicate, whatever its suffix, and every text value whose predicate ends in .name or .title, each value once and in triple order. Body is every other text value in triple order, then body, the entity's offloaded body ("" for none), joined as WithBody joins it. The cap cuts Body's tail as Truncate does and never cuts Name.

func (Rule) Values

func (r Rule) Values(state *graph.EntityState) []string

Values returns the entity's text values in triple order, one for each text triple.

func (Rule) WithBody

func (r Rule) WithBody(doc Document, body string) Document

WithBody returns doc, a Document this rule made with no offloaded body, with body joined to it as Document joins one: after the other body text, a space between, the whole cut at the rule's cap. A caller that reads the body later keeps doc and not the entity. A doc already cut is returned as it is: the cap falls inside its body text, so body would only follow the cut.

type Stores

type Stores interface {
	Streamable(instance string) (storage.StreamableStore, bool)
}

Stores finds the store registered under a storage instance; *storeregistry.Registry is one. The store is borrowed for one read, never kept or closed.

Jump to

Keyboard shortcuts

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