我正在尝试删除所有三元组,我有这些功能,
类变量
public static String defaultNameSpace = "http://www.semanticweb.org/admin/ontologies/2016/3/Inventory#";
public Model Inventario = null;
public Model schema = null;
public String DatabaseFile = "PR2INVENTARIORDFXML.owl";
public OutputStream output;
public ResultSet runQuery(String queryRequest, Model model)
{
StringBuffer queryStr = new StringBuffer();
ResultSet response = null;
// Establish Prefixes
//Set default Name space first
queryStr.append("PREFIX base: <" + defaultNameSpace + "> ");
queryStr.append("PREFIX rdfs: <" + "http://www.w3.org/2000/01/rdf-schema#" + "> ");
queryStr.append("PREFIX rdf: <" + "http://www.w3.org/1999/02/22-rdf-syntax-ns#" + "> ");
queryStr.append("PREFIX owl: <http://www.w3.org/2002/07/owl#>");
//Now add query
queryStr.append(queryRequest);
Query query = QueryFactory.create(queryStr.toString());
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try
{
response = qexec.execSelect();
}
finally { }
return response;
}
我有每个查询的函数,这是一个例子
public ResultSet AllRecords(Model model)
{
return runQuery("select ?s ?p ?o where{?s ?p ?o."
+ "} " , model);
}
当我尝试运行这些查询时
public ResultSet BorrarPC(Model model)
{
return runQuery("DELETE {base:PC1 ?p ?o} " +
"WHERE {base:PC1 ?p ?o}" +
"" , model);
}
public ResultSet eraseAllTriples(Model model)
{
return runQuery("DELETE {?s ?p ?o} " +
"WHERE {?s ?p ?o}" +
"" , model);
}
它给了我这些错误
run:
线程“main”中的异常com.hp.hpl.jena.query.QueryParseException:在第1行第233列遇到“”delete“”DELETE“”。 期待以下之一: “字首” ... “选择” ... “描述”...... “构建”...... “问”......
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:87)
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse(ParserSPARQL11.java:40)
at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:132)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:69)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:28)
at explorerowlexample.FinalProject.runQuery(FinalProject.java:146)
at explorerowlexample.FinalProject.BorrarPC(FinalProject.java:90)
at explorerowlexample.FinalProject.main(FinalProject.java:56)
Java结果:1 建立成功(总时间:5秒)
如何创建删除声明?
答案 0 :(得分:2)
SPARQL更新请求不是查询。
您需要使用更新API:请参阅UpdateExecutionFactory
。