# QUOTATION-v1

Quotation rule version 1 of this record: how a passage typed into the
quotation verifier, and the retained text it is checked against, are both
read as words, with test vectors. The rule changes no observation and no
digest.

The retained text is the text whose SHA-256 is an observation's
`content_hash`: the record's own normalisation has already reduced it, as the
NORMALISATION documents beside this one state with their own vectors. A typed
passage is reduced by that same normalisation FIRST (step 0 below), so the
verifier's normalisation is the record's, and this rule then reads both texts
the same way. Steps 1 to 5 fold characters the record's normalisation keeps;
an answer says, for each match, whether it holds without them (exact) or only
with them (normalised).

A change to this rule is a new version with a new document. This document is
never edited in place once published.

The machine-read parts are the fenced `json` blocks. The code that applies
the rule is the client served at /js/verify-quote.js; the build runs those
same bytes over the retained text, and a plant
(`scripts/plants/d/test_quote_verifier.py`) requires every vector below to be
reproduced by that client and by a second, separate reading of this document
and of the record's normalisation code.

## Identity

```json
{
 "block": "identity",
 "quotation_version": 1,
 "window_words": 4,
 "key_bytes": 6,
 "exact_key_bytes": 4,
 "max_input_characters": 2000
}
```

## The rule, in the order it runs

0. **The record's normalisation.** The passage is reduced by the rule values
   of the latest `NORMALISATION-v<N>.md`: each `volatile` pattern replaced in
   order (among them a date after "as of", "printed", "generated",
   "retrieved", "accessed" or "downloaded"; a clock value; a hex run of 32 to
   64 characters; a UUID; a counter; an "ago" time; script, style, nav,
   header, footer and aside elements), then every whitespace run made one
   space, then both ends trimmed. This is the pass the observation writer
   applies to every text it hashes. Its markup-only steps (tags, character
   references) and its per-host exclusions are not applied: a typed passage
   is text and has no host. The index document at /api/v1/verify/quote.json
   carries the values applied, with the version they come from.
1. **Soft hyphens are removed.** U+00AD is read as if absent, so a word it
   stands inside stays one word.
2. **Whitespace is one space.** Every run of the characters listed below is
   read as a single space. The list is fixed here rather than taken from an
   engine's Unicode tables, so every engine reads the same set.
3. **Ligatures are written out.** U+FB00 to U+FB06 are read as the letters
   they join.
4. **Quotation marks are read as the plain mark of their kind.** Single
   curly marks and single angle marks as `'`; double curly marks and double
   angle marks as `"`.
5. **Dashes and hyphens are read as the hyphen-minus** `-`.
6. **Words.** A mark is a character in the mark ranges below. A word is a
   maximal run of characters that are neither whitespace nor marks. What
   stands between two words, after steps 1 to 5, is a **gap**.
7. **Windows.** A window is four consecutive words and the three gaps
   between them, as one string: the FOLDED window. The window's EXACT string
   is the reduced text's own characters from the first character of its
   first word to the last character of its last word, with no step from 1 to
   5 applied. The index holds, for every window of every retained text it
   reads, the first six bytes of the SHA-256 of the folded window's UTF-8
   bytes as its key and the first four bytes of the SHA-256 of the exact
   string beside it.
8. **The checked span** of a typed passage is its first word through its
   last word. Characters before its first word and after its last word are
   outside every window and are not part of the check.
9. **Exact and normalised.** A match is a chain of windows held by one
   version at consecutive word positions. It is **exact** where every
   window's exact digest is the passage's own, so the reduced passage's
   characters stand in the text from its first word to its last; it is
   **normalised** where the chain holds only by the folded keys.

Letter case is kept. Nothing else is mapped: no other punctuation, no
accent, no number form, no spelling.

A passage of fewer than four words is not checked, because no window can be
formed from it. A passage over 2,000 characters is not checked.

