From 470280a7b75896291de383ee5e86506673f9713a Mon Sep 17 00:00:00 2001 From: "Hofstetter Benjamin (extern)" Date: Wed, 27 Mar 2024 15:48:25 +0100 Subject: [PATCH] fix issue 74 --- samples/issues.sparqlbook | 14 ++++++++++++++ src/extension/endpoint/sparql-utils.ts | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 samples/issues.sparqlbook diff --git a/samples/issues.sparqlbook b/samples/issues.sparqlbook new file mode 100644 index 0000000..65b050c --- /dev/null +++ b/samples/issues.sparqlbook @@ -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: \nPREFIX rdf: \n\nfrom \nselect *\nWHERE \n{ \n BIND( AS ?cube)\n ?cube rdf:type cube:Cube\n}\n", + "metadata": {} + } +] \ No newline at end of file diff --git a/src/extension/endpoint/sparql-utils.ts b/src/extension/endpoint/sparql-utils.ts index 088aaa2..57c43ec 100644 --- a/src/extension/endpoint/sparql-utils.ts +++ b/src/extension/endpoint/sparql-utils.ts @@ -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;