A unit audit beside an abstract edit: use Decimal, then review the sentence

2026-11-06来源 dev.to PythonEnglish

An abstract editor can preserve a number while changing its unit. A small deterministic check can make that mismatch visible to a research developer. It cannot decide whether the biology, assay or prose is correct.

This is a self-authored teaching input: a source quantity is 7.5 ng/mL. A candidate says 7.5 ug/mL. Here ug is an explicit ASCII spelling for micrograms, not a parser guessing what the author meant. Both denominators are mL.

A deliberately narrow, runnable check

Save this as unit_audit.py and run python3 unit_audit.py. It uses Python's standard-library Decimal with decimal strings, avoiding a binary-float detour for these finite decimal examples. No service, model, patient data or scientific Run is involved.

from decimal import Decimal # Narrow teaching checker: mass concentration, in ng/mL or ug/mL only. TO_NG = {"ng/mL": Decimal("1"), "ug/mL": Decimal("1000")} def compare(source_value, source_unit, candidate_value, candidate_unit): left = Decimal(source_value) * TO_NG[source_unit] right = Decimal(candidate_value) * TO_NG[candidate_unit] return { "source_ng_per_mL": str(left), "candidate_ng_per_mL": str(right), "same_amount": left == right, } print(compare("7.5", "ng/mL", "7.5", "ug/mL")) print(compare("7.5", "ng/mL", "0.0075", "ug/mL")) 

Actual local output:

{'source_ng_per_mL': '7.5', 'candidate_ng_per_mL': '7500.0', 'same_amount': False} {'source_ng_per_mL': '7.5', 'candidate_ng_per_mL': '7.5000', 'same_amount': True} 

The first candidate represents 7,500 ng/mL rather than 7.5. The second represents the same quantity after an explicit conversion. Equality here covers only that mathematical statement. It does not authorize a conversion in a language-only editing task.

Bind the check to the author's material

Keep the authorized source paragraph and the candidate alongside the result. Record which occurrence each quantity belongs to, its comparator and the measurement name. In this toy checker the caller already supplies the mapping; the program does not extract values from prose or discover corresponding sentences.

For example, a source saying “below 7.5 ng/mL” must not silently become “7.5 ng/mL.” Running compare would not see the lost word below because it has no comparator input. Nor would it detect serum becoming plasma, a quantification limit becoming an observed measurement, or a different participant set. Those remain explicit author-review items.

Reject unsupported units instead of guessing. This dictionary does not handle molar concentrations, molecular weights, logarithms, normalized ratios, assay-specific conventions or the full range of Unicode spellings. A real application should start from its actual input contract and method evidence, not expand this two-entry example into a universal scientific validator.

Reviewable output for a writing workflow

Return the source occurrence, candidate occurrence, requested editing scope, this limited check and unresolved semantic questions. The researcher first confirms the measurement and the intended operation, then checks every affected table and paragraph before accepting changed wording. Preserve uncertainty instead of turning a check into a “scientifically approved” badge.

ICMJE asks authors to consult the target journal's unit requirements. That guidance is a reason to make conversion explicit, not to replace symbols without converting values. Its abstract guidance also requires consistency with the article.

We are the RigorMed team. Our research-material handoff starts with an author's existing authorized text, editing constraints and an auditable comparison. This standalone teaching script is not a claim that this exact code is integrated into the product. Model execution follows displayed credits; final scientific and manuscript decisions remain with the author.

https://rigormed.com/en?utm_source=dev&utm_medium=article&utm_campaign=d54_morning_unit_audit

Sources:

All quantities and sentences here are synthetic teaching material. The output above is from the actual local execution of the shown code.

原文:https://www.a8q9.cn/en/article/a-unit-audit-beside-an-abstract-edit-use-decimal-then-review-the-sentence-70dce8.html

相关文章