如何用C#编写代码,向数据库中添加新的数据。

问题描述 投票:0回答:1

向GraphDB添加三联体

SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("http://localhost:7200/sparql"), "http://localhost:7200/");
SparqlResultSet results = endpoint.QueryWithResultSet("PREFIX : <http://www.example.org/> INSERT DATA {:test :test :hhrh }");

为什么不工作?

StardogConnector stardog = new StardogConnector("http://localhost:7200", "test", "admin", "posw");
stardog.Begin();
string query = "PREFIX : <http://www.example.org/>SELECT * WHERE {:" + line[0] + " ?k :" + line[1] + "}";
stardog.Query(query);
stardog.Commit();

另一种方式,同样的问题。在一个lokalka上创建了一个DB


是的,我也得出了这个结论,我是第一次使用GraphDB。那么,如何用一个文件来实现呢?我写了这样的代码。

IGraph g = new Graph();

string sql = "PREFIX : <http://www.example.org/> INSERT DATA {:test :test :hhrh }";
g.LoadFromFile("t.n3"); 

Object results = g.ExecuteQuery(sql);

就出现了这样一个错误

VDS.RDF.Parsing.RdfParseException
HResult = 0x80131500
Message = [InsertKeywordToken at Line 1 Column 36 to Line 1 Column 42] Unexpected Token encountered - expected a BASE / PREFIX directive or a Query Keyword to start a Query
Source = dotNetRDF
Stack trace:
in VDS.RDF.Parsing.SparqlQueryParser.ParseInternal (SparqlQueryParserContext context)
in VDS.RDF.Parsing.SparqlQueryParser.ParseInternal (TextReader input)
in VDS.RDF.Parsing.SparqlQueryParser.ParseFromString (String queryString)
in VDS.RDF.GraphExtensions.ExecuteQuery (IGraph g, String sparqlQuery)
in algorAutoText.Program.Main (String [] args) in C: \ Users \ Denis \ source \ repos \ algorAutoText \ algorAutoText \ Program.cs: line 43

判断错误,我应该是没有加BASE PREFIX。但他在请求中

c# sparql rdf graphdb dotnetrdf
1个回答
0
投票

更新和删除查询通过语句endpoint来实现。

即: /repositories/{repository_id}/statements.

你可以在这里看到RDF4J服务器的REST API。

http:/docs.rdf4j.orgrest-api#_the_rdf4j_server_rest_api。


0
投票

当你使用DELETE或INSERT关键字时,你正在做一个SPARQL 更新,而不是Query。SPARQL将Query和Update分离成两个独立的规范,大多数triple store将它们作为两个独立的端点来实现(例如出于安全原因)。

要从dotNetRDF更新到triple store,你有两个选择。

  1. 您可以直接使用SPARQL更新端点,在这种情况下,您需要检查您的三重存储的文档,以找出如何为其创建URL--请参阅 https:/github.comdotnetrdfdotnetrdfwikiUserGuid-Updating-With-SPARQL#remot-updates。 了解更多信息。

  2. 另外,如果你的三重存储是dotNetRDF支持的存储之一(Stardog和SesameGraphDB都支持),那么有一些方便的包装器可以让这一切变得更容易--关于这一点的更多信息,请参见 https:/github.comdotnetrdfdotnetrdfwikiUserGuid-Triple-Store-Integration#update。

© www.soinside.com 2019 - 2024. All rights reserved.