2017-05-30 1 views
0

MESHオントロジーを照会したいと思っています。それは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> 

答えて

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");    

       } 
     } 

    } 
+0

が、それは便利だありがとうオントロジー内のデータの形式であります –

関連する問題