OpenRefine / SparqlExtension

Extension which lets you create an OpenRefine project from a SPARQL query
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

Query other endpoints #12

Closed WaltonG closed 2 years ago

WaltonG commented 2 years ago

Hi @antoine2711 Am working on querying other endpoints. My solution is to retrieve the user provided endpoint from the textarea then export the endpoint variable from sparql-source-ui.js to Sparql.js. However am getting the error Uncaught SyntaxError: Unexpected token 'export' from the following line

https://github.com/OpenRefine/SparqlExtension/blob/1108e29325682575614f915393e05344b90eefee/module/scripts/index/sparql-source-ui.js#L20

I found this solution online but it doesnt solve the problem. To solve the "Uncaught SyntaxError Unexpected token 'export'" error, set the type property to module in your package.json file. Files ending with a .js extension are loaded as ES6 modules when the nearest package.json has a type field set to module.

The following line also gives the error Uncaught SyntaxError: Cannot use import statement outside a module

https://github.com/OpenRefine/SparqlExtension/blob/1108e29325682575614f915393e05344b90eefee/module/scripts/index/wikidata/Sparql.js#L8

WaltonG commented 2 years ago

@antoine2711 I thought of moving Sparql.js code to sparql-source-ui.js. as a function but the following line gives me the error api.query(...) is not a function

https://github.com/OpenRefine/SparqlExtension/blob/8892c0945f28eea0f5d12d88b5c4761e20a89478/module/scripts/index/sparql-source-ui.js#L27

antoine2711 commented 2 years ago

@antoine2711 I thought of moving Sparql.js code to sparql-source-ui.js. as a function but the following line gives me the error api.query(...) is not a function

Yes, because you drop the newhttps://github.com/OpenRefine/SparqlExtension/blob/8892c0945f28eea0f5d12d88b5c4761e20a89478/module/scripts/index/sparql-source-ui.js#L24

antoine2711 commented 2 years ago

@WaltonG : I fixed it, here the line: https://github.com/OpenRefine/SparqlExtension/blob/6e254eaf14823617b3540a8ad8124b501aca2aac/module/scripts/index/sparql-source-ui.js#L24

EDIT: The Sparql property of the object wikibase.queryService.api returns a function which is actually an object description. So, the new operator instantiate a new object of type wikibase.queryService.api, and we can send the parameters of the constructor: https://github.com/OpenRefine/SparqlExtension/blob/6e254eaf14823617b3540a8ad8124b501aca2aac/module/scripts/index/wikidata/Sparql.js#L40

You can also define the language. We could send the userLang to the querier. Maybe add a popmenu for a few choices? ;-)

Regards, Antoine

WaltonG commented 2 years ago

@antoine2711 Thank you for the fix and clear explanation of the logic