java错误代码查询_在Java代码中调用SPARQL查询(在DBPedia上)时出现HttpException错误...

本文探讨了使用Java进行SPARQL查询时遇到的问题,包括异常错误和Virtuoso返回的错误信息,并提供了具体的查询代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我对使用Java代码的SPARQL端点有问题。

特别是,我有这个Java类:

public class example {

public static void main(String[] args) {

String value = "http://dbpedia.org/resource/Fred_Guy";

example exam = example();

QueryExecution qe = exam.query(value);

ResultSet results = ResultSetFactory.copyResults( qe.execSelect() );

}

public QueryExecution query(String stringa){

ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +

"prefix dbpediaont: \n" +

"prefix rdf: \n" +

"\n" +

"select ?resource where {\n" +

"?mat rdf:type ?resource\n" +

"filter strstarts(str(?resource), dbpediaont:)\n" +

"}" );

Resource risorsa = ResourceFactory.createResource(stringa);

qs.setParam( "mat", risorsa );

QueryExecution exec = QueryExecutionFactory.sparqlService( "http://dbpedia.org/sparql", qs.asQuery() );

ResultSet results = ResultSetFactory.copyResults( exec.execSelect() );

while ( results.hasNext() ) {

System.out.println( results.next().get( "resource" ));

}

// A simpler way of printing the results.

ResultSetFormatter.out( results );

return exec;

}

}

我想检索谓词为“ RDF:type” 的资源“

http://dbpedia.org/resource/Fred_Guy ”

的对象。但是我有一个我不明白的错误:

Exception in thread "main" HttpException: 500

at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:340)

at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:276)

at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:345)

at MyPackage.example.main(example.java:19)

为什么会出现此错误?

我正在尝试执行此查询

没有写strstarts,我得到这个错误:

Virtuoso 37000 Error SP031: SPARQL compiler: No one quad map pattern is suitable for GRAPH { "http://dbpedia.org/resource/Fred_Guy" ?resource } triple at line 7

SPARQL query:

define sql:big-data-const 0

#output-format:text/html

define sql:signal-void-variables 1 define input:default-graph-uri prefix dbpediaont:

prefix rdf:

select ?resource where {

"http://dbpedia.org/resource/Fred_Guy" rdf:type ?resource

}

我在这里做错了什么?

我试图用Virtuoso编写以下代码:

prefix dbpediaont:

prefix rdf:

select ?resource where {

dbpedia:Fred_Guy rdf:type ?resource

}

如何用耶拿代码编写?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值