- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
基本上我有以下查询,它在所有在线 SPARQL 测试仪中都没有问题,但在使用 Java 和 Jena 2.6.4 时,我从未得到任何结果。出于演示目的,我已将这些值写入查询。
PREFIX g: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?subject ?stadium ?lat ?long
WHERE
{ ?subject g:lat ?lat .
?subject g:long ?long .
?subject <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> onto:Stadium .
?subject rdfs:label ?stadium
FILTER ( ( ( ( ( ?lat >= 52.4814 ) && ( ?lat <= 57.4814 ) ) && ( ?long >= -1.89358 ) ) && ( ?long <= 3.10642 ) ) && ( lang(?stadium) = "en" ) )
}
LIMIT 5
一些 Java,请注意,我已经尝试通过几种不同的方式访问它,但是我在整个项目中都使用 SPARQL,没有遇到任何问题。
Query query = QueryFactory.create(s2); //s2 = the query above
QueryExecution qExe = QueryExecutionFactory.create(query, model);
ResultSet resultsRes = qExe.execSelect();
try {
while (resultsRes.hasNext()) {
QuerySolution soln = resultsRes.nextSolution();
//never any results
}
} catch (Exception ex) {
System.out.println(ex);
}
最佳答案
除非您将整个 DBpedia 数据集加载到本地模型中,否则要获得与在 DBpedia SPARQL 表单中运行查询相同的效果,您必须将查询发送到 DBpedia SPARQL 端点。我对您的程序进行了以下修改:
package example;
import com.hp.hpl.jena.query.*;
public class AshTest
{
public static void main( String[] args ) {
String s2 = "PREFIX g: <http://www.w3.org/2003/01/geo/wgs84_pos#>\n" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"PREFIX onto: <http://dbpedia.org/ontology/>\n" +
"\n" +
"SELECT ?subject ?stadium ?lat ?long\n" +
"WHERE\n" +
" { ?subject g:lat ?lat .\n" +
" ?subject g:long ?long .\n" +
" ?subject <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> onto:Stadium .\n" +
" ?subject rdfs:label ?stadium\n" +
" FILTER ( ( ( ( ( ?lat >= 52.4814 ) && ( ?lat <= 57.4814 ) ) && ( ?long >= -1.89358 ) ) && ( ?long <= 3.10642 ) ) && ( lang(?stadium) = \"en\" ) )\n" +
" }\n" +
"LIMIT 5\n" +
"";
Query query = QueryFactory.create(s2); //s2 = the query above
QueryExecution qExe = QueryExecutionFactory.sparqlService( "http://dbpedia.org/sparql", query );
ResultSet results = qExe.execSelect();
ResultSetFormatter.out(System.out, results, query) ;
}
}
得到如下结果:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| subject | stadium | lat | long |
======================================================================================================================================================================================================================
| <http://dbpedia.org/resource/Welford_Road_Stadium> | "Welford Road Stadium"@en | "52.6242"^^<http://www.w3.org/2001/XMLSchema#float> | "-1.13306"^^<http://www.w3.org/2001/XMLSchema#float> |
| <http://dbpedia.org/resource/Hillsborough_Stadium> | "Hillsborough Stadium"@en | "53.4114"^^<http://www.w3.org/2001/XMLSchema#float> | "-1.50056"^^<http://www.w3.org/2001/XMLSchema#float> |
| <http://dbpedia.org/resource/Gateshead_International_Stadium> | "Gateshead International Stadium"@en | "54.9611"^^<http://www.w3.org/2001/XMLSchema#float> | "-1.57972"^^<http://www.w3.org/2001/XMLSchema#float> |
| <http://dbpedia.org/resource/Filbert_Street> | "Filbert Street"@en | "52.6236"^^<http://www.w3.org/2001/XMLSchema#float> | "-1.14056"^^<http://www.w3.org/2001/XMLSchema#float> |
| <http://dbpedia.org/resource/Craven_Park,_Hull> | "Craven Park, Hull"@en | "53.7539"^^<http://www.w3.org/2001/XMLSchema#float> | "-0.264722"^^<http://www.w3.org/2001/XMLSchema#float> |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
关于java - 使用 Jena 的 SPARQL 查询没有产生任何结果——但在线工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10626842/
我想用前缀来表示这个nt文件: . "a" . "b" . "c" . 我写入一个新的nt文件是: @prefix sp: . . "a" . "b" . "c"
我有一个名为 Modelling.owl 的 OWL 文件,它是使用 Protege 4.2 创建的。但是后来我必须通过使用 Jena 注册一些新的 Individual 和它的属性来修改它。例如我有
我正在尝试使用 Jena 写入本地免费的独立 GraphDB(版本 8.5.0)存储库。 我尝试过的 (1) 耶拿直接使用 我使用了这个 Jena 3.7.0 代码片段: String strInse
我无法在我的 Ontology 中表达以下情况: 假设我有四个人投票,投了四票(所以 vote 和 voter 之间存在一对一的映射)。人们可以投票赞成或反对。如果我知道三个人的投票结果,我应该能够推
我在我的项目中使用 Dbpedia,我想创建一个本地 sparql 端点,因为在线端点不可靠。我下载了数据转储(大型 NT 文件)并决定使用 Jena TDB。使用 NetBeans IDE,我使用输
我用这个java代码在jena中创建了一个模型 Model m = ModelFactory.createDefaultModel(); Resource a1 = m.createR
我有一个猫头鹰本体,我将它读入 Jena OntModel。然后我在运行时更新它。现在我想把它写回一个OWL 本体。我正在使用下面的代码: RDFWriter writer = model.getWr
我将 Jena 和 Fuseki 安装为服务使用 一个可靠的角色 gremid.fuseki . 而且我想自定义监听主机和监听端口。但是,我不知道。 也许我应该编辑$FUSEKI_BASE/confi
我正在对基于本体的上下文管理和基于流程的上下文管理进行性能分析。然而,为了创建与 PCM 案例研究类似的场景,我需要在推理过程中直接从 Jena SWRL 规则触发 Java 方法。我做了很多研究,但
我正在使用 SPARQL 查询查询整数结果: String qString = "SELECT (COUNT(?S) AS ?C) "+ "WHERE
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 8年前关闭。 Improve t
我无法找到一些使用 SWRL 和 Jena 的简单代码示例佩莱,或者至少使用 SWRL?我研究了 Pellet 文档中的一些示例,但没有关于使用 SWRL 的示例。网络上的大多数示例都不完整且令人困惑
我对 RDF 和 Jena 很陌生。我想将一个 .nt (N-TRIPLE) 文件加载到模型中。我试过 read(inputStream, "N-TRIPLE") 但没有帮助。 它抛出 org.apa
我成功地使用 Jena API 和 Eclipse 创建、修改、合并本体。我还在 Eclipse 中成功启动了 OWL 推理器和 Pellet 推理器。 现在我想了解如何使用 Jena API 在 E
我正在尝试使用 Jena 框架来编辑使用 Protoge 4.2 构建的现有本体。即更改属性值或添加个人或类别,然后进行推理。假设在本体中我们有这样的规则:hasAge(?p,?age)^swrlb:
我了解到您可以使用以下代码提取 rdf 文件并初始化为 jena 中的模型: DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(
我目前正在开发一个项目,初始值为 .owl包含我们本体的基本模式的文件。我们使用 Jena API 加载此文件并对其执行不同的操作,例如添加本体类和个体。 我们寻求将系统迁移到三重存储,这意味着,而不
这是我的代码: public class FunctionalityCheckTest1 { InfModel infModel; Model model = ModelFactory
我使用Jena和TDB来存储RDF,我想对其进行一些推断。但是RDF数据很大,Jena的owl reasoner必须将所有数据加载到内存中。 所以我想找到一个可以推理而不将所有数据加载到内存中的推理器
我建立了一个使用SWRL规则进行推理的本体。当我在Protege中执行SQWRL查询时,它工作正常。问题是,当我想将Pellet与Jena一起使用时,Pellet似乎在查询中不包括SWRL规则。我像这
我是一名优秀的程序员,十分优秀!