```json
{
 "block": "rule",
 "removed": ["­"],
 "space_ranges": [[9, 13], [32, 32], [133, 133], [160, 160], [5760, 5760], [8192, 8202], [8232, 8233], [8239, 8239], [8287, 8287], [12288, 12288], [65279, 65279]],
 "ligatures": {"ﬀ": "ff", "ﬁ": "fi", "ﬂ": "fl", "ﬃ": "ffi", "ﬄ": "ffl", "ﬅ": "st", "ﬆ": "st"},
 "quotes": {"‘": "'", "’": "'", "‚": "'", "‛": "'", "‹": "'", "›": "'", "“": "\"", "”": "\"", "„": "\"", "‟": "\"", "«": "\"", "»": "\""},
 "dashes": {"‐": "-", "‑": "-", "‒": "-", "–": "-", "—": "-", "―": "-", "−": "-", "﹘": "-", "﹣": "-", "－": "-"},
 "mark_ranges": [[0, 8], [14, 31], [33, 47], [58, 64], [91, 96], [123, 132], [134, 159], [161, 191], [215, 215], [247, 247], [8208, 8231], [8240, 8286], [8722, 8722], [12289, 12291], [12296, 12305], [65112, 65112], [65123, 65123], [65293, 65293]]
}
```

## What the index holds, and what it does not protect

The index holds digests of windows and, beside each, the version it came
from and three byte counts: where the window's first word starts in the
retained text, how far on its second word starts, and how far on its last
word ends. It holds no text. It is not a protection of the text either: a
digest answers any string put to it, so a guessed word can be tested as a
passage can, and an indexed text can be rebuilt from the index by testing
guessed words one window at a time, starting from any four words of it. A
text the record may not quote from is therefore not read into the index at
all: a version is indexed only where the clause-anchor admission
(`scripts/clause_anchors.py`, `admit()`) admitted its text, which refuses a
text whose licence position is not open, a text withheld from retention, a
host with no terms filing or a filing that refuses retention, and a host
reserving text and data mining.

## Vectors

Each vector is an input; the passage as the record's normalisation reduces
it (step 0); its words and gaps; the checked span, exact and normalised; and
the SHA-256 of each folded window and of each exact window, in order.

