research_helpers.prose
This module tracks every number a document states in prose and links it to the data that supports it, as well as auditing the prose for untracked numbers. See numbers in the prose.
- research_helpers.prose.normalise_prose(text)[source]
Return a manuscript as the registry matches against it: comments removed, whitespace collapsed.
A sentence that has been commented out no longer counts as printed.
- class research_helpers.prose.ProseNumber(key, template, values, source='', section='', document='paper')[source]
Bases:
objectOne fragment of a sentence as the document prints it, and how to compute its numbers.
‘template’ is the fragment with ‘{}’ where each number goes and doubled braces for literal ones, so ‘(Q_{{ov}} = {})’. Whitespace is immaterial: the fragment and the document are both compared with every run of whitespace collapsed to one space.
- Parameters:
- expected()[source]
Return the fragment with the numbers from the data.
- Raises:
ValueError – if the values do not fill the template exactly.
- Return type:
- pattern()[source]
Return a pattern matching the fragment whatever numbers it carries.
Used to find what the document prints when it does not print what the data contains. A number is matched as a run without whitespace, so a sentence that now says something else entirely does not pass for the same sentence with different numbers.
- class research_helpers.prose.Mismatch(key, section, expected, printed)[source]
Bases:
NamedTupleA fragment the document does not print as is in the data.
- class research_helpers.prose.ProseCheck(checked, stale, vanished, fixed, orphaned, failed, open_discrepancies)[source]
Bases:
NamedTupleWhat a check of the registry against its documents found.
- Parameters:
- class research_helpers.prose.Occurrence(line, token, context, category, detail='', start=0)[source]
Bases:
objectOne numeric token in a document’s prose, and what accounts for it.
- class research_helpers.prose.ProseRegistry(*, known_discrepancies=None, untraced=None, parameter_symbols=())[source]
Bases:
objectThe numbers a project’s documents state in prose, and their checks.
- Parameters:
- add(*entries)[source]
Register entries built directly.
- Raises:
ValueError – if a key is already registered.
- Return type:
- Parameters:
entries (ProseNumber)
- register(key, template, *, source='', section='', document=PAPER_DOCUMENT)[source]
Register the decorated function that computes the numbers of a fragment.
- check(paths=None, *, document=None)[source]
Compare every entry against the document that prints it.
- Parameters:
- Return type:
- Returns:
What was found or falsy when every entry holds.
- Raises:
FileNotFoundError – if a manuscript does not exist, or a document is configured without one.
KeyError – if an entry names a document the project does not configure.
- report(found)[source]
Return a description of what the check found.
- Return type:
- Parameters:
found (ProseCheck)
- audit(document=PAPER_DOCUMENT, path=None)[source]
Classify every numeric token in a document’s prose.
- Parameters:
- Return type:
- Returns:
Every token, in document order.
- Raises:
FileNotFoundError – if no ‘path’ is given and the document is configured without a manuscript.
- research_helpers.prose.audit(text, entries=(), *, tables_dir=None, parameter_symbols=())[source]
Classify every numeric token in a manuscript’s prose.
Each token falls in the first category that accounts for it:
registered: it lies inside a fragment one of the entries describes.
notation: it is a constant of an inline formula, or a parameter’s value in one that assigns a declared parameter symbol. Not a result.
cited-float: it appears in a generated table the same paragraph cites, which carries it.
other-float: it appears in a generated table the paragraph does not cite.
untraced: none of the above. These are the numbers to pin.
Numbers in the preamble, comments, display math, citations, labels, references and the arguments of ‘input’ and ‘includegraphics’ are not prose and are skipped.
- Parameters:
text (
str) – the manuscript, as written.entries (
Sequence[ProseNumber], default:()) – the registry entries for this manuscript.tables_dir (
Path|str|None, default:None) – where its generated tables are, named by label without the ‘tab:’ prefix.parameter_symbols (
Collection[str], default:()) – see ‘ProseRegistry’.
- Return type:
- Returns:
Every token, in document order.
- research_helpers.prose.audit_report(occurrences, *, title='Prose-number audit')[source]
Render an audit as Markdown, untraced numbers first.
- Parameters:
occurrences (
Sequence[Occurrence]) – what ‘audit’ found.title (
str, default:'Prose-number audit') – the heading.
- Return type:
- Returns:
The report.