본문으로 건너뛰기
Skillpedia
일반 코딩5.8k · #14677

bridging-presidio-and-spacy

하는 일

이 스킬은 OpenMed 임상 텍스트 도구를 Presidio, spaCy, LangChain에 연결합니다. 이들은 개인 데이터 탐지와 언어 앱에 널리 쓰이는 도구입니다. 이미 이 도구 중 하나를 쓰고 있고 그 안에서 OpenMed를 쓰고 싶은 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓Microsoft Presidio를 이미 쓰고 있고 OpenMed 임상 PII 탐지를 추가하고 싶을 때.
  • ✓spaCy 파이프라인이 OpenMed 개인 데이터 구간을 만들어야 할 때.
  • ✓LangChain 체인을 만들면서 언어 모델에 전달되기 전에 환자 데이터를 제거하고 싶을 때.

스킬 링크

https://github.com/maziyarpanahi/openmed/blob/master/skills/bridging-presidio-and-spacy/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/maziyarpanahi/openmed/blob/master/skills/bridging-presidio-and-spacy/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이미 Microsoft Presidio를 쓰고 있습니다. 제 Presidio 파이프라인에 OpenMed 임상 PII 탐지를 추가해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 선택한 도구에 필요한 추가 패키지만 설치한 다음, 맞는 어댑터를 사용해 OpenMed 결과와 그 도구의 형식 사이를 변환합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Bridging Presidio, spaCy & LangChain

OpenMed interoperates with the dominant PII/NLP ecosystems through a single, lazy adapter registry: openmed.interop. Adapters live behind explicit imports, so importing openmed never drags in Presidio, spaCy, or LangChain — each is an optional extra you install only when you need that bridge.

When to use

Reach for a bridge when:

  • you already run Microsoft Presidio and want OpenMed's clinical PII recall on top (or to feed OpenMed spans back into Presidio's anonymizer);
  • you have a spaCy pipeline and want OpenMed PII spans on the Doc;
  • you build LangChain chains and want to redact PHI before text reaches an LLM (the on-device guardrail in front of a cloud model);
  • you need OpenMed's de-identification reachable from an existing framework instead of rewriting the pipeline around openmed.deidentify.

The lazy adapter registry (verified)

import openmed.interop as interop

interop.available_adapters()
# ('cda', 'hl7v2', 'langchain', 'presidio', 'spacy')

spec = interop.adapter_spec("presidio")
# AdapterSpec(name='presidio', module='openmed.interop.presidio',
#             extra='presidio', description='Presidio RecognizerResult adapter')

mod = interop.get_adapter("presidio")        # imports openmed.interop.presidio
# Attribute access also works lazily:
openmed.interop.presidio                      # same module, imported on first touch

available_adapters() and adapter_spec() never import the adapter module, so they are safe to call for discovery even without the extra installed. get_adapter(name) (and attribute access) triggers the import — and the adapter's own optional dependency.

Install only the extra you need:

pip install "openmed[presidio]"     # Presidio RecognizerResult adapter
pip install "openmed[spacy]"        # spaCy openmed_deid component
pip install "openmed[langchain]"    # LangChain redaction runnable
# cda and hl7v2 adapters ship in core (no extra) — see their own skills

Presidio bridge (verified callables)

Module openmed.interop.presidio converts between Presidio RecognizerResults and OpenMed canonical PIIEntitys, and merges both detectors through OpenMed's semantic-unit merger.

from openmed.interop.presidio import (
    to_canonical,        # RecognizerResult(s) -> [PIIEntity]
    from_canonical,      # [PIIEntity] -> [RecognizerResult]  (needs presidio extra)
    merge_with_openmed,  # combine OpenMed + Presidio spans, resolve overlaps
    PresidioAdapterConfig,
)
import openmed

text = "Dr. Smith called patient at 617-555-0123 on 2024-03-02."

# Presidio gives you RecognizerResults; OpenMed gives PIIEntities.
openmed_spans = openmed.extract_pii(text).entities
presidio_results = analyzer.analyze(text=text, language="en")   # your Presidio analyzer

merged = merge_with_openmed(
    openmed_spans, presidio_results, text=text,
    config=PresidioAdapterConfig(preserve_presidio_labels=True),
)
# -> de-duplicated [PIIEntity]; overlaps resolved by score, length, OpenMed-origin

Why merge instead of union: merge_with_openmed runs both detectors' spans through merge_entities_with_semantic_units, so overlapping/adjacent detections collapse into one correct span (e.g. PHONE from Presidio vs a partial OpenMed hit) rather than producing double redactions. Label mapping is built in (Presidio PHONE_NUMBER ↔ OpenMed PHONE, US_SSN ↔ SSN, etc.).

To push OpenMed spans into Presidio's anonymizer, convert back:

results = from_canonical(openmed_spans)        # [RecognizerResult]
anonymized = anonymizer.anonymize(text=text, analyzer_results=results)

spaCy bridge (verified factory)

Module openmed.interop.spacy_component registers a spaCy pipeline factory named openmed_deid. Add it to a pipeline and OpenMed PII spans land on the Doc.

import spacy
import openmed.interop.spacy_component   # registers the @Language.factory

nlp = spacy.blank("en")
nlp.add_pipe("openmed_deid", config={
    "confidence_threshold": 0.5,
    "lang": "en",
    "target": "openmed_pii",     # doc.spans key
    "merge_ents": False,         # set True to also write doc.ents
    "alignment_mode": "expand",  # char->token alignment: strict|contract|expand
})

doc = nlp("Patient John Doe, MRN 12345, seen today.")
for span in doc.spans["openmed_pii"]:
    print(span.label_, span.text)
# raw char-offset spans also available on doc._.openmed_pii

`merge

자주 묻는 질문

OpenMed를 설치하면 세 도구가 모두 로드되나요?

아니요. 각 연결은 선택 기능이므로 필요한 것만 설치하면 됩니다.

OpenMed 구간을 Presidio로 되돌릴 수 있나요?

네. Presidio 형식과 주고받는 변환을 다룹니다.

LangChain도 다루나요?

네. 언어 모델에 전달되기 전에 텍스트를 가리는 방법을 다룹니다.

상세 정보

작성자의 원본 설명

Combine OpenMed clinical NLP with Microsoft Presidio, spaCy, or LangChain through OpenMed's built-in interop adapter registry (openmed.interop). Covers the lazy adapter registry (available_adapters, get_adapter, adapter_spec), the presidio/spacy/langchain pip extras, and the verified callables — Presidio to_canonical/from_canonical/merge_with_openmed, the spaCy openmed_deid pipeline factory, and the LangChain create_redaction_runnable. Use when the user wants to add Presidio recognizers, embed OpenMed PII detection in a spaCy pipeline, or use OpenMed de-identification as a LangChain runnable.

repo: maziyarpanahi/openmed

인기도

GitHub 스타
5.8k
순위
#14677
라이선스
Apache-2.0
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