Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Each release links to full notes on the
ignored, so `**True**.` scores 1.0 and `"false"` scores 0.0. Any other reply
scores 0.0 and warns, showing the start of the reply, rather than raising.

- The Postal Codes guide now says postal codes are compared exactly only when
`stickler.evaluate` gets a plain Pydantic `BaseModel`, and by edit distance on
a `StructuredModel` field without a comparator (even one passed to
`stickler.evaluate`) or a JSON Schema `string`
([#492](https://github.com/awslabs/stickler/issues/492)).

- Corrected introductory example scores, the default text comparator description,
and the sample amount in the documentation and README
([#478](https://github.com/awslabs/stickler/issues/478)).
Expand Down
23 changes: 17 additions & 6 deletions docs/docs/Guides/Comparators/postal-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ title: Postal Codes and Addresses

# Postal Codes and Addresses

Stickler compares postal codes **exactly**. `"98101-1234"` does not match
`"98101 1234"`, and `"98101"` does not match `"98101-1234"`.

That is deliberate, and it is probably not what you want for your data. This
page explains why the library refuses to guess, and how to get the behaviour
your country and pipeline need.
With `stickler.evaluate` on a plain Pydantic `BaseModel`, a field named `zip`,
`zip_code`, `postal_code`, `postcode` or `postal` is compared **exactly**:
`"98101-1234"` does not match `"98101 1234"`, and `"98101"` does not match
`"98101-1234"`. On a `StructuredModel`, even one passed to `stickler.evaluate`,
a field without a comparator is compared by edit distance, and so is a JSON
Schema `string`: `"98101-1234"` matches `"98102-1234"`, a different code.
Either way, name a comparator for your country.

The exact match is deliberate, and it is probably not what you want for your
data. This page explains why the library refuses to guess, and how to get the
behaviour your country and pipeline need.

## Why there is no `PostalCodeComparator`

Expand Down Expand Up @@ -62,6 +67,8 @@ class USZipComparator(BaseComparator):
collapsing them hides a real difference in what was extracted.
"""

DEFAULT_THRESHOLD = 1.0

def _compare(self, gt, pred) -> float:
return 1.0 if self._canonical(gt) == self._canonical(pred) else 0.0

Expand All @@ -80,6 +87,8 @@ class UKPostcodeComparator(BaseComparator):
the structural split survives.
"""

DEFAULT_THRESHOLD = 1.0

def _compare(self, gt, pred) -> float:
return 1.0 if self._canonical(gt) == self._canonical(pred) else 0.0

Expand Down Expand Up @@ -124,6 +133,8 @@ from stickler import BaseComparator
class ZipLookupComparator(BaseComparator):
"""Compare US ZIPs by the 5-digit code they resolve to."""

DEFAULT_THRESHOLD = 1.0

def _compare(self, gt, pred) -> float:
return 1.0 if self._resolve(gt) == self._resolve(pred) else 0.0

Expand Down
Loading