92 lines
2.9 KiB
Python
92 lines
2.9 KiB
Python
"""Run the approved first-batch ClinDB pipeline over five local paper copies."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
from mdpolish.components import (
|
|
ArxivSubmissionStampComponent,
|
|
HtmlTableDoubleEscapeComponent,
|
|
HtmlTableLayoutComponent,
|
|
ManuscriptLineNumberComponent,
|
|
PageBreakWordJoinComponent,
|
|
ReferenceSpacingComponent,
|
|
RepeatedRunningHeaderComponent,
|
|
WordReviewCommentComponent,
|
|
)
|
|
from mdpolish.experiment import InputDocument, collect_tool_metadata, run_experiment
|
|
from mdpolish.models import RunStatus
|
|
from mdpolish.pipeline import Pipeline
|
|
|
|
_DOCUMENT_IDS = ("dmp", "ejhf", "jama", "sim", "springer")
|
|
CLINDB_WORD_JOIN_MAPPINGS = (
|
|
("medi-", "cal", "medical"),
|
|
("possi-", "bly", "possibly"),
|
|
("cre-", "ated", "created"),
|
|
("SOFA-", "based", "SOFA-based"),
|
|
("life-", "threatening", "life-threatening"),
|
|
("threshold.", "olds", "thresholds"),
|
|
)
|
|
|
|
|
|
def build_pipeline() -> Pipeline:
|
|
"""Build the frozen ClinDB first-batch component order."""
|
|
return Pipeline(
|
|
[
|
|
WordReviewCommentComponent(),
|
|
ManuscriptLineNumberComponent(),
|
|
ArxivSubmissionStampComponent(),
|
|
RepeatedRunningHeaderComponent(),
|
|
PageBreakWordJoinComponent(CLINDB_WORD_JOIN_MAPPINGS),
|
|
HtmlTableDoubleEscapeComponent(),
|
|
HtmlTableLayoutComponent(),
|
|
ReferenceSpacingComponent(),
|
|
]
|
|
)
|
|
|
|
|
|
def _parse_args() -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--run-id", required=True, help="safe identifier within today's artifact directory")
|
|
return parser.parse_args()
|
|
|
|
|
|
def main() -> int:
|
|
args = _parse_args()
|
|
repository_root = Path(__file__).resolve().parents[1]
|
|
documents = tuple(
|
|
InputDocument(
|
|
document_id=document_id,
|
|
source_path=repository_root / "data" / "md" / f"{document_id}.md",
|
|
source_label=f"data/md/{document_id}.md",
|
|
)
|
|
for document_id in _DOCUMENT_IDS
|
|
)
|
|
started_at = datetime.now().astimezone()
|
|
try:
|
|
result = run_experiment(
|
|
pipeline=build_pipeline(),
|
|
documents=documents,
|
|
run_id=args.run_id,
|
|
artifacts_root=repository_root / "artifacts",
|
|
started_at=started_at,
|
|
tool=collect_tool_metadata(repository_root),
|
|
)
|
|
except Exception as error:
|
|
print(f"experiment failed: {type(error).__name__}: {error}", file=sys.stderr)
|
|
return 1
|
|
|
|
print(f"run_id={args.run_id}")
|
|
print(f"status={result.status.value}")
|
|
print(f"documents={result.document_count}")
|
|
print(f"changes={result.change_count}")
|
|
print(f"artifacts={result.run_directory}")
|
|
return 0 if result.status is RunStatus.SUCCESS else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|