我使用org.openrdf.rio.trig.TriGWriter创建SPARQL update查询。我的查询需要采用以下格式:
PREFIX ....
PREFIX ....
insert data{
graph <....../id>{}
graph <....../id>{}
graph <....../id>{}
}但我现在得到的是:
PREFIX ....
PREFIX ....
insert data{
graph <....../id>
@prefix ...
@prefix ...
{....}
graph <....../id>
@prefix ...
@prefix ...
{....}
graph <....../id>
@prefix ...
@prefix ...
{....}
}前缀与TriGWriter.startRDF()和TriGWriter.endRDF()调用相关。我想取消所有带有@前缀的行。我希望有一种干净利落的方法来做这件事,而不是在他们已经在那里的时候把他们弄出来。我正在查看TriGWriter.closeActiveContext()调用,但是没有得到好的结果。任何帮助都将不胜感激。
下面是生成我的sparql的代码:
def rdfWriter = new org.openrdf.rio.trig.TriGWriter(updateWriter);
rdfWriter.startRDF();
rdfWriter.handleNamespace("dc","http://purl.org/dc/terms/");
rdfWriter.handleNamespace("mrss","http://search.yahoo.com/mrss/");
rdfWriter.handleNamespace("xsd","http://www.w3.org/2001/XMLSchema#");
rdfWriter.handleNamespace("owl","http://www.w3.org/2002/07/owl#");
rdfWriter.handleNamespace("sesame","http://www.openrdf.org/schema/sesame#");
rdfWriter.endRDF();
updateWriter.getBuffer().setLength(resetLength);
it = map.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pair = (Map.Entry)it.next();
rdfWriter.startRDF();
"""GRAPH <${camelContext.getRegistry().lookup('context')}content/${pair.getKey()}>""".writeTo(updateWriter);
def graph = pair.getValue();
graph.each{
rdfWriter.handleStatement(it);
}
rdfWriter.endRDF();
}
updateWriter.append("${lsp} }; ${lsp}");发布于 2015-07-20 13:02:41
TriGWriter真的不是为这种事情而设计的。它编写TriG文档,而不是SPARQL update语句,虽然它们表面上相似,但在语法方面却不同(正如您已经发现的那样)。我认为您最好使用自己的简单RDFHandler实现,在这种实现中,您实际上只需要实现handleStatement。
然而,如果您坚持使用TriGWriter,您可以做的是创建一个TriGWriter的子类,在其中覆盖handleNamespace方法,使其成为一个简单的无操作。这样,编写器将永远不会编写前缀映射,也永远不会使用前缀名称而不是IRIs。
https://stackoverflow.com/questions/31482277
复制相似问题