PREFIXES not accepted in Neptune SPARQL update query.

0

I am getting inconsistent behavior from Neptune when using SPARQL endpoint and the UPDATE parameter

This succeeds:

number, ip1:38314, ip2:8182, HTTP_POST, [unknown], [unknown], "HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 653, cap: 653, components=1)) POST /sparql? HTTP/1.1 Accept-Encoding: identity Host:<neptune endpoint>:8182 User-Agent: Python-urllib/3.7 Accept: application/sparql-results+xml, application/rdf+xml Content-Type: application/sparql-update Connection: close content-length: 653", "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX xml: <http://www.w3.org/XML/1998/namespace> 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#> INSERT DATA { GRAPH <GRAP_URI> { <NS1:person--4c49da7e> a <http://xmlns.com/foaf/0.1/Person>, owl:NamedIndividual; <http://xmlns.com/foaf/0.1/firstName> 'John'; <http://xmlns.com/foaf/0.1/family_name> 'Snow'; <http://xmlns.com/foaf/0.1/workplaceHomepage> 'http://example.com' . } }"

While this fails:

number2, ip:37738, ip2:8182, HTTP_POST, [unknown], [unknown], "HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 703, cap: 703, components=1)) POST /sparql? HTTP/1.1 Accept-Encoding: identity Host: <neptune endpoint>:8182 User-Agent: Python-urllib/3.7 Accept: application/sparql-results+xml, application/rdf+xml Content-Type: application/sparql-update Connection: close content-length: 703", "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX xml: <http://www.w3.org/XML/1998/namespace> 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 flows: <NS1#> INSERT DATA { GRAPH <GRAPH_URI> { <flows:person--4c49da7e> a <http://xmlns.com/foaf/0.1/Person>, <http://www.w3.org/2002/07/owl#NamedIndividual>; <http://xmlns.com/foaf/0.1/firstName> 'John'; <http://xmlns.com/foaf/0.1/family_name> 'Snow'; <http://xmlns.com/foaf/0.1/workplaceHomepage> 'http://example.com' . } }"

Adding a single Prefix (whether a unique one such as PREFIX flows: <NS1#> in the example, or even just PREFIX owl: <http://www.w3.org/2002/07/owl#> will cause a 400 BAD REQUEST error.

I am running these using rdflib 6.x in python. The general execution code is:

from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore
from rdflib import Graph

store = SPARQLUpdateStore()
store.open((<neptune_endpoint>, <neptune_endpoint>))
ng = Graph(store, identifier="GRAPH_URI")
query = """#optionally put prefix here for testing
INSERT DATA
{
  <NS1:person--4c49da73> a <http://xmlns.com/foaf/0.1/Person>, owl:NamedIndividual;
      <http://xmlns.com/foaf/0.1/firstName> "John";
      <http://xmlns.com/foaf/0.1/family_name> "Snow";
      <http://xmlns.com/foaf/0.1/workplaceHomepage> "http://example.com" .
}"""

As far as I can tell from the SPARQL update documentation (https://www.w3.org/TR/sparql11-update/#insert), the prefixes should work.

EDIT: fixed some issues due to copying/anonymization that were not SPARQL compliant.

  • (as a side note, I tried calling the endpoint directly with python requests, but either the sparql protocol parameter using-named-graph-uri is ignored or there's some other issue because it was accepted with a 200 response but the triples aren't in the named graph.)

  • what is the exact named graph you are specifying?

  • @charivie The name of the named graph varies, but is always of the form "graph--<UUID>".

Gabe
질문됨 일 년 전305회 조회
2개 답변
0

The syntax of your second example query is incorrect for a couple of reasons.

See here:

.... PREFIX flows: <NS1#> INSERT DATA { GRAPH <GRAPH_URI> { flows#person--4c49da7e> a <http://xmlns.com/foaf/0.1/Person> ...
  1. <NS1#> is not a valid Namespace in RDF. Namespaces are IRI's, and as such need to have a ":" character to be valid, for example: <NS:1>
  2. flows#person--4c49da7e> is neither a full URI enclosed in "<>" or a use of the namespace "flows" as it does not have a ":" following the reference to 'flows.'

A valid query could be:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX xml: <http://www.w3.org/XML/1998/namespace> 
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 flows: <NS1:> 
INSERT DATA { 
    GRAPH <GRAPH:URI> { 
        flows:person--4c49da7e a <http://xmlns.com/foaf/0.1/Person>, 
                                  <http://www.w3.org/2002/07/owl#NamedIndividual>; 
                        <http://xmlns.com/foaf/0.1/firstName> 'John'; 
                        <http://xmlns.com/foaf/0.1/family_name> 'Snow'; 
                        <http://xmlns.com/foaf/0.1/workplaceHomepage> 'http://example.com' . 
                        } 
                        
                } 
답변함 일 년 전
0

Yeah, I apologize. I was copying the queries over by hand from another computer and manually redacting the neptune logs. The queries themselves are valid (as they are accepted by Neptune) so any errors are in my transposition.

Gabe
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인