Search code examples
ruby-on-railssparqlapache-jena

Perform an INSERT in Jena Fuseki with SPARQL gem (Ruby)


So I'm developing an API in Rails and using Jena Fuseki to store triples, and right now I'm trying to perform an INSERT in a named graph. The query is correct, since I ran it on Jena and worked perfectly. However, no matter what I do when using the Rails CLI, I keep getting the same error message:

SPARQL::Client::MalformedQuery: Error 400: SPARQL Update: No 'update=' parameter

I've created a method that takes the parameters of the object I'm trying to insert, and specified the graph where I want them.

def self.insert_taxon(uri, label, comment, subclass_of)
  endpoint = SPARQL::Client.new("http://app.talkiu.com:8030/talkiutest/update")
  query =
     "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
      PREFIX owl: <http://www.w3.org/2002/07/owl#>
      PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
      prefix gpc:<http://www.ebusiness-unibw.org/ontologies/pcs2owl/gpc/>
      prefix tk: <www.web-experto.com.ar/ontology#>

      INSERT DATA {
        GRAPH <http://app.talkiu.com:8030/talkiutest/data/talkiu> {
          <#{uri}> a owl:Class.
          <#{uri}> rdfs:label '#{label}'@es .
          <#{uri}> rdfs:comment '#{comment}' .
          <#{uri}> rdfs:subClassOf <#{subclass_of}> .
        }
      }"
  resultset = endpoint.query(query)
end 

As you can see, I'm using the UPDATE endpoint. Any ideas? Thanks in advance


Solution

  • Well... Instead of endpoint.query, I tried

    resultset = endpoint.update(query)
    

    and worked. Method returned

    <SPARQL::Client:0x2b0158a050e4(http://app.talkiu.com:8030/talkiutest/update)> 
    

    and the data is showing up in my database and graph. Hope this helps anyone with the same problem.