\Drupal\strata\Codec\Dictionary DictionaryPass

Trains each realm's dictionary from what that realm has actually been writing.

Samples come from the operations already in the store rather than from a fixture, because a dictionary is only worth anything if it looks like the next frame. A site whose nodes all carry the same twelve fields gets a dictionary full of those field names; a site with one node type gets a different one, and neither is guessable in advance.

Runs on cron and by hand, never on a flush. Building a candidate compresses the samples twice and the winner is scored against a held-out slice, so a pass costs seconds - fine on a schedule, impossible inside a web request.

A realm gets a new version only when one measures better than what it has. Retraining for the sake of it would add a version, strand nothing, and cost every new frame the same ratio, so the gain is measured against the realm's current dictionary before anything is written.

Summary

Methods
Properties
Constants
__construct
run
trainRealm
collect
realms
No public properties found
SEGMENT_LIMIT
SAMPLE_LIMIT
MIN_GAIN
No protected methods found
No protected properties found
No protected constants found
payloadOf
isSatisfied
trainer
store
objects
segments
commits
refs
logger
No private constants found

Constant

SEGMENT_LIMIT

SEGMENT_LIMIT = 200

Segments read to collect samples.

A bound on the pass rather than a policy: the newest segments describe what the site is writing now, and reading further back trains against a shape the site has moved on from.

SAMPLE_LIMIT

SAMPLE_LIMIT = 400

Most samples collected per realm.

MIN_GAIN

MIN_GAIN = 0.05

How much better a candidate has to be before it becomes a new version.

Five per cent. Below that the new version costs a fetch and a cache entry for nothing.

Properties

$trainer

$trainer : \Drupal\strata\Codec\Dictionary\DictionaryTrainer

Type

DictionaryTrainer

$store

$store : \Drupal\strata\Codec\Dictionary\DictionaryStore

Type

DictionaryStore

$objects

$objects : \Drupal\strata\Cas\ObjectStore

Type

ObjectStore

$segments

$segments : \Drupal\strata\Segment\SegmentReader

Type

SegmentReader

$commits

$commits : \Drupal\strata\Tree\CommitLog

Type

CommitLog

$refs

$refs : \Drupal\strata\Tree\RefStore

Type

RefStore

$logger

$logger : \Psr\Log\LoggerInterface

Type

LoggerInterface

Methods

__construct()

__construct(\Drupal\strata\Codec\Dictionary\DictionaryTrainer  $trainer, \Drupal\strata\Codec\Dictionary\DictionaryStore  $store, \Drupal\strata\Cas\ObjectStore  $objects, \Drupal\strata\Segment\SegmentReader  $segments, \Drupal\strata\Tree\CommitLog  $commits, \Drupal\strata\Tree\RefStore  $refs, \Psr\Log\LoggerInterface  $logger) : mixed

Constructs a pass.

Parameters

\Drupal\strata\Codec\Dictionary\DictionaryTrainer $trainer

Builds and scores the candidates.

\Drupal\strata\Codec\Dictionary\DictionaryStore $store

Where a winning dictionary is stored.

\Drupal\strata\Cas\ObjectStore $objects

Fetches the payload frames samples are taken from.

\Drupal\strata\Segment\SegmentReader $segments

Reads the segment manifests that name them.

\Drupal\strata\Tree\CommitLog $commits

Walks history to find the segments.

\Drupal\strata\Tree\RefStore $refs

Resolves the ref to walk from.

\Psr\Log\LoggerInterface $logger

Records what a pass did.

Returns

mixed —

run()

run(string  $ref = \Drupal\strata\Tree\RefStore::MAIN) : array<string,array{stored: bool, reason: string, ratio: float, source: string}>

Trains every realm that has enough recent data.

Parameters

string $ref

Ref to collect samples from.

Returns

array

Realm value keyed to what happened, so a command can print a line per realm rather than one number for the run.

trainRealm()

trainRealm(string  $realm, list  $samples) : array{stored: bool, reason: string, ratio: float, source: string}

Trains one realm.

Parameters

string $realm

Realm value.

list $samples

Payloads from that realm.

Returns

array{stored: bool, reason: string, ratio: float, source: string} —

What happened.

collect()

collect(string  $ref = \Drupal\strata\Tree\RefStore::MAIN) : array<string,list<string>>

Payload samples per realm, newest first.

Parameters

string $ref

Ref to walk.

Returns

array> —

Realm value keyed to payloads.

realms()

realms() : list<string>

Every realm that could carry a dictionary.

Returns

list

Realm values.

payloadOf()

payloadOf(list  $frames) : string|null

One operation's payload, reassembled from its frames.

Parameters

list $frames

Frame addresses.

Returns

string|null —

The payload, or NULL when any frame could not be read.

isSatisfied()

isSatisfied(array>  $samples) : bool

Whether every realm seen so far has all the samples it can use.

Parameters

array> $samples

What has been collected.

Returns

bool —

TRUE when nothing more can be added.