1

Adding triplets to 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 }");

why does not it work?

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();

another way, same problem. Created a DB on a lokalka


Yes, I also came to this conclusion, I use GraphDB for the first time. Well, how can I implement it with a file? I wrote such code.

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

here comes such an error

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

judging by mistake, I supposedly did not add BASE / PREFIX. But he is in the request

Jonas W
  • 3,200
  • 1
  • 31
  • 44
Denis8388
  • 21
  • 3
  • 2
    " same problem"...what problem exactly? You need to tell us the problem before we can try to fix it! – ADyson Apr 23 '20 at 08:30
  • ` VDS.RDF.Query.RdfQueryException HResult=0x80131500 Сообщение = A HTTP Error occurred while trying to make the SPARQL Query, see inner exception for details Источник = dotNetRDF Трассировка стека: в VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultSet(ISparqlResultsHandler handler, String sparqlQuery) в VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultSet(String sparqlQuery) в algorAutoText.Program.Main(String[] args) в C:\Users\Денис\source\repos\Program.cs:строка 98 Внутреннее исключение 1: WebException: Удаленный сервер возвратил ошибку: (404) Не найден.` – Denis8388 Apr 23 '20 at 08:37
  • 1
    Ok thanks but: 1) Please put the details into your original question. Code, error messages, details etc do not belong in the comments. You can use the "edit" button (just under the blue "c#" and "rdf" tags) to change your question and add this information. 2) Please translate any exception messages into English, as this is an English-speaking site only. (P.S. If you speak Russian, there is also a [Stack Overflow на русском](https://ru.stackoverflow.com/) you can use instead, if you prefer.) – ADyson Apr 23 '20 at 08:39
  • Anyway from as much as I can see, your request to localhost:7200 seems to be returning a 404 Not Found error. This means your URL is wrong, or that the sparql server is not installed properly. Unfortunately we cannot see your environment, so it's not easy for us to know what the correct URL should be, or how the server is configured. – ADyson Apr 23 '20 at 08:41
  • 2
    Most likely, the main problem is wrong URI. See e.g. this question: https://stackoverflow.com/a/46283806/7879193 – Stanislav Kralin Apr 23 '20 at 09:01
  • 2
    wrong request URL, please read the docs – UninformedUser Apr 23 '20 at 09:09
  • My code does not accept ""SparqlResultSet"" for writing, what should I use instead? – Denis8388 Apr 23 '20 at 10:07
  • writing to what? – UninformedUser Apr 25 '20 at 14:04

2 Answers2

0

Update and delete queries come through the /statements endpoint,

i.e. /repositories/{repository_id}/statements.

You can see the RDF4J server REST API here:

http://docs.rdf4j.org/rest-api/#_the_rdf4j_server_rest_api

Sava Savov
  • 551
  • 2
  • 4
0

When you use the DELETE or INSERT keywords you are doing a SPARQL Update, not a Query. SPARQL separates Query and Update into two separate specifications and most triple stores implement them as two separate endpoints (e.g. for security reasons).

To do an update from dotNetRDF into a triple store you have two options.

  1. You can work directly with the SPARQL update endpoint in which case you will need to check the documentation for your triple store to find out how to create the URL for that - see https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Updating-With-SPARQL#remote-updates for details.

  2. Alternatively if your triple store is one of the ones supported by dotNetRDF (Stardog and Sesame/GraphDB both are), then there are convenience wrappers that make this a bit easier - for more information about this please refer to https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Triple-Store-Integration#update

Kal
  • 1,887
  • 12
  • 16