获取有关耶拿OWL班级的RDF三倍

时间:2015-04-18 11:06:37

标签: rdf sparql jena semantic-web owl

我想制作一个OWL动词来将本体转换为人类可读的文本。首先,我想参加一个OWL课程,并获得有关它的所有陈述。

例如,鉴于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") .

或类似的东西

1 个答案:

答案 0 :(得分: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不那么强大。