```json
{
 "block": "vectors",
 "vectors": [
  {
   "input": "The system shall be validated.",
   "reduced": "The system shall be validated.",
   "words": [
    "The",
    "system",
    "shall",
    "be",
    "validated"
   ],
   "gaps": [
    " ",
    " ",
    " ",
    " "
   ],
   "checked": "The system shall be validated",
   "checked_normalised": "The system shall be validated",
   "window_sha256": [
    "57d3e5cef2faaec939abedd32255778f428dc3fd00251c7403d72014f000f863",
    "d267695d5035d6bfa2b22626d3e42269d186b7031ce5a64589e460f499aaf19b"
   ],
   "exact_window_sha256": [
    "57d3e5cef2faaec939abedd32255778f428dc3fd00251c7403d72014f000f863",
    "d267695d5035d6bfa2b22626d3e42269d186b7031ce5a64589e460f499aaf19b"
   ]
  },
  {
   "input": "\u201cRecords should be\u00a0kept\u201d \u2014 in both paper and electronic form.",
   "reduced": "\u201cRecords should be kept\u201d \u2014 in both paper and electronic form.",
   "words": [
    "Records",
    "should",
    "be",
    "kept",
    "in",
    "both",
    "paper",
    "and",
    "electronic",
    "form"
   ],
   "gaps": [
    " ",
    " ",
    " ",
    "\" - ",
    " ",
    " ",
    " ",
    " ",
    " "
   ],
   "checked": "Records should be kept\u201d \u2014 in both paper and electronic form",
   "checked_normalised": "Records should be kept\" - in both paper and electronic form",
   "window_sha256": [
    "558ba7b823d6669ac65ace34723b0135a806411b1a30edce39c851a9c7a60605",
    "284e0426825edc73f6970378bdd805372ec5c4746e9e7cd6a62a3264c33587de",
    "65feaca601c7a4d8db4d1dc4f9a7c287c70a5c28c3199fa20256bb1da650ce8f",
    "3e70ab0c6350a5fe2a9be77b6b6317eebd41aa85637256cb70386004cbfae9f6",
    "fa663e939bbeccf9961febd1240caf296c58eb6c8de70bc69850c5138b7038a8",
    "49c7c5e02d106b5755ed2193b052ea0516f095390a41627c5242294e9bb352d9",
    "b09345713fa90d6af5e0a4bafb0fe981b10ffffc8c4551ec9c5a6479fdb3b741"
   ],
   "exact_window_sha256": [
    "558ba7b823d6669ac65ace34723b0135a806411b1a30edce39c851a9c7a60605",
    "247f15859a0baa0e3a94410c825beffd9217a8576b87ee3ced07f74667cb5554",
    "d4ddbb92aefc58b19e1adc7c10fb003e72acef129471d3eeafe14a6337cbb4b6",
    "61029474f8bed985f64ab8d154d13e4ab2f84d9430eeb651e1fa8255c822d691",
    "fa663e939bbeccf9961febd1240caf296c58eb6c8de70bc69850c5138b7038a8",
    "49c7c5e02d106b5755ed2193b052ea0516f095390a41627c5242294e9bb352d9",
    "b09345713fa90d6af5e0a4bafb0fe981b10ffffc8c4551ec9c5a6479fdb3b741"
   ]
  },
  {
   "input": "This guidance applies as of 3 May 2024 to all computerised systems.",
   "reduced": "This guidance applies to all computerised systems.",
   "words": [
    "This",
    "guidance",
    "applies",
    "to",
    "all",
    "computerised",
    "systems"
   ],
   "gaps": [
    " ",
    " ",
    " ",
    " ",
    " ",
    " "
   ],
   "checked": "This guidance applies to all computerised systems",
   "checked_normalised": "This guidance applies to all computerised systems",
   "window_sha256": [
    "c75f0a6065b7a3eaab0c3a67c1f28f86f2f29a4ca71abce3380d581222658c8a",
    "4eabcbd35e5fb9ebceac5e3daaf3629df21407a39a514b32dc0733f6edfb1d09",
    "4782b6ca7b4157ad68e1b5619d75b4bcb704dedf71289302353fc1593e2c4890",
    "90453cbb5478e7ab72214b9ad129069086bef50f1f9eb74005e123ae66b1c0b2"
   ],
   "exact_window_sha256": [
    "c75f0a6065b7a3eaab0c3a67c1f28f86f2f29a4ca71abce3380d581222658c8a",
    "4eabcbd35e5fb9ebceac5e3daaf3629df21407a39a514b32dc0733f6edfb1d09",
    "4782b6ca7b4157ad68e1b5619d75b4bcb704dedf71289302353fc1593e2c4890",
    "90453cbb5478e7ab72214b9ad129069086bef50f1f9eb74005e123ae66b1c0b2"
   ]
  },
  {
   "input": "Records changed 5 days ago shall be kept.",
   "reduced": "Records changed shall be kept.",
   "words": [
    "Records",
    "changed",
    "shall",
    "be",
    "kept"
   ],
   "gaps": [
    " ",
    " ",
    " ",
    " "
   ],
   "checked": "Records changed shall be kept",
   "checked_normalised": "Records changed shall be kept",
   "window_sha256": [
    "77e61582c2038ce6f90134c7f86b2bcdb7564988e303b697552617b91ece2d1d",
    "0a682cbabb2e885fe40ded396c6648e9c0c5084ec7549deccd2e24dc970ab5b6"
   ],
   "exact_window_sha256": [
    "77e61582c2038ce6f90134c7f86b2bcdb7564988e303b697552617b91ece2d1d",
    "0a682cbabb2e885fe40ded396c6648e9c0c5084ec7549deccd2e24dc970ab5b6"
   ]
  },
  {
   "input": "Vali\u00addation of the \ufb01nal \ufb02ow   records",
   "reduced": "Vali\u00addation of the \ufb01nal \ufb02ow records",
   "words": [
    "Validation",
    "of",
    "the",
    "final",
    "flow",
    "records"
   ],
   "gaps": [
    " ",
    " ",
    " ",
    " ",
    " "
   ],
   "checked": "Vali\u00addation of the \ufb01nal \ufb02ow records",
   "checked_normalised": "Validation of the final flow records",
   "window_sha256": [
    "70bfc2cbffc11ab16896a58b78f7b59acc918ad4ebd34d1044bbe74c247553f5",
    "69787048f46bee860331d9eb200b11c4844696643870680cabcb3ccc6ed150fc",
    "35f014783de39db4b8e9d253416779941f6d983f43215ddf5ca08656cb7a51de"
   ],
   "exact_window_sha256": [
    "81d97a219c4f54307dd69d3572e9fa61184434584a7247dcafdcf937a0523bbd",
    "d0f5e7cc19d2af4aae51fd717d4dcf16832f1f019fbd52d06f15e353ebdb3f60",
    "22742599851f11fc58384f39883d3f8fdc444c83b2783b93c75463569a4dd09d"
   ]
  },
  {
   "input": "See section 3.1.2 (\u2018Risk review\u2019) of Annex\u201399.",
   "reduced": "See section 3.1.2 (\u2018Risk review\u2019) of Annex\u201399.",
   "words": [
    "See",
    "section",
    "3",
    "1",
    "2",
    "Risk",
    "review",
    "of",
    "Annex",
    "99"
   ],
   "gaps": [
    " ",
    " ",
    ".",
    ".",
    " ('",
    " ",
    "') ",
    " ",
    "-"
   ],
   "checked": "See section 3.1.2 (\u2018Risk review\u2019) of Annex\u201399",
   "checked_normalised": "See section 3.1.2 ('Risk review') of Annex-99",
   "window_sha256": [
    "d00bc258e4032fbdb7684ac5bdcb0e79e95cb3460a735a66c7399ab43f76da36",
    "8c32e687cbccc0a1ee829479be4b6280d96ef7f767d79bf4797c7d49c76214f9",
    "1133a1573b692d057ac44417270abb59a074c171f2da1db22436ec1c5ef282eb",
    "32fb190765527b5fc0b45060af8841d1e71b0170be95df906336fb245cb8e259",
    "ce2fcd46ff727cdf9c9aa2b1b72ac6d636d54f7196a9c96a0143bad15831603a",
    "45f6f254279edae7c02ee49b9df025b6aea6401284b4653b89fade77cbd0decc",
    "e3fb437cffcf8b2b98e98099b3f53662a93efab7713385a936018204c63ce4d7"
   ],
   "exact_window_sha256": [
    "d00bc258e4032fbdb7684ac5bdcb0e79e95cb3460a735a66c7399ab43f76da36",
    "8c32e687cbccc0a1ee829479be4b6280d96ef7f767d79bf4797c7d49c76214f9",
    "1707b891f57804e71b3facfe96c8d6ad5716c982012946a5c5586ae7ea6bc9bd",
    "af1304a944940de432f62217459e2a42c6d5989beca0209a88a924449c579e8e",
    "6334f81d7e385b49c88bdead0cd30716725c2c3caf08e8a9dda1e6bce6fcb086",
    "a4b927eb28b7cfe10b9c12a0000b8db5cd1cfeb3ca6db2fb8718bdcbd131ef4e",
    "1266dc00769aa87aef025872e1bfbc76f76c988c3d884c27f11611ec8cb04473"
   ]
  },
  {
   "input": "  leading and trailing   marks are outside the span!!  ",
   "reduced": "leading and trailing marks are outside the span!!",
   "words": [
    "leading",
    "and",
    "trailing",
    "marks",
    "are",
    "outside",
    "the",
    "span"
   ],
   "gaps": [
    " ",
    " ",
    " ",
    " ",
    " ",
    " ",
    " "
   ],
   "checked": "leading and trailing marks are outside the span",
   "checked_normalised": "leading and trailing marks are outside the span",
   "window_sha256": [
    "ea6490ba30ee9ca3f8a895a9549d9ee8486a3acaccd4adaaa6e7cc020a0282f1",
    "ff96fc6da767f7e7d952b137aa392f86e472180f446b9d453a73dd290f7fd507",
    "669dc97419b1d3e1d1dac3200fde4562bf604d3bd9ba55cdb23662b535259e9b",
    "5336f080b6f8b70282ca4c398561349e7592a7941b88d45b6b62f47a216f94d2",
    "067f3c39ab17d012ba48d85b183722154edca317dec0cfa01d010f5280d1a854"
   ],
   "exact_window_sha256": [
    "ea6490ba30ee9ca3f8a895a9549d9ee8486a3acaccd4adaaa6e7cc020a0282f1",
    "ff96fc6da767f7e7d952b137aa392f86e472180f446b9d453a73dd290f7fd507",
    "669dc97419b1d3e1d1dac3200fde4562bf604d3bd9ba55cdb23662b535259e9b",
    "5336f080b6f8b70282ca4c398561349e7592a7941b88d45b6b62f47a216f94d2",
    "067f3c39ab17d012ba48d85b183722154edca317dec0cfa01d010f5280d1a854"
   ]
  },
  {
   "input": "Three words only",
   "reduced": "Three words only",
   "words": [
    "Three",
    "words",
    "only"
   ],
   "gaps": [
    " ",
    " "
   ],
   "checked": "Three words only",
   "checked_normalised": "Three words only",
   "window_sha256": [],
   "exact_window_sha256": []
  }
 ]
}
```
