当前位置: 首页 > 知识库问答 >
问题:

如何使用TDB和reasoner配置Apache Jena Fuseki?删除数据集时出错

桑睿识
2023-03-14

尽管有很多关于这个问题的问题/答案,我仍然很难配置Apache Jena Fuseki。

我正在尝试配置一个Apache Jena Fuseki实例,并激活TDB和OWL reasoner,以测试我的应用程序。我需要创建一个数据集,执行我的测试,并以编程方式删除数据集。

我使用stain/jena-fusekidocker映像运行Apache Jena fuseki。

bash-4.3# ./fuseki-server -version
Jena:       VERSION: 3.10.0
Jena:       BUILD_DATE: 2018-12-30T15:45:57+0000
TDB:        VERSION: 3.10.0
TDB:        BUILD_DATE: 2018-12-30T15:45:57+0000
Fuseki:     VERSION: 3.10.0
Fuseki:     BUILD_DATE: 2018-12-30T15:45:57+0000
bash-4.3# cat /fuseki/shiro.ini 

[main]
# Development
ssl.enabled = false
plainMatcher=org.apache.shiro.authc.credential.SimpleCredentialsMatcher
iniRealm.credentialsMatcher = $plainMatcher

[users]
admin=mysupersecurepassword

[roles]

[urls]
## Control functions open to anyone
/$/status = anon
/$/ping   = anon

