You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by Gregor Trefs <gr...@gmail.com> on 2015/11/23 00:16:00 UTC
DatasetGraph.getGraph(Node) violation of liskov substitutionremoveNamedModel
Dear Jena Devs,
I am further into my application and think I found a violation of the
Liskov Substitution principle. In short, the principle states that using a
subtype of a type should not alter the meaning of the application. While I
was driving my application, I discovered this fuzzy description of
method org.apache.jena.sparql.core.DatasetGraph.getGraph(Node).
/** Get the graph named by graphNode : returns null on no graph
* NB Whether a dataset contains a graph if there are no triples is not
defined - see the specifc implementation.
* Some datasets are "open" - they have all graphs even if no triples,
* */
While I see the point, that some dataset graphs follow the Open World
Principle and, therefore, rather return an empty graph instead of a
nothing, it is a struggle for me as a developer because I cannot reason
about the actual behaviour when I first call Dataset.remove and then
Dataset.getNamedModel to assure that the model is gone. Using the dataset
which is returned by the TDBFactory would actually fails this test.
My questions are: Is there a guideline which Datasetgraphs are used when?
Is there a possibility to determine whether a graph is present or not? How
does the union of all dataset graphs look like under the "open" assumption?
Best regards,
Gregor
Re: DatasetGraph.getGraph(Node) violation of liskov
substitutionremoveNamedModel
Posted by Andy Seaborne <an...@apache.org>.
On 22/11/15 23:16, Gregor Trefs wrote:
> Dear Jena Devs,
>
> I am further into my application and think I found a violation of the
> Liskov Substitution principle. In short, the principle states that using a
> subtype of a type should not alter the meaning of the application. While I
> was driving my application, I discovered this fuzzy description of
> method org.apache.jena.sparql.core.DatasetGraph.getGraph(Node).
>
> /** Get the graph named by graphNode : returns null on no graph
> * NB Whether a dataset contains a graph if there are no triples is not
> defined - see the specifc implementation.
> * Some datasets are "open" - they have all graphs even if no triples,
> * */
You may wish to read the SPARQL Update spec on the subject as well. It
has to take account the different needs of different implementations.
> While I see the point, that some dataset graphs follow the Open World
> Principle and, therefore, rather return an empty graph instead of a
> nothing, it is a struggle for me as a developer because I cannot reason
> about the actual behaviour when I first call Dataset.remove and then
> Dataset.getNamedModel to assure that the model is gone. Using the dataset
> which is returned by the TDBFactory would actually fails this test.
Note also that getGraph() could be called and returned before remove -
then what?
> My questions are: Is there a guideline which Datasetgraphs are used when?
Note the javadoc for removeGraph:
/** Remove all data associated with the named graph */
"remove all data" means the contract is that there are no triples in the
graph.
(Even this isn't possible with inference graphs but let's skip the
meaning of axiomatic triples and read "data" as "useful data")
So you can reason about before and after.
> Is there a possibility to determine whether a graph is present or not?
Testing whether there is any content is a good plan.
containsGraph(graphName) is best implemented as the
equivalent of find(graphName, ?, ? ?).hasNext()
In DatasetGraphs implemented in Jena itself, that is true (AFAIK). For
ones implemented by 3rd parties, you'll have to check with them.
> How
> does the union of all dataset graphs look like under the "open" assumption?
An RDF Graph is a set of triples.
The union is not affected by empty graphs.
Andy
>
> Best regards,
> Gregor
>
Re: DatasetGraph.getGraph(Node) violation of liskov substitutionremoveNamedModel
Posted by "A. Soroka" <aj...@virginia.edu>.
When you say Dataset.remove, which doesn’t exist, are you talking about Dataset::removeNamedModel? If so, the comment for that method is "Remove a named graph.” That makes no particular guarantee about the behavior of Dataset::getNamedModel before-and-after the invocation of Dataset::removeNamedModel.
As I understand it, the idea of the (more-or-less intentional) ambiguity in the specification is that a graph may or may not have some existence apart from the existence of its contents, or to put it another way: the name of a named graph is an identifier, not a container. So it is legitimate to say that to remove a named graph is to remove all of the triples in it. It is also legitimate to say that to remove a named graph is to make its name resolve to nothing (null). Your problem, in that sense, is not an LSP violation. The problem is that you want to rely on a behavior which is intentionally left to the implementation to define.
---
A. Soroka
The University of Virginia Library
> On Nov 22, 2015, at 6:16 PM, Gregor Trefs <gr...@gmail.com> wrote:
>
> Dear Jena Devs,
>
> I am further into my application and think I found a violation of the
> Liskov Substitution principle. In short, the principle states that using a
> subtype of a type should not alter the meaning of the application. While I
> was driving my application, I discovered this fuzzy description of
> method org.apache.jena.sparql.core.DatasetGraph.getGraph(Node).
>
> /** Get the graph named by graphNode : returns null on no graph
> * NB Whether a dataset contains a graph if there are no triples is not
> defined - see the specifc implementation.
> * Some datasets are "open" - they have all graphs even if no triples,
> * */
>
> While I see the point, that some dataset graphs follow the Open World
> Principle and, therefore, rather return an empty graph instead of a
> nothing, it is a struggle for me as a developer because I cannot reason
> about the actual behaviour when I first call Dataset.remove and then
> Dataset.getNamedModel to assure that the model is gone. Using the dataset
> which is returned by the TDBFactory would actually fails this test.
>
> My questions are: Is there a guideline which Datasetgraphs are used when?
> Is there a possibility to determine whether a graph is present or not? How
> does the union of all dataset graphs look like under the "open" assumption?
>
> Best regards,
> Gregor