Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to dereference relative URIs in jsonld #21

Open
derwehr opened this issue Nov 4, 2020 · 8 comments
Open

Error when trying to dereference relative URIs in jsonld #21

derwehr opened this issue Nov 4, 2020 · 8 comments

Comments

@derwehr
Copy link

derwehr commented Nov 4, 2020

Expected Behavior

The jsonld is loaded into the urdf store and then queried

Current Behavior

Upon loading urdf reports the following error and stops:

(node:38682) UnhandledPromiseRejectionWarning: jsonld.InvalidUrl: Dereferencing a URL did not result in a valid JSON-LD object. Possible causes are an inaccessible URL perhaps due to a same-origin policy (ensure the server uses CORS if you are using client-side JavaScript), too many redirects, a non-JSON response, or more than one HTTP Link Header was provided for a remote context.
    at Promise.all.queue.map (/home/wehr/workspace/uRDF.js/node_modules/jsonld/lib/context.js:1000:15)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Steps to Reproduce

1. Create data and context files

Create a file (called data.jsonld in this example) with the following content:

{"@context":"./context.jsonld","id":"","type":"History"}

and a file (called context.jsonld in this example) with the content:

{
    "@context": {
        "id": "@id",
        "type": "@type"
    }
}

2. Host the files locally

Host the 2 files from 1. locally. For example with apache

3. Create a query file

create a file (called query.sparqle in this example) with the following content:

PREFIX sosa: <http://www.w3.org/ns/sosa/>

SELECT ?s
FROM <http://localhost/data.jsonld>
WHERE 
{
    ?obs sosa:madeBySensor ?s .
}

Execute the query with urdf

From within the urdf directory, run the following command to execute the query:
npm run urdf query query.sparql

Context (Environment)

We are trying to use urdf to query the jsonld returned by the sc-ble-adapter.
A simliar issue has been resolved in the urdf browser (kianschmalenbach/rdf-browser#11)

@aharth
Copy link

aharth commented Feb 23, 2021

Any news?

@vcharpenay
Copy link
Owner

I get the error if my local server doesn't set Content-Type: application/ld+json.

When I add that header, URIs are properly resolved.

@aharth
Copy link

aharth commented Feb 24, 2021

Hm, then something strange is going on.

$ npm run urdf query query.rq 

> [email protected] urdf
> node src/cli.js "query" "query.rq"
(node:5754) UnhandledPromiseRejectionWarning: jsonld.InvalidUrl: Dereferencing a URL did not result in a valid JSON-LD object. Possible causes are an inaccessible URL perhaps due to a same-origin policy (ensure the server uses CORS if you are using client-side JavaScript), too many redirects, a non-JSON response, or more than one HTTP Link Header was provided for a remote context.
    at /tmp/uRDF.js/node_modules/jsonld/lib/context.js:1000:15
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:5754) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:5754) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
$
$ curl -v "http://localhost/data.jsonld" > /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying ::1:80...
* Connected to localhost (::1) port 80 (#0)
> GET /data.jsonld HTTP/1.1
> Host: localhost
> User-Agent: curl/7.74.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Wed, 24 Feb 2021 22:36:53 GMT
< Server: Apache/2.4.46 (Debian)
< Last-Modified: Wed, 24 Feb 2021 22:35:07 GMT
< ETag: "38-5bc1ca59efe88"
< Accept-Ranges: bytes
< Content-Length: 56
< Access-Control-Allow-Origin: *
< Content-Type: application/ld+json
< 
{ [56 bytes data]
100    56  100    56    0     0  28000      0 --:--:-- --:--:-- --:--:-- 28000
* Connection #0 to host localhost left intact
$ curl -v "http://localhost/context.jsonld" > /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying ::1:80...
* Connected to localhost (::1) port 80 (#0)
> GET /context.jsonld HTTP/1.1
> Host: localhost
> User-Agent: curl/7.74.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Wed, 24 Feb 2021 22:37:08 GMT
< Server: Apache/2.4.46 (Debian)
< Last-Modified: Wed, 24 Feb 2021 22:35:17 GMT
< ETag: "48-5bc1ca632b3e4"
< Accept-Ranges: bytes
< Content-Length: 72
< Access-Control-Allow-Origin: *
< Content-Type: application/ld+json
< 
{ [72 bytes data]
100    72  100    72    0     0  36000      0 --:--:-- --:--:-- --:--:-- 72000
* Connection #0 to host localhost left intact
$ 

When I change data.jsonld to (a context with an absolute URI)

{"@context":"http://localhost/context.jsonld","id":"","type":"History"}

it seems to work

$ npm run urdf query query.rq 

> [email protected] urdf
> node src/cli.js "query" "query.rq"

No result.
$ 

We would like to use a source which puts relative URIs to context files.

@vcharpenay
Copy link
Owner

Alright. Can you make these files publicly available so that I can reproduce the error on the same resources as you?

@aharth
Copy link

aharth commented Feb 25, 2021

http://harth.org/andreas/2021/urdf/

Any query with FROM http://harth.org/andreas/2021/urdf/index.jsonld

@aharth
Copy link

aharth commented Mar 5, 2021

Quick question: we have to prepare a demo for next Wednesday... should we set up an elaborate workaround?

@vcharpenay
Copy link
Owner

I overlooked your last comment, sorry. 94d482b fixes the issue.

@derwehr
Copy link
Author

derwehr commented Mar 19, 2021

Thank you, I can confirm this bug is fixed for the query command.
However when using loadFrom I still can't process the jsonld from http://harth.org/andreas/2021/urdf/index.jsonld.

I tried to do this executing the following file via node (node loadFrom.js):

const urdf = require('./src/urdf-module.js');

// urdf.query with SELECT FROM - this is working
// const querySelectFrom = 'SELECT * FROM <http://harth.org/andreas/2021/urdf/index.jsonld> WHERE { ?s ?p ?o . }';
// urdf.query(querySelectFrom).then(console.log);

urdf.loadFrom('http://harth.org/andreas/2021/urdf/index.jsonld')
    .then(() => {
        console.log(urdf.size()); // 18
        urdf.query('SELECT * WHERE { ?s ?p ?o . }').then(console.log) // []
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants