COMPETENCY_QUESTIONS=["What antibiotics treat strep throat?","Which drugs interact with warfarin?",]defevaluate_ontology(graph,questions):return{q:bool(graph.query(translate_to_sparql(q)))forqinquestions}
KG-based RAG (LLM + ontology lookup)
defkg_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)returnllm.generate(f"Answer using facts:\n{facts}\nQ: {question}")
Ontology-driven relevancy filter
deffilter_docs_by_ontology(docs:list[str],target_concept:str,kg)->list[str]:# tag each doc with concepts via NER + ontology mappingrelevant_concepts=set(kg.descendants_of(target_concept))return[dfordindocsifrelevant_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 기반 평가.