lpgcast.validate¶
Validate a reply against the slice it was asked for.
Complete on purpose: graflo's writer silently drops an edge whose key no edge declares and a vertex with no identity value, which is right for a writer and wrong for an extraction. Every such case is a finding here.
Deterministic fixes run first and are recorded: values are coerced to their field type (declared units stripped), an edge given in the reverse of its declared direction is flipped, and quotes are matched ignoring case and whitespace runs. A property's quote is read nearest its owner's. An identity value the text refers to but only the episode's context states is grounded there. A number written as digits, or a date, must be what its quote states. What remains are findings, each naming the item it removes. An item with a finding is left out; the rest of the reply stands.
Attributes¶
CONSEQUENTIAL = frozenset({'endpoint_invalid'})
module-attribute
¶
FINDING_ORDER = ('unknown_type', 'duplicate_ref', 'identity_insufficient', 'undeclared_edge', 'dangling_ref', 'undeclared_property', 'duplicate_property', 'coercion', 'value_not_in_quote', 'quote_not_found', 'endpoint_invalid')
module-attribute
¶
FindingKind = Literal['duplicate_ref', 'unknown_type', 'undeclared_property', 'duplicate_property', 'coercion', 'value_not_in_quote', 'quote_not_found', 'identity_insufficient', 'dangling_ref', 'undeclared_edge', 'endpoint_invalid']
module-attribute
¶
Scope = Literal['vertex', 'edge', 'property']
module-attribute
¶
Classes¶
Finding
¶
Bases: BaseModel
A defect in a reply, and the item it removes.
Source code in lpgcast/validate.py
Attributes¶
detail = Field(default=None, description='Sub-kind, e.g. the coercion kind.')
class-attribute
instance-attribute
¶
fragment = Field(description='The offending item as the model wrote it.')
class-attribute
instance-attribute
¶
kind
instance-attribute
¶
message
instance-attribute
¶
path = Field(description='Location in the reply, e.g. ``vertices[1].props[0]``.')
class-attribute
instance-attribute
¶
ref = Field(default=None, description='Vertex ref involved, if any.')
class-attribute
instance-attribute
¶
scope = Field(description='What is left out: a vertex, an edge or one property.')
class-attribute
instance-attribute
¶
Fix
¶
Bases: BaseModel
A deterministic correction applied without asking the model.
Source code in lpgcast/validate.py
ValidEdge
¶
Bases: BaseModel
An edge that passed, oriented as declared.
Source code in lpgcast/validate.py
ValidUnmapped
¶
Bases: BaseModel
An unmapped entry, located in the text when its quote is found.
Source code in lpgcast/validate.py
ValidVertex
¶
Bases: BaseModel
A vertex that passed, with coerced properties and spans.
Source code in lpgcast/validate.py
Validation
¶
Bases: BaseModel
The checked reply.
Source code in lpgcast/validate.py
Attributes¶
edges = Field(default_factory=list)
class-attribute
instance-attribute
¶
findings = Field(default_factory=list)
class-attribute
instance-attribute
¶
fixes = Field(default_factory=list)
class-attribute
instance-attribute
¶
kept
property
¶
Items kept: vertices, edges and properties. Used to pick the best attempt.
repairable
property
¶
Findings worth showing the model: all but consequences of others.
unmapped = Field(default_factory=list)
class-attribute
instance-attribute
¶
vertices = Field(default_factory=list)
class-attribute
instance-attribute
¶
Functions:¶
identity_fields(vertex)
¶
Properties that take part in any identity of vertex.
Source code in lpgcast/validate.py
mention_identity(vertex, props)
¶
How a mention can be looked up: ("identity", fields) when the primary
identity is complete (or its digest computable), else the first secondary
identity whose fields are all present. None when neither.
Source code in lpgcast/validate.py
validate(wire, slice_, text, context=())
¶
Check wire against slice_, the episode text and its context.