Pom需要添加的依赖:
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>3.9.0</version>
</dependency>
对于.owl文件,需要分析他的结构
<owl:Class rdf:about="http://www.owl-ontologies.com/Ontology1540950082.owl#吊瓜">
<owl:equivalentClass rdf:resource="http://www.owl-ontologies.com/Ontology1540950082.owl#黄瓜"/>
<rdfs:subClassOf rdf:resource="http://www.owl-ontologies.com/Ontology1540950082.owl#果菜类作物"/>
<rdfs:subClassOf rdf:resource="http://www.owl-ontologies.com/Ontology1540950082.owl#蔬菜类作物"/>
</owl:Class>
其中,Class代表吊瓜这种类,equivalentClass代表吊瓜的同名类,subClass0f代表吊瓜和黄瓜的上一级分类
首先创建一个本体模型
package com.example.demo.owlread;
import org.apache.jena.ontology.*;
import org.apache.jena.rdf.model.ModelFactory;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class OWLSearch2 {
private static OntModel createOnt(String owlpath) throws Fil