[
https://issues.apache.org/jira/browse/JENA-1391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16202087#comment-16202087
]
ASF GitHub Bot commented on JENA-1391:
--------------------------------------
Github user afs commented on a diff in the pull request:
https://github.com/apache/jena/pull/287#discussion_r144321132
--- Diff: jena-arq/src/main/java/org/apache/jena/query/Dataset.java ---
@@ -113,4 +113,11 @@
* The dataset can not be used for query after this call.
*/
public void close() ;
+
+ /**
+ * @return Whether this {@code Dataset} is empty of graphs. Be aware
of the semantic looseness inherent in
+ * <a
href="https://www.w3.org/TR/2014/REC-rdf11-concepts-20140225/#h_note_4">the
definition
+ * of RDF Datasets</a>; whether a named graph exists if nothing is in
it is implementation-specific.
+ */
+ boolean isEmpty();
--- End diff --
Sure we can. Change the javadoc to "returns true if the dataset contains
no statements in any model". That's what it does, and what the test does
anyway, because the impl passes down to `DatasetGraph.isEmpty`. That is the
useful operation.
> Add Convenience Methods to Dataset
> ----------------------------------
>
> Key: JENA-1391
> URL: https://issues.apache.org/jira/browse/JENA-1391
> Project: Apache Jena
> Issue Type: Improvement
> Components: ARQ
> Affects Versions: Jena 3.4.0
> Reporter: Adam Jacobs
> Assignee: A. Soroka
> Priority: Trivial
>
> The Dataset interface could provide several convenience methods similar to
> the Model interface, allowing usability of RDF quads on par with RDF triples.
> Specific examples include,
> # add(Dataset)
> # remove(Dataset)
> # union(Dataset)
> # intersection(Dataset)
> # difference(Dataset)
> # isEmpty()
> Following is a possible implementation of these methods.
> {code:java}
> default Dataset add(Dataset d) {
> this.getDefaultModel().add(d.getDefaultModel());
> d.listNames().forEachRemaining(name ->
> this.getNamedModel(name).add(d.getNamedModel(name)));
> return this;
> }
> default Dataset remove(Dataset d) {
> this.getDefaultModel().remove(d.getDefaultModel());
> d.listNames().forEachRemaining(name ->
> this.getNamedModel(name).remove(d.getNamedModel(name)));
> return this;
> }
> default Dataset union(Dataset d) {
> return DatasetFactory.create().add(this).add(d);
> }
> default Dataset difference(Dataset d) {
> Dataset output = DatasetFactory.create();
>
> output.setDefaultModel(this.getDefaultModel().difference(d.getDefaultModel()));
> this.listNames().forEachRemaining(name -> {
> Model difference =
> this.getNamedModel(name).difference(d.getNamedModel(name));
> if (!difference.isEmpty()) output.addNamedModel(name, difference);
> });
> return output;
> }
> default Dataset intersection(Dataset d) {
> Dataset output = DatasetFactory.create();
>
> output.setDefaultModel(this.getDefaultModel().intersection(d.getDefaultModel()));
> Set<String> names = this.names();
> names.retainAll(d.names());
> names.forEach(name -> {
> Model intersection =
> this.getNamedModel(name).intersection(d.getNamedModel(name));
> if (!intersection.isEmpty()) output.addNamedModel(name,
> intersection);
> });
> return output;
> }
> default Set<String> names() {
> Set<String> names = new HashSet<>();
> this.listNames().forEachRemaining(names::add);
> return names;
> }
> default boolean isEmpty() {
> return this.asDatasetGraph().isEmpty();
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)