Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
58 lines
2.4 KiB
Python
58 lines
2.4 KiB
Python
import unittest
|
|
import tempfile
|
|
|
|
from scispacy.candidate_generation import CandidateGenerator, create_tfidf_ann_index, MentionCandidate
|
|
from scispacy.umls_utils import UmlsKnowledgeBase
|
|
|
|
|
|
class TestCandidateGeneration(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
super().setUp()
|
|
|
|
def test_create_index(self):
|
|
|
|
umls_fixture = UmlsKnowledgeBase("tests/fixtures/umls_test_fixture.json")
|
|
with tempfile.TemporaryDirectory() as dir_name:
|
|
umls_concept_aliases, tfidf_vectorizer, ann_index = create_tfidf_ann_index(dir_name, umls_fixture)
|
|
|
|
assert len(umls_concept_aliases) == 93
|
|
assert len(ann_index) == 93 # Number of deduplicated aliases + canonical ids
|
|
tfidf_params = tfidf_vectorizer.get_params()
|
|
|
|
assert tfidf_params["analyzer"] == "char_wb"
|
|
assert tfidf_params["min_df"] == 10
|
|
assert tfidf_params["ngram_range"] == (3, 3)
|
|
|
|
def test_candidate_generation(self):
|
|
|
|
umls_fixture = UmlsKnowledgeBase("tests/fixtures/umls_test_fixture.json")
|
|
with tempfile.TemporaryDirectory() as dir_name:
|
|
umls_concept_aliases, tfidf_vectorizer, ann_index = create_tfidf_ann_index(dir_name, umls_fixture)
|
|
|
|
candidate_generator = CandidateGenerator(ann_index, tfidf_vectorizer, umls_concept_aliases, umls_fixture)
|
|
results = candidate_generator(['(131)I-Macroaggregated Albumin'], 10)
|
|
|
|
canonical_ids = [x.concept_id for x in results[0]]
|
|
assert canonical_ids == ['C0000005', 'C0000015', 'C0000074', 'C0000102', 'C0000103']
|
|
|
|
# The mention was an exact match, so should have a distance of zero to a concept:
|
|
assert results[0][0] == MentionCandidate(concept_id='C0000005',
|
|
aliases=['(131)I-Macroaggregated Albumin'],
|
|
similarities=[1.0])
|
|
|
|
# Test we don't crash with zero vectors
|
|
results = candidate_generator(['ZZZZ'], 10)
|
|
assert results == [[]]
|
|
|
|
def test_empty_list(self):
|
|
|
|
umls_fixture = UmlsKnowledgeBase("tests/fixtures/umls_test_fixture.json")
|
|
with tempfile.TemporaryDirectory() as dir_name:
|
|
umls_concept_aliases, tfidf_vectorizer, ann_index = create_tfidf_ann_index(dir_name, umls_fixture)
|
|
|
|
candidate_generator = CandidateGenerator(ann_index, tfidf_vectorizer, umls_concept_aliases, umls_fixture)
|
|
results = candidate_generator([], 10)
|
|
|
|
assert results == []
|