我想查询MESH Ontology,它包含超过281776个类。 我希望有所有与“牙科”这个词有关的课程 我该如何用java Jena编写查询? 这是本体中数据的形式
<!-- http://bioonto.de/mesh.owl#D003813 -->
<owl:Class rdf:about="http://bioonto.de/mesh.owl#D003813">
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Dentistry</rdfs:label>
<rdfs:subClassOf rdf:resource="http://bioonto.de/mesh.owl#E06"/>
<rdfs:subClassOf rdf:resource="http://bioonto.de/mesh.owl#H02.163"/>
</owl:Class>
<!-- http://bioonto.de/mesh.owl#D003814 -->
<owl:Class rdf:about="http://bioonto.de/mesh.owl#D003814">
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Dentistry, Operative</rdfs:label>
<rdfs:subClassOf rdf:resource="http://bioonto.de/mesh.owl#E06.323"/>
<rdfs:subClassOf rdf:resource="http://bioonto.de/mesh.owl#H02.163.180"/>
</owl:Class>
<!-- http://bioonto.de/mesh.owl#D003815 -->
<owl:Class rdf:about="http://bioonto.de/mesh.owl#D003815">
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Dentists</rdfs:label>
<rdfs:subClassOf rdf:resource="http://bioonto.de/mesh.owl#M01.526.485.330"/>
<rdfs:subClassOf rdf:resource="http://bioonto.de/mesh.owl#N02.360.330"/>
</owl:Class>
答案 0 :(得分:1)
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import java.io.InputStream;
public class Test {
// absolute path to your owl file
static final String inputFileName = "path and file name";
public static void main (String [] args) {
// creating ontology model without reasoner specification
OntModel model = ModelFactory.createOntologyModel();
// opening input owl file
InputStream in = FileManager.get().open(inputFileName);
// reading input owl file
model.read(in, "");
// getting all classes
ExtendedIterator classes = model.listClasses();
//iterating classes
while (classes.hasNext()) {
OntClass cls = (OntClass) classes.next();
// getting local class name - without prefix
String className = cls.getLocalName();
// case sensitive string containment check
if (className.contains("dentistry"));
System.out.print(className + "\n");
}
}
}