---
id: wiki-2026-0508-ontology-engineering
title: Ontology Engineering
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Ontology Engineering, Ontological Engineering, Ontology-Driven Relevancy Filtering, OWL Modeling]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [ontology, owl, rdf, sparql, knowledge-graph, protege, semantic-web, kg-rag]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack: { language: python/turtle, framework: 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) 도메인 모델
```turtle
@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 — 동적 클래스 정의 + 추론
```python
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)
```python
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 → 평가
```python
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)
```python
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
```python
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

- 부모: [[Knowledge Representation]], [[Semantic-Web]]
- 변형: [[Knowledge-Graphs]]
- Adjacent: [[OWL]], [[RDF]], [[GraphRAG]]

## 🤖 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로 축약.

## 🧪 검증 / 중복

- 검증: HermiT/ELK consistency check, SHACL validation, competency Q coverage, FAIR 점수.
- 중복: [[Ontology-Engineering|Ontological-Engineering]], [[Ontology-Driven-Relevancy-Filtering]] → 본 문서로 redirect.

## 🕓 Changelog

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