我使用OpenRdf与Sparql一起从DBPedia收集数据,但在针对DBPedia Sparql端点运行的以下查询中遇到一些错误:
CONSTRUCT{
?battle ?relation ?data .
}
WHERE{
?battle rdf:type yago:Battle100953559 ;
?relation ?data .
FILTER(?relation != owl:sameAs)
}
LIMIT 1
OFFSET 18177我修改了限制并进行了偏移,指出了引发问题的具体结果。
答复是:
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ns1: <http://en.wikipedia.org/wiki/> .
<http://dbpedia.org/resource/Mongol%E2%80%93Jin_Dynasty_War> foaf:isPrimaryTopicOf ns1:Mongol–Jin_Dynasty_War .问题是,ns1:Mongol_Jin_War实体包含一个减号,因此,在使用OpenRdf在Java应用程序中运行此查询时,我会得到以下异常:
org.openrdf.query.QueryEvaluationException: org.openrdf.rio.RDFParseException:期望'.',找到‘-’第3行
有什么办法可以绕过这个问题吗?
谢谢!
发布于 2015-03-12 15:41:04
为了帮助其他可能遇到同样问题的用户,我将在这里发布使用OpenRDF v2.7.x设置图形查询首选输出格式的方法。
您需要创建一个SPARQLRepository子类来访问HTTPClient (出于某种原因,该字段是protected。
public class NtripleSPARQLRepository extends SPARQLRepository {
public NtripleSPARQLRepository(String endpointUrl) {
super(endpointUrl);
this.getHTTPClient().setPreferredRDFFormat(RDFFormat.NTRIPLES);
}
}您只需要创建这个类的一个新实例:
NtripleSPARQLRepository repository = new NtripleSPARQLRepository(service);
RepositoryConnection connection = new SPARQLConnection(repository);
Query query = connection.prepareQuery(QueryLanguage.SPARQL, "YOUR_QUERY");发布于 2015-05-12 04:43:43
如果您正在查询Virtuoso服务器,那么您很可能在Virtuoso的实现中遇到了懒散的问题。我在获得XML结果(输出中的垂直选项卡,但只有XML1.0),最近在JSON结果中看到了这种情况(不是基本的多语言平面中字符的转义)。
https://stackoverflow.com/questions/29011016
复制相似问题