如何解决dotNetRdf 方法 UpdateGraph 在 Virtuoso 服务器上不成功
我在 linux 机器上有一个 Virtuoso-Server(我“继承”了它,所以我没有自己设置它)。我还继承了连接到服务器的 OntoWiki 前端来操作数据。由于这有点笨拙且非常手动,因此我编写了一个 C# 项目来访问和显示数据。我使用 dotNetRdf 访问数据。读取没问题,但是现在我也想更新数据,于是使用了UpdateGraph方法。为了对此进行测试,我在 dotNetRdf-Website 的这个示例之后编写了一个小型测试项目:https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Triple-Store-Integration#updategraph
这是我的实现。
VirtuosoManager _virtuosoManager = new VirtuosoManager(ServerAddress,ServerPort,VirtuosoManager.DefaultDB,_user,_password);
string _graphName = "http://od.fmi.uni-leipzig.de/example";
Graph _graph = new Graph();
_virtuosoManager.LoadGraph(_graph,_graphName);
INode s = _graph.CreateUriNode(new Uri(_graphName + "/test"));
INode p = _graph.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
INode o = _graph.CreateUriNode(new Uri("http://example.org/Example"));
Triple t = new Triple(s,p,o);
_virtuosoManager.UpdateGraph(_graphName,new List<Triple>() { t },null);
此代码运行时没有错误,但图表中也没有任何更新(我使用以下 SPARQL-Request 检查)
SELECT * WHERE {GRAPH ?g {<http://od.fmi.uni-leipzig.de/example/test> ?p ?o .}}
什么都不返回。
因此,我更改了服务器上的日志级别,以查看服务器如何/是否收到我的请求。我在日志文件中发现了以下几行:
...
15:47:16 cslQ_0 109 xxx.xxx.xxx.xxx 1113:2 s1113_2_1 SPARQL define output:format '_JAVA_' INSERT DATA
INTO <http://od.fmi.uni-leipzig.de/example>
{
<http://od.fmi.uni-leipzig.de/example/test> a <http://example.org/Example> .
}
15:47:16 COMP_2 109 xxx.xxx.xxx.xxx 1113:2 Compile text: SPARQL define output:format '_JAVA_' INSERT
DATA
INTO <http://od.fmi.uni-leipzig.de/example>
{
<http://od.fmi.uni-leipzig.de/example/test> a <http://example.org/Example> .
}
15:47:16 EXEC_1 109 xxx.xxx.xxx.xxx 1113:2 s1113_2_1 Exec 1 time(s) SPARQL define output:format
'_JAVA_' INSERT DATA
INTO <http://od.fmi.uni-leipzig.de/example>
{
<http://od.fmi.uni-leipzig.de/example/test> a <http://example.org/Example> .
}
看起来我的请求已到达并已计算。尽管如此,三重还是缺失的。您知道要检查/更改请求或服务器以使其工作吗?
更新: 对于 dotNetRdf 的 VirtuosoManager,还有另一种称为“更新”的方法,您可以在其中向 Endpoint 发送 SPARQL-Query。所以我用 Server-Log 中的 SPARQL-Query 进行了尝试:
string query = "INSERT DATA " + Environment.NewLine +
"INTO <http://od.fmi.uni-leipzig.de/example>" + Environment.NewLine +
"{" + Environment.NewLine +
"<http://od.fmi.uni-leipzig.de/example/test> a <http://example.org/Example> ." + Environment.NewLine +
"}";
_virtuosoManager.Update(query);
并且三元组被插入到数据库中!所以这似乎是(我使用的)dotNetRdf 的 UpdateGraph() 方法的问题。所以,我有一种解决方法,但我更愿意省略容易出错的 Triple=>SPARQL 转换,并将其留给 dotNetRdf 的专业人员(他们可能在 UpdateGraph() 方法中执行此操作)。
这是请求的服务器日志:
13:45:58 cslQ_0 109 xxx.xxx.xxx.xxx 1113:2 s1113_2_0 SPARQL INSERT DATA
INTO <http://od.fmi.uni-leipzig.de/example>
{
<http://od.fmi.uni-leipzig.de/example/test> a <http://example.org/Example> .
}
13:45:58 COMP_2 109 xxx.xxx.xxx.xxx 1113:2 Compile text: SPARQL INSERT DATA
INTO <http://od.fmi.uni-leipzig.de/example>
{
<http://od.fmi.uni-leipzig.de/example/test> a <http://example.org/Example> .
}
13:45:58 EXEC_1 109 xxx.xxx.xxx.xxx 1113:2 s1113_2_0 Exec 1 time(s) SPARQL INSERT DATA
INTO <http://od.fmi.uni-leipzig.de/example>
{
<http://od.fmi.uni-leipzig.de/example/test> a <http://example.org/Example> .
}
如您所见,不同之处在于
定义输出:格式'JAVA'
对于失败的调用。
提前致谢,
弗兰克
解决方法
作为 answered on the dotNetRDF issue —
我认为 output:format
不是这里的问题。问题是更新事务不是由您拥有的代码提交的。这样做的方法是在 Dispose()
上调用 _virtuosoManager
方法。因此,将更新包装在 using()
块中是最好的方法:
using(var _virtuosoManager = new VirtuosoManager(...)) {
// Call one or more update methods
}
或者,您也可以显式调用 Dispose()
(例如,如果您要将管理器实例包装在另一个类中)。
并得到提问者的确认——
非常感谢您的回复,确实解决了我的问题! (我使用了 .Dispose()
)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。