diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d0fb6ee..b6a3e6c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)). diff --git a/docs/docs/Guides/Comparators/postal-codes.md b/docs/docs/Guides/Comparators/postal-codes.md index d0480aaf..b38a53ed 100644 --- a/docs/docs/Guides/Comparators/postal-codes.md +++ b/docs/docs/Guides/Comparators/postal-codes.md @@ -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` @@ -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 @@ -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 @@ -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