gpt4 book ai didi

java - Jena 未从导入的 RDF 文件加载数据

转载 作者:行者123 更新时间:2023-11-30 04:25:57 24 4
gpt4 key购买 nike

我有一个在 TopBraid 中加载的 RDF 文件,我还从网络导入了一些 RDF 文件。最后,我保存了基本文件并检查其代码以确保它包含导入语句。

<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://www.bbc.co.uk/nature/life/Bird"/>
<owl:imports rdf:resource="http://www.bbc.co.uk/nature/life/Animal"/>
<owl:imports rdf:resource="http://www.bbc.co.uk/nature/life/Chordate"/>
<owl:imports rdf:resource="http://www.bbc.co.uk/nature/kingdom"/>
</owl:Ontology>

所以,这就是文件,当我执行下面的 sparql 时,我得到了结果:

PREFIX wo:<http://purl.org/ontology/wo/>
SELECT *
WHERE {
?subject wo:kingdom ?object .
}

但是,当我与 Jena 使用相同的文件时,我没有得到任何结果,看来 Jena 没有考虑导入:

// Open the bloggers RDF graph from the filesystem
InputStream in = new FileInputStream(new File("/home/noor/TBCMEWorkspace/bbc/index.rdf"));

// Create an empty in-memory model and populate it from the graph
Model model = ModelFactory.createMemModelMaker().createFreshModel();
model.read(in,null); // null base URI, since model URIs are absolute
in.close();

// Create a new query
String queryString = "PREFIX wo:<http://purl.org/ontology/wo/>" +
" SELECT * " +
" WHERE { " +
" ?subject ?x ?object . " +
" } ";

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

// Important - free up resources used running the query
qe.close();

有什么办法让耶拿考虑进口吗?

最佳答案

普通的 Jena 模型不会加载导入的 OWL 模型,但 OntModel将要。基本的 Jena 模型旨在处理 RDF(即包括 OWL,但也包括 RDF 的其他用途),而本体 API 中的 OntModel 专门设计用于处理 OWL 和其他本体。

关于java - Jena 未从导入的 RDF 文件加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15868824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com