Closed krokers closed 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 withrdf: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 IRIhttp://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
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?
@krokers
By default rdf.parse, parses with content-type='text/turtle'
.
What you are trying to parse is an invalid turtle content.
A valid one is :
@prefix schema:<http://schema.org/>.
<#myId> a schema:Person.
or
<#myId> a <http://schema.org/Person>.
A statement is composed of a quad : subject, object, predicate, doc. Each term being a node. doc is optional For example :
rdf.st(rdf.sym('yourUrl#myId'), rdf.sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), rdf.sym('http://schema.org/Person'))
To experiment you can create a turtle file in your pod, and edit the content.
a
is allways accepted as a replacement. If you want you can use rdf:type
, but add the @prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
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?
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") );
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.
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.
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 expectsa
, and won't work withrdf: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(...))
.