35

SHACL 기초: Shape, Target, Constraint

SHACL 데이터 검증 & 오픈 온톨로지

학습 목표

SHACL의 3대 구성 요소를 설명할 수 있다 NodeShape와 PropertyShape를 구분하고 작성할 수 있다 주요 제약 조건을 적용할 수 있다 Validation Report를 읽고 위반 사항을 식별할 수 있다

SHACL 기초: Shape, Target, Constraint

학습 목표

  • SHACL의 3대 구성 요소(Shape, Target, Constraint)를 설명할 수 있다
  • NodeShape와 PropertyShape의 차이를 구분한다
  • 주요 제약 조건(datatype, minCount, maxCount, pattern, in)을 작성할 수 있다
  • Validation Report를 읽고 위반 사항을 식별할 수 있다

SHACL이란?

SHACL = Shapes Constraint Language

  • W3C 표준 (2017년 권고)
  • RDF 데이터의 "검증 규칙"을 정의하는 언어
  • 비유: JSON Schema가 JSON을 검증하듯, SHACL이 RDF를 검증
에디터 로딩 중...

SHACL의 3대 구성 요소

에디터 로딩 중...

1. Target (대상 지정)

검증할 노드를 지정합니다:

Target 유형설명예시
sh:targetClass특정 클래스의 모든 인스턴스sh:targetClass schema:Person
sh:targetNode특정 개별 노드sh:targetNode ex:Alice
sh:targetSubjectsOf특정 프로퍼티의 주어sh:targetSubjectsOf foaf:name
sh:targetObjectsOf특정 프로퍼티의 목적어sh:targetObjectsOf schema:author
에디터 로딩 중...

2. Shape (모양 정의)

NodeShape: 노드 전체에 대한 제약

에디터 로딩 중...

PropertyShape: 개별 프로퍼티에 대한 제약

에디터 로딩 중...

3. Constraint (제약 조건)

값 타입 제약

제약설명예시
sh:datatype데이터 타입 지정sh:datatype xsd:string
sh:class클래스 타입 지정sh:class schema:Organization
sh:nodeKind노드 종류sh:nodeKind sh:IRI (URI여야 함)

카디널리티 제약

제약설명예시
sh:minCount최소 값 개수sh:minCount 1 (필수)
sh:maxCount최대 값 개수sh:maxCount 1 (단일 값)

값 범위 제약

제약설명예시
sh:minInclusive최소값 (이상)sh:minInclusive 0
sh:maxInclusive최대값 (이하)sh:maxInclusive 150
sh:minExclusive초과sh:minExclusive 0
sh:maxExclusive미만sh:maxExclusive 200

문자열 제약

제약설명예시
sh:minLength최소 길이sh:minLength 2
sh:maxLength최대 길이sh:maxLength 100
sh:pattern정규표현식sh:pattern "^[A-Z]"

열거형 제약

제약설명예시
sh:in허용 값 목록sh:in ("male" "female" "other")
sh:hasValue반드시 포함sh:hasValue "active"

완전한 SHACL 예시: 직원 관리

에디터 로딩 중...

Validation Report 읽기

SHACL 검증 결과는 Validation Report로 반환됩니다:

에디터 로딩 중...

심각도(Severity) 3단계

심각도의미데이터 거부?
sh:Violation규칙 위반 (기본값)
sh:Warning경고 (권장 사항)아니오
sh:Info정보 (참고용)아니오
에디터 로딩 중...

SHACL vs OWL 비교 정리

에디터 로딩 중...

📖 심화 읽기: W3C SHACL Specification — https://www.w3.org/TR/shacl/

핵심 포인트
  • SHACL = W3C 표준 데이터 검증 언어 (Shapes Constraint Language)
  • 3대 구성 요소: Target(대상), Shape(모양), Constraint(제약)
  • NodeShape는 노드 전체, PropertyShape는 개별 프로퍼티 검증
  • sh:datatype, sh:minCount, sh:maxCount, sh:pattern, sh:in이 핵심 제약
  • Validation Report: sh:conforms true/false로 검증 결과 확인
  • OWL(추론)과 SHACL(검증)은 상호 보완적으로 함께 사용