Skip to content

Commit

Permalink
Merge pull request #75 from zazuko:BenjaminHofstetter/issue74
Browse files Browse the repository at this point in the history
fix issue 74
  • Loading branch information
BenjaminHofstetter authored Mar 27, 2024
2 parents 06ef038 + 470280a commit ee041e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
14 changes: 14 additions & 0 deletions samples/issues.sparqlbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"kind": 1,
"language": "markdown",
"value": "# Using FROM clause yields 'Unknown query type' #74\n\n## Error\nSPARQL error: Unknown query type\n\n## Cause\nThe notebook tries to guess the query type in order to set the HTTP ACCEPT header. Because some stores return a SPO SPARQL JSON result for construct queries and we want turtle.\n\nThe notebook ignores comment and empty lines, so the first non-empty line should be a construct, select, ask, or describe.\n\nThis test is not enough. \n\n## Solution\n\nAt the moment we don't want to parse the query with SPARQLjs. To be store / sparql flavour agnostic. \n",
"metadata": {}
},
{
"kind": 2,
"language": "sparql",
"value": "PREFIX cube: <https://cube.link/>\nPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n\nfrom <https://lindas.admin.ch/foen/cube>\nselect *\nWHERE \n{ \n BIND(<https://environment.ld.admin.ch/foen/ubd000502/1> AS ?cube)\n ?cube rdf:type cube:Cube\n}\n",
"metadata": {}
}
]
15 changes: 14 additions & 1 deletion src/extension/endpoint/sparql-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ export function getSPARQLQueryKind(query: string): SPARQLQueryKind {
const linesWithoutPrefix = linesWithoutCommentsAndEmpty.filter(line => {
return !line.startsWith('prefix');
});
const firstLine = linesWithoutPrefix[0];
const lineWithQueryKind = linesWithoutPrefix.filter(line => {
return line.startsWith(SPARQLQueryKind.select) ||
line.startsWith(SPARQLQueryKind.construct) ||
line.startsWith(SPARQLQueryKind.describe) ||
line.startsWith(SPARQLQueryKind.ask) ||
line.startsWith(SPARQLQueryKind.update) ||
line.startsWith(SPARQLQueryKind.load) ||
line.startsWith(SPARQLQueryKind.clear) ||
line.startsWith(SPARQLQueryKind.drop) ||
line.startsWith(SPARQLQueryKind.create) ||
line.startsWith(SPARQLQueryKind.json);
}
);
const firstLine = lineWithQueryKind[0];
if (firstLine !== undefined) {
if (firstLine.startsWith(SPARQLQueryKind.select)) {
return SPARQLQueryKind.select;
Expand Down

0 comments on commit ee041e6

Please sign in to comment.