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

List from RDF doesn't work #5

Open
iddan opened this issue Mar 19, 2020 · 3 comments
Open

List from RDF doesn't work #5

iddan opened this issue Mar 19, 2020 · 3 comments

Comments

@iddan
Copy link

iddan commented Mar 19, 2020

FromRDF() doesn't parse lists

Example

N-Quads:

<http://example.com/alice> <http://example.com#friends> _:1 .
	_:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.com/bob> .
	_:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .

Go: Playground

package main

import (
	"encoding/json"
	"fmt"

	"github.com/linkeddata/gojsonld"
)

func main() {
	nquads := `<http://example.com/alice> <http://example.com#friends> _:1 .
	_:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.com/bob> .
	_:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .`
	dataset, err := gojsonld.ParseDataset([]byte(nquads))
	if err != nil {
		panic(err)
	}
	doc := gojsonld.FromRDF(dataset, &gojsonld.Options{})
	d, _ := json.MarshalIndent(doc, "", "    ")
	fmt.Printf("%v\n", string(d))
}

Result:

[
    {
        "@id": "1",
        "http://www.w3.org/1999/02/22-rdf-syntax-ns#first": [
            {
                "@id": "http://example.com/bob"
            }
        ],
        "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest": [
            {
                "@list": []
            }
        ]
    },
    {
        "@id": "http://example.com/alice",
        "http://example.com#friends": [
            {
                "@id": "1"
            }
        ]
    }
]

Node.js: RunKit

const jsonld = require("jsonld");
const result = await jsonld.fromRDF(`<http://example.com/alice> <http://example.com#friends> _:1 .
	_:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <http://example.com/bob> .
	_:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .`);
JSON.stringify(result, null, 4)

Result:

[
    {
        "@id": "http://example.com/alice",
        "http://example.com#friends": [
            {
                "@list": [
                    {
                        "@id": "http://example.com/bob"
                    }
                ]
            }
        ]
    }
]
@deiu
Copy link

deiu commented Mar 19, 2020

Hi @iddan, thank you for opening this issue!

I'm afraid I won't have time to look into it short term, so it would be super awesome if you think you can provide a PR with the fix. :)

@iddan
Copy link
Author

iddan commented Mar 19, 2020

Hey @deiu! Thanks for the quick reply. I will try to get around this to unblock a PR in Cayley.

@iddan
Copy link
Author

iddan commented Mar 21, 2020

I found out https://github.com/piprate/json-gold got it right. Will consider whether it's better implementing it here or use their implementation.

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

2 participants