繁体   English   中英

相同的Sparql使用不同的程序会产生不同的结果

[英]Same Sparql with different result using different programs

我将TopBraid用作IDE和Java中的Jena。 对于相同的SPARQL查询和相同的文件,我得到两个不同的结果集。 本体可以在这里找到, https://dl.dropboxusercontent.com/u/108022472/ontology.owl

SPARQL是:

select ?individual ?type ?label where {
  ?individual rdf:type ?type .
  ?individual rdfs:label ?label
  filter (?type in (wo:Kingdom))
}

我的Java代码:

public class ExeSparql {
    static String prefix = "PREFIX owl: <http://www.w3.org/2002/07/owl#> " +
            "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " +
            "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
            "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
            "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/> " +
            "PREFIX : <http://dbpedia.org/resource/> " +
            "PREFIX dbpedia2: <http://dbpedia.org/property/> " +
            "PREFIX wo:<http://purl.org/ontology/wo/>" +
            "PREFIX dbpedia: <http://dbpedia.org/> ";

    public static ResultSet execute(String queryString){
        queryString = prefix + queryString;
        Model model = null;
        try {
            InputStream in = new FileInputStream(new File("/home/noor/TBCMEWorkspace/recreate/index.rdf"));
            // Create an empty in-memory model and populate it from the graph
            model = ModelFactory.createOntologyModel();
            model.read(in,null); // null base URI, since model URIs are absolute
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Query query = QueryFactory.create(queryString);
        // Execute the query and obtain results
        QueryExecution qe = QueryExecutionFactory.create(query, model);
        ResultSet results = qe.execSelect();
        ResultSetFormatter.out(System.out, results, query);
        //qe = QueryExecutionFactory.create(query, model);
        //results = qe.execSelect();
        return results;
    }
}

耶拿代码有什么问题吗? 使用topbraid,结果很好,而使用Jena,结果是错误的。

结果应该是:

| wo:王国| “动物” | | | wo:王国| “动物”

但是使用耶拿,它会返回错误类型的结果集

我已经尝试使用您提供的数据执行此查询(我必须添加前缀):

prefix wo: <http://purl.org/ontology/wo/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select ?individual ?type ?label where {
  ?individual rdf:type ?type .
  ?individual rdfs:label ?label
  filter (?type in (wo:Kingdom))
}

我使用耶拿的命令行arq运行查询,结果如下:

$ arq --query query.sparql --data ontology.owl 
-------------------------------------------------------------------
| individual                            | type       | label      |
===================================================================
| <file:/nature/life/Animal#kingdom>    | wo:Kingdom | "Animals"  |
| <file:/nature/kingdom/Animal#kingdom> | wo:Kingdom | "animalia" |
-------------------------------------------------------------------

耶拿(2.10.0)和ARQ(2.10.0)的版本如下:

$ arq --version
Jena:       VERSION: 2.10.0
Jena:       BUILD_DATE: 2013-02-20T12:04:26+0000
ARQ:        VERSION: 2.10.0
ARQ:        BUILD_DATE: 2013-02-20T12:04:26+0000

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM