Backend (make everything real, no stubs): - Implement all 10 Python engine scripts (scispacy, pymare, pytrials, minicheck, indra, openalex, paperqa, pykeen, storm, asreview) behind the existing lib/engines bridges. openalex + pytrials are zero-dep (stdlib urllib, work out of the box); the 8 heavy engines run the real library when installed and emit an honest structured error envelope when absent — no phantom capability, no faked outputs. - /api/verify: hard production guard so the offline fixture path can NEVER activate in production (MOCK_MODE gated to NODE_ENV!=production); prod always runs the real retrieve→extract→verify pipeline. - /api/auth/google: wrap the OAuth entrypoint in try/catch — fail closed to /login. - MoA: wire the previously-dangling design_priors artifact into the multivers cross-source verifier as a mean-preserving, clamped (+/-25%) design-credibility weight; exact no-op when absent, so the benchmark verdict mix is protected. Frontend (enterprise-grade polish): - New shared console UI kit (components/console/ui.tsx): Skeleton, Card, Badge, Button, StatCard, EmptyState — one source for the house tokens. - Skeleton shimmer keyframe; LoadingBanner now renders shimmer instead of plain text (propagates to ~29 tool pages, signature unchanged). - Real workspace overview landing page: live stats (fixes a phantom 'claims' field the old page always rendered as 0), recent verifications with permalinks, quick actions, skeleton loading + empty + error states. Verified: tsc clean, 10/10 verify integration tests pass, production build compiles all 417 pages.
95 lines
3.1 KiB
Python
Executable File
95 lines
3.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""scispaCy biomedical entity linking — stdin/stdout bridge.
|
|
|
|
Bridge: lib/engines/scispacy.ts (linkEntities). Reads a JSON job on stdin
|
|
{"text": str} and emits exactly one JSON object on stdout:
|
|
|
|
success: {"ok": true, "entities": [
|
|
{"text", "label", "start", "end",
|
|
"umlsCui": str|null, "canonicalName": str|null, "score": float|null}, ...]}
|
|
handled error: {"ok": false, "error": "..."} (exit 1)
|
|
|
|
Dep-gated: requires `scispacy` + `spacy` and a biomedical model (default
|
|
en_core_sci_sm, override with SCISPACY_MODEL). When the library or model is absent
|
|
the script emits an honest error envelope and exits 1 — never fake entities. Runs
|
|
real NER + UMLS entity linking. The input text is read from stdin only, never logged.
|
|
"""
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
DEFAULT_MODEL = "en_core_sci_sm"
|
|
|
|
|
|
def link(job):
|
|
text = job.get("text")
|
|
if not isinstance(text, str) or not text.strip():
|
|
return {"ok": False, "error": "scispacy: non-empty 'text' is required"}
|
|
|
|
try:
|
|
import spacy
|
|
# Importing registers the "scispacy_linker" factory with spaCy's pipeline.
|
|
import scispacy # noqa: F401
|
|
from scispacy.linking import EntityLinker # noqa: F401
|
|
except ImportError:
|
|
return {"ok": False, "error": "scispacy not installed; install scispacy to enable this engine"}
|
|
|
|
model_name = os.environ.get("SCISPACY_MODEL", DEFAULT_MODEL)
|
|
try:
|
|
nlp = spacy.load(model_name)
|
|
except OSError:
|
|
return {
|
|
"ok": False,
|
|
"error": f"scispacy model '{model_name}' not installed; install it "
|
|
f"(see allenai/scispacy releases) to enable this engine",
|
|
}
|
|
|
|
if "scispacy_linker" not in nlp.pipe_names:
|
|
nlp.add_pipe(
|
|
"scispacy_linker",
|
|
config={"resolve_abbreviations": True, "linker_name": "umls"},
|
|
)
|
|
linker = nlp.get_pipe("scispacy_linker")
|
|
|
|
doc = nlp(text)
|
|
entities = []
|
|
for ent in doc.ents:
|
|
umls_cui = None
|
|
canonical_name = None
|
|
score = None
|
|
kb_ents = getattr(ent._, "kb_ents", None)
|
|
if kb_ents:
|
|
cui, top_score = kb_ents[0]
|
|
umls_cui = cui
|
|
score = float(top_score)
|
|
concept = linker.kb.cui_to_entity.get(cui)
|
|
if concept is not None:
|
|
canonical_name = concept.canonical_name
|
|
entities.append({
|
|
"text": ent.text,
|
|
"label": ent.label_,
|
|
"start": ent.start_char,
|
|
"end": ent.end_char,
|
|
"umlsCui": umls_cui,
|
|
"canonicalName": canonical_name,
|
|
"score": score,
|
|
})
|
|
|
|
return {"ok": True, "entities": entities}
|
|
|
|
|
|
def main():
|
|
try:
|
|
raw = sys.stdin.read()
|
|
job = json.loads(raw) if raw.strip() else {}
|
|
out = link(job)
|
|
print(json.dumps(out))
|
|
return 0 if out.get("ok") else 1
|
|
except Exception as exc: # noqa: BLE001 — surface every failure as a JSON envelope
|
|
print(json.dumps({"ok": False, "error": f"{type(exc).__name__}: {exc}"}))
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|