UnitGuard

class UnitGuard(units: Map<String, MeasurementUnit> = Vocabulary.UNITS) : MatchGuard

Rejects matches whose prompts mention different units or currencies.

Convert 50 km to miles and Convert 50 km to meters share their number, share four of five words, and embed almost identically — NumericGuard sees nothing wrong and word overlap is high enough to pass any sane lexical check. The only thing that differs is the unit, so that is what this guard reads.

Comparison is by set, not by sequence: "convert 50 km to miles" and "how many miles is 50 km" mention the same two units and mean the same thing. Direction swaps like EUR to USD against USD to EUR are DirectionGuard's job.

Like EntityGuard, it rejects a substitution and not an addition. Each prompt must name a unit the other does not, so "375 f to c" still matches "What is 375 degrees Fahrenheit in Celsius?" — one of them simply spells the units out.

Units are compared by their canonical name, so km and kilometers are one unit rather than a swap. See Vocabulary.UNITS.

Constructors

Link copied to clipboard
constructor(units: Map<String, MeasurementUnit> = Vocabulary.UNITS)

Properties

Link copied to clipboard
open override val name: String

Short stable identifier, surfaced in dev.kmemo.CacheLookup.Miss.detail.

Functions

Link copied to clipboard
open override fun evaluate(query: String, candidate: String): GuardVerdict

Judges serving the response cached for candidate in answer to query.