linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
564 stars 143 forks source link

Cannot define statement with "a" predicate #505

Closed krokers closed 3 years ago

krokers commented 3 years ago

Seem there is no way to define statement with "a" predicate, e.g.: <#myId> a schema:Person .

I know that a is a substitute of "https://www.w3.org/1999/02/22-rdf-syntax-ns#type". Unfortunately some client libraries expects a, and won't work with rdf:type (e.g. default solid POD chat client).

Would be great if rdflib.js have a possibility to define such predicate. Could be something generic for parsing statements, e.g. Statement.parse("<#myId> a schema:Person") or a way to define a predicate using predefined constants, e.g.rdf.st(rdf.sym(...), rdf.predicates.a, rdf.sym(...)).

elf-pavlik commented 3 years ago

I know that a is a substitute of <https://www.w3.org/1999/02/22-rdf-syntax-ns#type>. Unfortunately some client libraries expects a, and won't work with rdf:type (e.g. default solid POD chat client).

This sounds like bug in those applications. AFAIK any turtle parser should create a Named Node with value: 'https://www.w3.org/1999/02/22-rdf-syntax-ns#type' as predicate when parsing <#myId> a schema:Person.

https://www.w3.org/TR/turtle/#sec-iri

The token a in the predicate position of a Turtle triple represents the IRI http://www.w3.org/1999/02/22-rdf-syntax-ns#type .

Also https://rdf.js.org/data-model-spec/#namednode-interface requires NamedNode to have an IRI as a value so one shouldn't be able to create named nodes with non IRI values.

BTW using anything else than Named Node on predicate position would render it a generalized RDF triple

krokers commented 3 years ago

Well, might be a bug in the chat application. But I'm not controlling it, so there is nothing I can do about that. :/

Anyway, a is really quite common predicate. I saw it in almost every document I checked. Is there really no way to create such statement using rdflib.js?

bourgeoa commented 3 years ago

@krokers

krokers commented 3 years ago

Yes, I know prefix for schema is needed. I just omitted that in my example to make it simpler. I'm just focusing on the statement.

So what I'm trying to do is to create such statement using rdflib.js. <#myId> a <http://schema.org/Person>.

I couldn't find a way in rdflib.js to define a predicate which is just a, without any prefix. I cannot use rdf:type for the reasons explained earlier.

I'm constructing the document by defining list of statements which I then pass toUpdateManager.update([], insertions, ...)

So, is there any workaround to construct such statement using just rdflib.js?

jeff-zucker commented 3 years ago

You gave an example above of parsing a Turtle statement containing an "a" - that works in rdflib now. If you want to use "a" in an rdflib add(), any() etc. try this:

const a = rdf.sym("http://www.w3.org/1999/02/22-rdf-syntax-ns#type") ;
store.add( rdf.sym("http://example.com/Foo"), a, rdf.sym("http://example.com/Bar")  );
jeff-zucker commented 3 years ago

Well, might be a bug in the chat application. But I'm not controlling it, so there is nothing I can do about that. :/

That's not how open source works. If you find a bug in an application you report the bug to the application developer. No, you don't "controll" the application, but unless you report it, it probably won't get fixed. If a library like rdflib starts making exceptions for misbehaving applications, then other applications will write stuff to misbehave because they can get away with it. Stop the problem where it exists (in that application), don't pollute the rest of the ecosystem with ways to work around the problem.

krokers commented 3 years ago

With your example it worked. Thank you! const a = rdf.sym("http://www.w3.org/1999/02/22-rdf-syntax-ns#type") ;

And of course I totally agree on reporting bugs for other projects. I just thought that it's not possible to define such, valid, document using rdflib.js. So I assumed it's a missing feature in rfdlib.js. That's why I reported here.

Anyway, thank you for quick responses and for your time. IMO we can close the ticket.