【问题标题】:Get RDF triples about an OWL Class in Jena获取有关耶拿 OWL 课程的 RDF 三元组
【发布时间】:2015-04-18 11:06:36
【问题描述】:

我正在尝试制作一个 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") .

或类似的东西

【问题讨论】:

    标签: rdf sparql jena semantic-web owl


    【解决方案1】:

    我不确定你为什么只提到了一个类,因为你还需要了解这些类的属性,以便能够制作语言器。如果您阅读整个 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 中要容易得多。您可以轻松提取所有内容。 Jena 在处理 OWL 文件时没有那么强大。

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 1970-01-01
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多