gpt4 book ai didi

java - Sparql 删除语句 Jena OWL

转载 作者:行者123 更新时间:2023-12-02 03:41:19 24 4
gpt4 key购买 nike

我正在尝试删除所有三元组,我有这些函数,

类变量

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””。期待其中之一: “字首” ... “选择” ... “描述” ... “ build ”... “问”...

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 秒)

如何创建删除语句?

最佳答案

SPARQL 更新请求不是查询。

您需要使用更新 API:请参阅 UpdateExecutionFactory

关于java - Sparql 删除语句 Jena OWL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36807101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com