# Everything else
/**=anon
bash-4.3# cat /fuseki/config.ttl 
# Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0
## Fuseki Server configuration file.

@prefix :        <#> .
@prefix fuseki:  <http://jena.apache.org/fuseki#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .

[] rdf:type fuseki:Server ;
   .

为了测试我的应用程序,我尝试创建一个数据集,执行测试,并以编程方式删除数据集。为此,我使用Fuseki HTTP管理协议。

我遵循以下步骤:

  • 发布/$/datasets以创建数据集。
  • post/dataset_name/data上载数据文件。
  • (执行我的应用程序测试)
  • post/dataset_name?update=drop+all删除数据。
  • delete/$/datasets/dataset_name删除数据集。
curl -F 'files[]=@dataset.ttl' http://localhost:3030/$/datasets
@prefix fuseki: <http://jena.apache.org/fuseki#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix : <#> .


# Custom code
tdb:GraphTDB rdfs:subClassOf ja:Model .

# Setup service
:service rdf:type fuseki:Service ;
    rdfs:label                          "TDB dataset_name" ;
    fuseki:name                         "dataset_name" ;
    fuseki:dataset                      :dataset ;
    fuseki:serviceQuery                 "query", "sparql" ;
    fuseki:serviceUpdate                "update" ;
    fuseki:serviceUpload                "upload" ;
    fuseki:serviceReadWriteGraphStore   "data" ;
    fuseki:serviceReadGraphStore        "get" ;
.

# Setup Assembler model with reasoner
:dataset rdf:type ja:RDFDataset;
    ja:defaultGraph :modelInf ;
.
:modelInf rdf:type ja:InfModel;
    ja:baseModel :tdbGraph ;
    ja:reasoner [ 
        ja:reasonerURL <http://jena.hpl.hp.com/2003/OWLFBRuleReasoner> 
    ] ;
.

# TDB dataset used for RDF storage
:tdbGraph rdf:type tdb:GraphTDB;
    tdb:location "/fuseki/databases/dataset_name" ;
.

[2019-10-23 14:41:00] Admin      INFO  [6] POST http://localhost:3030/$/datasets
[2019-10-23 14:41:00] Admin      INFO  [6] Filename: dataset.ttl, Content-Type=application/octet-stream, Charset=null => Turtle : Count=19 Triples=19 Quads=0
[2019-10-23 14:41:00] Admin      INFO  [6] Create database : name = /dataset_name
[2019-10-23 14:41:02] Admin      INFO  [6] 200 OK (1.894 s)

一切正常:p

使用卷曲:

curl -F 'files[]=@data.rdf' http://localhost:3030/dataset_name/data
{ 
  "count" : 1524 ,
  "tripleCount" : 1524 ,
  "quadCount" : 0
}

Jena Fuseki原木

[2019-10-23 14:44:52] Fuseki     INFO  [7] POST http://localhost:3030/dataset_name/data
[2019-10-23 14:44:53] Fuseki     INFO  [7] Filename: data.rdf, Content-Type=application/octet-stream, Charset=null => RDF/XML : Count=1524 Triples=1524 Quads=0
[2019-10-23 14:44:54] Fuseki     INFO  [7] 200 OK (1.858 s)
curl -d "update=DROP+ALL" -X POST http://localhost:3030/dataset_name/update
...
Update succeeded
...
[2019-10-23 15:04:13] Fuseki     INFO  [67] POST http://localhost:3030/dataset_name/update
[2019-10-23 15:04:14] Fuseki     INFO  [67] 200 OK (268 ms)
curl -X DELETE http://localhost:3030/$/datasets/dataset_name
[2019-10-23 15:10:17] Admin      INFO  [92] DELETE http://localhost:3030/$/datasets/dataset_name
[2019-10-23 15:10:17] Admin      INFO  [92] DELETE ds=/dataset_name
[2019-10-23 15:10:17] Server     INFO  Shutting down data service for [, data, upload, query, get, update, sparql]
[2019-10-23 15:10:17] Admin      WARN  [92] RC = 500 : Not in a transaction
org.apache.jena.tdb.transaction.TDBTransactionException: Not in a transaction
        at org.apache.jena.tdb.transaction.DatasetGraphTransaction.get(DatasetGraphTransaction.java:140)
        at org.apache.jena.tdb.transaction.DatasetGraphTransaction.getDatasetGraphToQuery(DatasetGraphTransaction.java:86)
        at org.apache.jena.tdb.store.GraphTxnTDB.getDatasetGraphTDB(GraphTxnTDB.java:51)
        at org.apache.jena.tdb.store.GraphTDB.sync(GraphTDB.java:128)
        at org.apache.jena.tdb.store.GraphTDB.close(GraphTDB.java:133)
        at org.apache.jena.reasoner.BaseInfGraph.close(BaseInfGraph.java:445)
        at org.apache.jena.reasoner.rulesys.BasicForwardRuleInfGraph.close(BasicForwardRuleInfGraph.java:360)
        at org.apache.jena.reasoner.rulesys.FBRuleInfGraph.close(FBRuleInfGraph.java:710)
        at org.apache.jena.sparql.core.DatasetGraphMapLink.close(DatasetGraphMapLink.java:199)
        at org.apache.jena.fuseki.server.DataService.expel(DataService.java:223)
        at org.apache.jena.fuseki.server.DataService.shutdown(DataService.java:199)
        at org.apache.jena.fuseki.mgt.ActionDatasets.execDeleteItem(ActionDatasets.java:360)
        at org.apache.jena.fuseki.ctl.ActionContainerItem.execDelete(ActionContainerItem.java:105)
        at org.apache.jena.fuseki.ctl.ActionContainerItem.perform(ActionContainerItem.java:64)
        at org.apache.jena.fuseki.ctl.ActionCtl.executeLifecycle(ActionCtl.java:68)
        at org.apache.jena.fuseki.ctl.ActionCtl.executeAction(ActionCtl.java:62)
        at org.apache.jena.fuseki.ctl.ActionCtl.execCommonWorker(ActionCtl.java:53)
        at org.apache.jena.fuseki.servlets.ActionBase.doCommon(ActionBase.java:74)
        at org.apache.jena.fuseki.ctl.ActionContainerItem.doDelete(ActionContainerItem.java:52)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1655)
        at org.apache.jena.fuseki.servlets.FusekiFilter.doFilter(FusekiFilter.java:101)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
        at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
        at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
        at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
        at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
        at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
        at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
        at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
        at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
        at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
        at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
        at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
        at org.apache.jena.fuseki.servlets.CrossOriginFilter.handle(CrossOriginFilter.java:285)
        at org.apache.jena.fuseki.servlets.CrossOriginFilter.doFilter(CrossOriginFilter.java:248)
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
        at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:690)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
        at org.eclipse.jetty.server.Server.handle(Server.java:503)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
        at java.lang.Thread.run(Thread.java:745)
[2019-10-23 15:10:17] Admin      INFO  [92] 500 Not in a transaction (65 ms)

我用默认的数据集配置文件尝试相同的过程,没有错误。所以我认为这来自数据集配置文件。

这里是我所说的默认数据集配置文件

@prefix :      <http://base/#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix tdb2:  <http://jena.apache.org/2016/tdb#> .
@prefix ja:    <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix fuseki: <http://jena.apache.org/fuseki#> .

:service_tdb_all        a                   fuseki:Service ;
        rdfs:label                          "TDB2 dataset_name" ;
        fuseki:dataset                      :tdb_dataset_readwrite ;
        fuseki:name                         "dataset_name" ;
        fuseki:serviceQuery                 "query" , "sparql" ;
        fuseki:serviceReadGraphStore        "get" ;
        fuseki:serviceReadWriteGraphStore   "data" ;
        fuseki:serviceUpdate                "update" ;
        fuseki:serviceUpload                "upload" .

:tdb_dataset_readwrite  a                   tdb2:DatasetTDB2 ;
        tdb2:location                       "/fuseki/databases/dataset_name" .

我没有找到任何关于如何正确配置Jena Fuseki的文档。很多例子可以找到,但从一些年来,不知道他们是否仍然是最新的。也没有解释它们是如何真正起作用的,所以很难适用于具体的情况。

    null
@prefix : <#> .
@prefix fuseki: <http://jena.apache.org/fuseki#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> .
@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .

[] rdf:type fuseki:Server ;
    fuseki:services (
        <#service>
    ) .

## ---------------------------------------------------------------
## Service with only SPARQL query on an inference model.
## Inference model base data in TDB.

<#service> rdf:type fuseki:Service ;
    fuseki:name "dataset_name" ;
    fuseki:serviceQuery "query" , "sparql" ;
    fuseki:serviceUpdate "update" ;
    fuseki:serviceUpload "upload" ;
    fuseki:serviceReadWriteGraphStore "data" ;
    fuseki:serviceReadGraphStore "get" ;
    fuseki:dataset <#dataset>  ;
    .

<#dataset> rdf:type ja:RDFDataset ;
    ja:defaultGraph <#model> ;
    . 

<#model> rdf:type ja:InfModel ;
    ja:baseModel <#tdbGraph> ;
    ja:reasoner [
        ja:reasonerURL <http://jena.hpl.hp.com/2003/OWLFBRuleReasoner> ;
    ] ;
    .

<#tdbGraph> rdf:type tdb:GraphTDB ;
    tdb:dataset <#tdbDataset> ;
    .

<#tdbDataset> rdf:type tdb:DatasetTDB ;
    tdb:location "/fuseki/databases/dataset_name" ;
    .

步骤1出错。

Fuseki日志:

[2019-10-23 15:20:51] Admin      INFO  [93] POST http://localhost:3030/$/datasets
[2019-10-23 15:20:51] Admin      INFO  [93] Filename: dataset.ttl, Content-Type=text/turtle, Charset=null => Turtle : Count=23 Triples=23 Quads=0
[2019-10-23 15:20:51] Admin      INFO  [93] Create database : name = /dataset_name
[2019-10-23 15:20:51] Admin      WARN  [93] RC = 500 : cannot find a most specific type for :tdbGraph, which has as possibilities: ja:Model tdb:GraphTDB.
org.apache.jena.assembler.exceptions.AmbiguousSpecificTypeException: cannot find a most specific type for :tdbGraph, which has as possibilities: ja:Model tdb:GraphTDB.

共有1个答案

孔阎宝
2023-03-14

完整服务器为使用其中一个模板通过UI或协议创建的数据库提供delete。服务器推送的任意配置文件无法通过这种方式删除;即使它们可以与服务器解除链接,也可能会留下一些东西(它们是任意的assmbler文件),这对测试不利。

对于测试,有一种更简单的方法。为每个测试旋转一个服务器,无论是脚本的还是Java(JUnit等)的。“Fuseki Main”版本的服务器启动和停止相当快。因此,启动具有所需配置的服务器--如果数据相当小,您可以使用内存中的TDB数据库(位置为“--mem-”)来存储数据。

这将在服务器退出时完成clearup,使测试完全隔离。

 类似资料:
  • 问题内容: 我正在用Node.js和Mongoose准备数据库创建脚本。如何检查数据库是否已经存在,如果存在,请使用Mongoose删除(删除)该数据库? 我找不到一种将其与猫鼬放在一起的方法。 问题答案: 没有办法从猫鼬中删除一个集合,最好的办法是删除其中一个的内容: 但是有一种方法可以访问mongodb本机javascript驱动程序,该驱动程序可用于 警告 尝试备份之前进行备份,以防万一出问

  • 我在一个文件夹中有两个csv文件,如下所示:文件1: 文件 2: 我想从文件夹中读取文件,然后删除标题名称(col1,col2),然后将行更改为列,将列更改为行,这意味着转置它并将这两个文件合并到一个新的csv文件中,如下所示:

  • 我们可以通过以下查询删除所有节点和关系。 但是新创建的节点将内部id作为({最后一个节点内部id}+1)。它不会重置为零。 我们如何重置neo4j数据库,比如新创建的节点将获得id为0? 从2.3开始,我们可以删除所有有关系的节点,

  • 问题内容: 我当前的光泽配置设置如下所示: 并且想知道如何删除设置的 “ max_bytes_per_sec” 部分。 你能给我一个建议吗? 问题答案: 好的。我发现了如何删除持久性设置:您转到主节点的已定义数据路径,更具体地说(在我的情况下),然后删除全局状态文件。然后重新启动elasticsearch。

  • 我在编码方面是新手,所以我复制粘贴了一些教程的代码,但是当我试图删除“睡眠”列中的所有数据时,出现了这个错误。 Android数据库sqlite。SQLiteException:在“20170128”附近:编译时出现语法错误(代码1)::在android上从20170128删除。数据库sqlite。SQLiteConnection。android上的nativePrepareStatement(本

  • 问题内容: 我正在使用回收者视图和SQLite数据库创建一个应用程序。当用户输入一些数据时,它会显示在“回收者”视图中,并且还会添加到我的数据库中。现在,我想在回收者视图中实现功能。 我想要的是: 我想同时从数据库和回收者视图中删除所需的行,而不会得到任何意外结果。并且所有行均应删除。 我尝试过的 我实现了对回收视图(我使用cardView作为回收鉴于行)。现在,当使用它的长按时,我将获得适配器位