目录

 

基础知识

RDF Formats

开源库

JENA

简介

OWLAPI

简介

OWLAPI使用

 

工具

protege

简介


基础知识

知识图谱基础之RDF, RDFS与OWL 通俗易懂

OWL的基础知识, 譬如复杂类(Complex Class, unionOf, intersectionOf, complementOf)

OWL 本体构建指南 内容详细, 解释准确

RDF Formats

ExtensionLanguage
.ttlTurtle
.ntN-Triples
.nqN-Quads
.trigTriG
.rdfRDF/XML
.owlRDF/XML
.jsonldJSON-LD
.trdfRDF Thrift
.rtRDF Thrift
.rjRDF/JSON
.trixTriX

开源库

JENA

简介

A free and open source java framework for building Semantic Web and Linked Data applications.

文档详细

OWLAPI

简介

The OWL API is a java API for creating, manipulating and serialising OWL Ontologies

文档少, 且老旧.使用起来难度挺大.

OWLAPI使用

  • IRI
owlOntology.getOntologyID().getOntologyIRI()
result = {Present@8453} "Optional.of(https://brickschema.org/schema/1.1/Brick)"
  reference = {IRI@8455} "https://brickschema.org/schema/1.1/Brick"
    remainder = "Brick"
    namespace = "https://brickschema.org/schema/1.1/"

IRIremindernamespace组成

  • 导入ttl
OWLOntologyManager owlOntologyManager = OWLManager.createOWLOntologyManager();
OWLOntology owlOntology = owlOntologyManager.loadOntologyFromOntologyDocument(ttl.getInputStream());
  • 获取class

升级到5.0版本之后, 获取OWLClass的接口更改为classesInSignature(), 而且此函数返回的是stream()流.

List<OWLClass> owlClasses = owlOntology.classesInSignature().collect(Collectors.toList());
  • 获取OWLClass下的rdfs:labe
List<String> labels = owlOntology.annotationAssertionAxioms(owlClass.getIRI())
                //get only the annotations with rdf Label property
                .filter(axiom -> axiom.getProperty().getIRI().getIRIString().equals(OWLRDFVocabulary.RDFS_LABEL.getIRI().getIRIString()))
                .map(axiom -> axiom.getAnnotation())
                .filter(annotation-> annotation.getValue() instanceof OWLLiteral)
                .map(annotation -> (OWLLiteral) annotation.getValue())
                .map(literal -> literal.getLiteral())
                .collect(Collectors.toList());
  • Reasoner HermiT

简介: 

HermiT is reasoner for ontologies written using the Web Ontology Language (OWL). Given an OWL file, HermiT can determine whether or not the ontology is consistent, identify subsumption relationships between classes, and much more. 

版本配合:

OWLAPIHermiT
5.1.01.3.8.510

安装:

(1) Maven

<dependency>
  <groupId>net.sourceforge.owlapi</groupId>
  <artifactId>org.semanticweb.hermit</artifactId>
  <version>1.3.8.510</version>
  <type>bundle</type>
</dependency>

(2) Jar包安装

下载安装包, 在控制台输入以下命令进行安装, 前提是maven已安装

mvn install:install-file -Dfile=.\org.semanticweb.hermit-1.3.8.510.jar -DgroupId=net.sourceforge.owlapi -DartifactId=org.semanticweb.hermit -Dversion=1.3.8.510 -Dpackaging=jar

使用

(1) 获取OWLClass的subClasses

OWLReasonerFactory owlReasonerFactory = new ReasonerFactory();
OWLReasoner owlReasoner = owlReasonerFactory.createReasoner(owlOntology);
owlReasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY);
List<OWLClass> owlClasses = owlOntology.classesInSignature().collect(Collectors.toList());
owlClasses.forEach(owlClass -> {
    owlReasoner.getSubClasses(owlClass, false).forEach(System.out::println);
});

 

工具

protege

简介

A free, open-source ontology editor and framework for building intellignet systems.

使用web工具导入Ontology,可以辅助理解知识图谱的概念.

 

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