---
id: wiki-2026-0508-semantics-ontology
title: "Semantics & Ontology"
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Formal Semantics, Knowledge Ontology, Semantic Web]
duplicate_of: none
source_trust_level: A
confidence_score: 0.88
verification_status: applied
tags: [semantics, ontology, knowledge-representation, kg, owl, rdf]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: python / SPARQL / Turtle
  framework: rdflib / owlready2 / Neo4j
---

# Semantics & Ontology

## 매 한 줄
> **"매 semantics 는 의미의 formal mapping, ontology 는 그 mapping 의 schema"**. Tarski (1933) 의 model theory 에서 출발해 매 W3C OWL2 (2012), 그리고 2026 의 Neuro-symbolic LLM (Anthropic Constitutional AI graph, OpenAI memory ontology) 까지. 매 LLM hallucination 억제와 grounded reasoning 의 backbone.

## 매 핵심

### 매 Semantics — 3 layers
- **Lexical**: token → concept (WordNet, BabelNet, ConceptNet 5.7).
- **Compositional**: phrase 의 구조 → Montague-style λ-calculus, dependent types.
- **Referential**: expression → world entity (Kripke 의 possible-world, 매 LLM 의 entity-linking).

### 매 Ontology stack
- **RDF**: subject–predicate–object triple.
- **RDFS**: class hierarchy, domain/range.
- **OWL2**: description-logic (SROIQ) — 매 reasoning decidable.
- **SHACL/ShEx**: data-shape validation — 매 schema-as-constraints.
- **SPARQL 1.1**: query language.

### 매 Modern (2026)
- **Knowledge Graph**: Wikidata 102M items, Google KG, schema.org.
- **LLM-grounded**: Mem0, Zep, Anthropic Memory ontology — 매 entity/relation extraction → KG → context retrieval.
- **Neuro-symbolic**: AlphaProof, GraphRAG (Microsoft 2024), Neo4j-LLM Graph Builder.

### 매 응용
1. RAG over structured knowledge (GraphRAG).
2. Agent memory (Mem0, LangGraph state).
3. Compliance / Healthcare (SNOMED-CT, FHIR ontology).
4. E-commerce schema.org / product KG.

## 💻 패턴

### RDF triple in Turtle
```turtle
@prefix : <https://wiki.local/> .
@prefix schema: <https://schema.org/> .

:claude-opus-4-7 a schema:SoftwareApplication ;
    schema:name "Claude Opus 4.7" ;
    schema:creator :anthropic ;
    schema:datePublished "2026-04" .
```

### SPARQL query
```sparql
PREFIX schema: <https://schema.org/>
SELECT ?model ?date WHERE {
  ?model a schema:SoftwareApplication ;
         schema:creator <https://wiki.local/anthropic> ;
         schema:datePublished ?date .
  FILTER (?date >= "2026-01"^^xsd:gYearMonth)
} ORDER BY DESC(?date)
```

### rdflib programmatic graph
```python
from rdflib import Graph, Namespace, Literal, URIRef

W = Namespace("https://wiki.local/")
g = Graph()
g.bind("w", W)
g.add((W.claude, W.author, W.anthropic))
g.add((W.anthropic, W.label, Literal("Anthropic")))
g.serialize("kg.ttl", format="turtle")
```

### OWL class with owlready2
```python
from owlready2 import Thing, ObjectProperty, get_ontology

onto = get_ontology("https://wiki.local/onto.owl")
with onto:
    class Model(Thing): pass
    class Org(Thing): pass
    class created_by(ObjectProperty):
        domain = [Model]; range = [Org]

    claude = Model("Claude_Opus_4_7")
    anthropic = Org("Anthropic")
    claude.created_by = [anthropic]

onto.save("onto.owl")
```

### Pydantic-based lightweight schema (LLM extraction)
```python
from pydantic import BaseModel, Field
from typing import Literal

class Entity(BaseModel):
    id: str
    type: Literal["Model", "Org", "Paper"]
    name: str

class Relation(BaseModel):
    subj: str; pred: str; obj: str
    confidence: float = Field(ge=0, le=1)

class KGFragment(BaseModel):
    entities: list[Entity]
    relations: list[Relation]
```

### Cypher (Neo4j 5.x)
```cypher
MERGE (m:Model {id: "claude-opus-4-7"})
  ON CREATE SET m.name = "Claude Opus 4.7"
MERGE (o:Org {id: "anthropic"})
MERGE (m)-[:CREATED_BY]->(o);

MATCH (m:Model)-[:CREATED_BY]->(o:Org {id: "anthropic"})
RETURN m ORDER BY m.released DESC LIMIT 10;
```

### GraphRAG retrieval (LangChain 0.3+ pseudocode)
```python
from langchain_neo4j import Neo4jGraph
from langchain.chains import GraphCypherQAChain

graph = Neo4jGraph()
chain = GraphCypherQAChain.from_llm(llm=claude, graph=graph, verbose=False)
chain.invoke("Which models did Anthropic release in 2026?")
```

## 매 결정 기준

| 상황 | Approach |
|---|---|
| Open-world web data | RDF + OWL |
| Tight schema + queries | Property graph (Neo4j) |
| LLM agent memory | Mem0 / Zep + light schema |
| Healthcare / compliance | SNOMED + FHIR |
| Reasoning required | OWL2 EL/RL profile |
| Quick prototype | Pydantic class hierarchy |

**기본값**: LLM-era 에는 Property Graph (Neo4j) + Pydantic schema + LLM extractor 가 매 pragmatic — full OWL stack 은 regulated domain 한정.

## 🔗 Graph
- 부모: [[Knowledge-Structure]] · [[Knowledge-Graph-Foundations]]
- 변형: [[Ontology]] · [[Knowledge Graph]]
- 응용: [[Information Retrieval (IR)]] · [[Theoretical-Computer-Science]]
- Adjacent: [[Pragmatics]] · [[Linguistics_and_Communication]]

## 🤖 LLM 활용
**언제**: agent long-term memory, GraphRAG, structured extraction, regulated-domain reasoning.
**언제 X**: small-scale prompts, transient chat, free-form creative gen.

## ❌ 안티패턴
- **OWL Full reasoning 요구**: 매 undecidable — EL/QL/RL profile 만 사용.
- **Schema 없이 KG 만 쌓기**: 매 garbage-in, query 불가.
- **LLM-extracted triple 의 unverified ingestion**: 매 confidence threshold + human sample 필수.
- **Ontology 의 over-engineering**: 매 6-month 후 누구도 안 쓰는 abstract class hierarchy.

## 🧪 검증 / 검토
- Verified (W3C OWL2 Primer 2012; Hogan et al. "Knowledge Graphs" ACM Comput. Surv. 2021; Microsoft GraphRAG 2024 paper).
- 신뢰도 A.

## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — semantics layers, ontology stack, GraphRAG/Neo4j/Mem0 modern context, RDF/SPARQL/Cypher patterns |
