rdfjs / types

Authoritative TypeScript typings for all RDFJS specifications
MIT License
17 stars 13 forks source link

Need for `BaseQuad`, `InQuad` and `OutQuad`? #41

Closed dhurlburtusa closed 1 day ago

dhurlburtusa commented 6 months ago

Can someone help me understand the need for the BaseQuad interface? Seems like the Quad interface is sufficient.

What is the need for InQuad and OutQuad in DatasetCore, Dataset, DatasetCoreFactory, and DatasetFactory?

tpluscode commented 6 months ago

Quad, which is the default quad interface, limits the types of subject, predicate, object and graph it accepts using subtypes Quad_Subject, Quad_Predicate, Quad_Object, and Quad_Graph respectively. This prevents you from accidentally using the defaultGraph as subject, blank node as property, etc.

The InQuad and OutQuad are the same by default. This means that a dataset accepts and contains quads of the same type. However, an implementor may choose to use an extended model internally which adds some property, for example a pre-computed hash. Given an instance of DatasetCore<MyQuad>, the add method would only accept MyQuad, preventing using quads produced from other factories. This would be a nuisance from the perspective of interoperability. Instead, the implementor could accept any kinds of quad as input and add the hash dynamically so that the stored quad conforms to the internal interface. This is done by typing an implementation as DatasetCore<MyQuad, Quad> or even DatasetCore<MyQuad, BaseQuad>.

Here's that example

dhurlburtusa commented 6 months ago

Thanks for the quick reply Tomasz.

Quad, which is the default quad interface, limits the types of subject, predicate, object and graph it accepts using subtypes Quad_Subject, Quad_Predicate, Quad_Object, and Quad_Graph respectively. This prevents you from accidentally using the defaultGraph as subject, blank node as property, etc.

I understand the need for Quad with its extra restrictions on subject, predicate, object, and graph. That makes sense (although I think Quad in Quad_Subject and Quad_Object should be replaced with Triple but that is for a different discussion). I did see that it was the default but I don't understand the purpose of BaseQuad. It only "restricts" subject, predicate, object, and graph to Term which is even less restrictive than generalized RDF triples since it allows BaseQuad not only in the subject and object but also in the predicate and graph positions. Generalized triples only allow IRI, blank node, and literals in subject, predicate, object, and graph.

I don't believe RDF-star includes the concept of generalized triples. There isn't any explicit mention of generalized triples in the RDF-star spec. Also, if RDF-star did include the concept of generalized triples, then I'd have expected to see examples or mention of quoted-triples in predicates and graphs too.

The InQuad and OutQuad are the same by default. This means ...

Ok, that makes sense. Thanks for the great explanation and the code example.

tpluscode commented 2 days ago

Hello @dhurlburtusa can we close this issue as answered or do you still find something missing?