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 ¶
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.
Types ¶
type Document ¶
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 ¶
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 ¶
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.