Add paperspec correct, check math forms and datasets, and give the tools public names
The work the other paper tools planned for paperspec (paperdesk PLAN M5.4, paperform PLAN 4.2): - paperspec correct and paperspec.revision apply proposed corrections to a package, folder or zip, and write it only once it validates. - doc.math.form is checked: label and style commands always, the form's own spelling when papermath is installed or forms= is passed. - paperspec.datasets and seven doc.dataset.* rules check a package's datasets. - fixtures/invalid gains suspect-witness and math-form-label (33 in all). - Canonical JSON reads numbers as doubles, so 1e20 round-trips. - The registries and the JSON-LD context ship in the wheel. - Public names for what paperdesk and paperform imported as private ones, with the old names kept as aliases. - The text and lossy-projection functions are about three times faster through the gate, tested equal to the old code on every code point. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013XwDhn4LkrKQfw4ArDEr2E
This commit is contained in:
70 files changed
+4470
-270
No files matched your search
@@ -692,3 +692,66 @@ class TestMetaHash:
|
||||
other = dict(self.DOCUMENT, policy="withheld", key="another")
|
||||
assert meta_hash(other) == meta_hash(self.DOCUMENT)
|
||||
assert meta_hash(dict(self.DOCUMENT, language="fr")) != meta_hash(self.DOCUMENT)
|
||||
|
||||
|
||||
def _lossy_by_hand(s):
|
||||
"""The lossy projection of a strict projection, character by character (spec/05 §5.5)."""
|
||||
out, stack, i, n = [], [], 0, len(s)
|
||||
while i < n:
|
||||
ch = s[i]
|
||||
if ch in "_^" and i + 1 < n and s[i + 1] == "{":
|
||||
stack.append("s")
|
||||
i += 2
|
||||
continue
|
||||
if ch == "{":
|
||||
stack.append("t")
|
||||
out.append(ch)
|
||||
elif ch == "}":
|
||||
if not stack or stack.pop() == "t":
|
||||
out.append(ch)
|
||||
elif ch == hashing.MARK_OPEN:
|
||||
j = s.find(hashing.MARK_CLOSE, i)
|
||||
i = n if j < 0 else j + 1
|
||||
continue
|
||||
else:
|
||||
out.append(ch)
|
||||
i += 1
|
||||
t = unicodedata.normalize("NFKC", "".join(out).casefold())
|
||||
return "".join(
|
||||
c for c in t if not is_ws(c) and unicodedata.category(c) != "Pd" and c != ""
|
||||
)
|
||||
|
||||
|
||||
LOSSY_ALPHABET = [
|
||||
"_",
|
||||
"^",
|
||||
"{",
|
||||
"}",
|
||||
hashing.MARK_OPEN,
|
||||
hashing.MARK_CLOSE,
|
||||
hashing.OBJ,
|
||||
"a",
|
||||
"B",
|
||||
"\u00df", # sharp s, which case folding expands
|
||||
"\u00ad", # soft hyphen
|
||||
"-",
|
||||
"\u2013", # en dash
|
||||
"\u2212", # minus sign
|
||||
" ",
|
||||
"\u00a0", # no-break space
|
||||
"\u2009", # thin space
|
||||
"\ufb01", # the fi ligature, which NFKC expands
|
||||
"\u00b2", # superscript two
|
||||
"1",
|
||||
]
|
||||
|
||||
|
||||
@given(st.text(alphabet=st.sampled_from(LOSSY_ALPHABET), max_size=40))
|
||||
@settings(derandomize=True, max_examples=500, database=None, deadline=None)
|
||||
def test_the_lossy_projection_matches_its_character_by_character_definition(s):
|
||||
assert hashing.lossy_from_strict(s) == _lossy_by_hand(s)
|
||||
|
||||
|
||||
def test_the_lossy_projection_drops_every_dash_and_white_space_character():
|
||||
every = "".join(chr(c) for c in range(0x110000) if not 0xD800 <= c <= 0xDFFF)
|
||||
assert hashing.lossy_from_strict(every) == _lossy_by_hand(every)
|
||||
Reference in new issue
Block a user