2015-04-18 60 views
0

我打算使OWL词汇表将本体论转换为可读的文本。一开始,我想采用OWL类并获取有关它的所有声明。在Jena获得有关OWL类的RDF三元组

例如,给定OWL类 “WhiteBurgundy”:

<owl:Class rdf:ID="WhiteBurgundy"> 
    <owl:intersectionOf rdf:parseType="Collection"> 
    <owl:Class rdf:about="#Burgundy" /> 
    <owl:Class rdf:about="#WhiteWine" /> 
    </owl:intersectionOf> 
</owl:Class> 

我想获得的三元组:

("WhiteBurgundy", "isfrom" , ""#Burgundy") .

("WhiteBurgundy", "isa" , ""#WhiteWine") .

或类似的东西

回答

0

我我不知道为什么你只提到了一个类,因为你还需要知道这些类的属性,这些类是通过定义的,以便能够使用口头语言。如果你读完整个OWL文件,然后提取你需要的东西,那可能会提供更多的信息。例如,我试图提取类的两个名称和属性:

public static void main(String[] args) { 
    //create the reasoning model using the base 
    OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM); 
    String file = "Ontology" + File.separator + "pizza.owl"; 

    InputStream in; 
    try { 
     in = new FileInputStream(file); 
     model.read(in, "RDF/XML"); 
     in.close(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } // or any windows path 


    // Create a new query 
    String queryString =   
      "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "+ 
        "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "+ 
        "PREFIX owl: <http://www.w3.org/2002/07/owl#> "+ 
        "select distinct * "+ 
        "where { "+ 
        "?s a owl:Class."+ 
        "?s rdfs:subClassOf ?o ."+ 
        "?o owl:onProperty ?y ."+ 
        "?o owl:someValuesFrom|owl:allValuesFrom ?z ."+ 

        "} \n "; 
    Query query = QueryFactory.create(queryString); 

    // Execute the query and obtain results 
    QueryExecution qe = QueryExecutionFactory.create(query, model); 
    ResultSet results = qe.execSelect(); 

    // Output query results  
    ResultSetFormatter.out(System.out, results, query); 

} 

然而,这很容易在OWL API完成。你可以很容易地提取一切。在处理OWL文件时,Jena并不强大。