Files
2nd/10_Wiki/Topics/AI_and_ML/Ontology-Engineering.md
T
koriweb d8a80f6272 chore(wiki): dangling 링크 canonical 정규화 (768파일/1200건)
이름만 다른(표기 변형) [[위키링크]]를 대상 문서의 canonical 제목으로 치환해
끊겼던 1,200개 링크를 연결. 제목/파일명 정규화 일치만 적용하고 별칭 매칭은
과병합 위험으로 제외(애매성 가드). 원본은 _link_reconcile_backup/ 에 백업.
도구: Datacollect/scripts/link_reconcile_apply.mjs

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 12:24:15 +09:00

5.7 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-ontology-engineering Ontology Engineering 10_Wiki/Topics verified self
Ontology Engineering
Ontological Engineering
Ontology-Driven Relevancy Filtering
OWL Modeling
none A 0.9 applied
ontology
owl
rdf
sparql
knowledge-graph
protege
semantic-web
kg-rag
2026-05-10 pending
language framework
python/turtle rdflib/owlready2/protege

Ontology Engineering

도메인의 개념·관계·제약을 형식 모델(OWL/RDF)로 표현하는 엔지니어링. 2025년 KG-based RAG로 재부상.

핵심

구성요소

  • Class (개념): Person, Drug, Symptom.
  • Individual (인스턴스): :John a :Person.
  • ObjectProperty / DataProperty: hasParent, hasAge.
  • Axioms: subClassOf, equivalentClass, disjointWith, cardinality.
  • Restrictions: someValuesFrom, allValuesFrom, hasValue.

표현 언어

  • RDF / RDFS: 그래프 데이터 모델 + 기본 어휘.
  • OWL 2 DL: description logic, decidable. 추론기(reasoner) 지원.
  • OWL 2 EL/QL/RL: 큰 온톨로지 / 쿼리 / 룰 최적화 프로파일.
  • SHACL: shape constraints, validation.
  • SPARQL 1.1: 그래프 쿼리.

방법론

  • METHONTOLOGY: 명세 → 개념화 → 형식화 → 구현 → 평가.
  • NeOn: re-engineering, alignment, modular ontology.
  • Ontology Development 101 (Stanford): iterative + competency questions.
  • OBO Foundry: 생명과학 표준 (orthogonality, FAIR).

도구

  • Protégé: 데스크톱 OWL 에디터, plugin (HermiT, ELK reasoner).
  • WebProtégé: 협업.
  • owlready2 / rdflib (Python), Apache Jena (Java).
  • GraphDB / Stardog / Neo4j+n10s: triple/labeled-property store.

모던 응용 (2025-2026)

  • KG-based RAG: LLM이 ontology 기반 KG를 조회 (vs vector-only RAG). 정확도/추적성 향상.
  • GraphRAG (Microsoft): 커뮤니티 요약 + 엔티티 그래프.
  • NL2SPARQL: LLM이 자연어 → SPARQL 변환.
  • Ontology-driven 분류/필터링: 문서를 도메인 개념으로 태깅 → relevancy filtering.

💻 패턴

Turtle (TTL) 도메인 모델

@prefix : <http://ex.com/med#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:Drug a owl:Class .
:Antibiotic a owl:Class ; rdfs:subClassOf :Drug .
:treats a owl:ObjectProperty ; rdfs:domain :Drug ; rdfs:range :Disease .
:Amoxicillin a :Antibiotic ; :treats :StrepThroat .

owlready2 — 동적 클래스 정의 + 추론

from owlready2 import *
onto = get_ontology("http://ex.com/med.owl")
with onto:
    class Drug(Thing): pass
    class Antibiotic(Drug): pass
    class treats(ObjectProperty): pass
    class Amoxicillin(Antibiotic): pass
sync_reasoner()  # HermiT 호출, 클래스 계층 추론

SPARQL 쿼리 (rdflib)

from rdflib import Graph
g = Graph().parse("med.ttl", format="turtle")
q = """
PREFIX : <http://ex.com/med#>
SELECT ?drug WHERE {
  ?drug a/rdfs:subClassOf* :Antibiotic ;
        :treats :StrepThroat .
}
"""
for row in g.query(q): print(row.drug)

Competency questions → 평가

COMPETENCY_QUESTIONS = [
    "What antibiotics treat strep throat?",
    "Which drugs interact with warfarin?",
]
def evaluate_ontology(graph, questions):
    return {q: bool(graph.query(translate_to_sparql(q))) for q in questions}

KG-based RAG (LLM + ontology lookup)

def kg_rag(question: str, llm, kg) -> str:
    sparql = llm.generate(f"Translate to SPARQL using ontology schema:\n{kg.schema}\nQ: {question}")
    facts = kg.query(sparql)
    return llm.generate(f"Answer using facts:\n{facts}\nQ: {question}")

Ontology-driven relevancy filter

def filter_docs_by_ontology(docs: list[str], target_concept: str, kg) -> list[str]:
    # tag each doc with concepts via NER + ontology mapping
    relevant_concepts = set(kg.descendants_of(target_concept))
    return [d for d in docs
            if relevant_concepts & extract_concepts(d, kg)]

결정 기준

상황 권장
작은 schema, 빠른 ETL RDFS + SHACL
추론 필요 (subsumption) OWL 2 EL (확장성)
복잡 제약, 의료/법률 OWL 2 DL + HermiT
LPG (속성 그래프) 워크로드 Neo4j + neosemantics
LLM 통합 RAG OWL 2 EL + GraphDB + NL2SPARQL
협업 편집 WebProtégé

기본값: OWL 2 EL + Protégé + GraphDB + competency-question 기반 평가.

🔗 Graph

🤖 LLM 활용

  • 언제: NL→SPARQL 변환, 클래스 라벨링/정의 초안, axiom 검토 페어, ontology alignment 후보 제안, KG-RAG 답변 합성.
  • 언제 X: critical 도메인 axiom 단독 결정 (전문가 검토 필수), reasoner를 LLM으로 대체 (decidability 보장 X).

안티패턴

  • 평면 taxonomy를 ontology로 부르기 (axiom/속성 없음).
  • 클래스를 인스턴스로 사용 (metamodeling 혼동).
  • 모든 것을 owl:Thing 직속 (계층 부재).
  • Reasoner 없이 disjointWith 남발 (불일치 탐지 안됨).
  • Competency question 없이 모델 시작 → scope creep.
  • Ontology를 LLM 컨텍스트에 raw로 주입 (token 폭발) — schema-only로 축약.

🧪 검증 / 중복

🕓 Changelog

  • 2026-05-10: 표준 포맷, KG-based RAG / GraphRAG / NL2SPARQL 추가, redirect 통합.