CONSTRUCT query fails.
I am trying to issue a CONSTRUCT query. Shows me "sparql query failed". Does this node module support CONSTRUCT ? My endpoint is openrdf-sesame server. I checked my query from openrdf-workbench and it is working fine. However, when I try the same query from node application,it fails.
Sorry for my late answer.
Can you give an example of your CONSTRUCT query which failed?
Actually it should not fail, because it simply sends the given query to the endpoint and returns the result as is. If you got "sparql query failed" error this means that your endpoint returned an error or http status code is >= 300.
Ok - I have one, and a comment about the error handling. First, the query.
Submit this query to http://live.dbpedia.org/sparql :
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://dbpedia.org/resource/>
PREFIX d: <http://dbpedia.org/>
PREFIX do: <http://dbpedia.org/ontology/>
PREFIX yago: <http://dbpedia.org/class/yago/>
PREFIX dct: <http://purl.org/dc/terms/>
CONSTRUCT { ?Team rdfs:label ?TeamName;
:current_rostered_player ?Teammate.
}
WHERE {
BIND (:LeBron_James as ?Player)
?Player do:team ?Team;
do:termPeriod ?PlayerTermPeriod.
FILTER EXISTS {?PlayerTermPeriod do:activeYearsStartYear ?start}
FILTER NOT EXISTS {?PlayerTermPeriod do:activeYearsEndYear ?end}
?PlayerTermPeriod do:team ?Team.
?Teammate do:team ?Team;
do:termPeriod ?TeammateTermPeriod.
FILTER EXISTS {?TeammateTermPeriod do:activeYearsStartYear ?tm_start}
FILTER NOT EXISTS {?TeammateTermPeriod do:activeYearsEndYear ?tm_end}
?Teammate rdfs:label ?TeammateName.
Filter (lang(?TeammateName) = 'en')
?Team rdfs:label ?TeamName.
Filter (lang(?TeamName) = 'en')
}
ORDER BY ?TeammateName
You should get something like this:
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix dbpedia: <http://dbpedia.org/resource/> .
dbpedia:Cleveland_Cavaliers rdfs:label "Cleveland Cavaliers"@en ;
dbpedia:current_rostered_player dbpedia:Timofey_Mozgov ,
dbpedia:Matthew_Dellavedova ,
dbpedia:Kevin_Love ,
dbpedia:Kyrie_Irving ,
dbpedia:Iman_Shumpert ,
<http://dbpedia.org/resource/Anderson_Varej%C3%A3o> ,
<http://dbpedia.org/resource/Joe_Harris_(basketball)> ,
<http://dbpedia.org/resource/James_Jones_(basketball_player)> ,
dbpedia:Alex_Kirk ,
dbpedia:Anderson_Varejão ,
dbpedia:Mo_Williams ,
dbpedia:LeBron_James .
Try the same thing by pushing the query through sparql-client.
You're likely to see your node-red app crash, due to the error checking logic in sparql-client: the line
if (error || response.statusCode >= 300)
lets through cases where "error" is null and the statusCode is >= 300, and thus testing for
error.code == "ECONNREFUSED"
throws an exception due to the null "error". That's easily remedied by changing the test to
if (error && error.code == "ECONNREFUSED")
So, back to the problem, which is that the SPARQL endopoint, which responds fine in direct interaction at the dbpedia site, returns astatusCode of 400. Not sure where to look for other info, but I'm guessing it's something to do with either how the query is packaged and sent or a different manner by which the CONSTRUCT result is sent.
Let me know if there are other things to check.
UPDATE: Fuseki server is telling me that the error is:
400 Can't determine output content type: application/sparql-results+json
I've tried a few options in sparql-client but without a good outcome. Some combination of headers should a least send back a result.
UPDATE2: these header values seem to make the error conditions go away:
encoding: 'utf8',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/rdf+json'
}
};
var defaultParameters = {
format: 'application/rdf+json',
'content-type': 'application/sparql-results+json'
Still no result values, but perhaps they need to be handled differently.
Mark