You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "A. Soroka (JIRA)" <ji...@apache.org> on 2017/11/03 19:27:00 UTC
[jira] [Comment Edited] (JENA-1391) Add Convenience Methods to
Dataset
[ https://issues.apache.org/jira/browse/JENA-1391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16238220#comment-16238220 ]
A. Soroka edited comment on JENA-1391 at 11/3/17 7:26 PM:
----------------------------------------------------------
Just a note that work on this is ongoing at https://github.com/ajs6f/jena/tree/JENA-1391.
Right now I've sketched in much of the API (though not all). There are no tests yet, and I still need to write an impl of dataset intersection and some more collectors. But comments eagerly welcomed! Particularly [~jaco0646] please let me know if this looks to be going in a direction that will support your needs.
Comparison link: https://github.com/apache/jena/compare/master...ajs6f:JENA-1391
was (Author: ajs6f):
Just a note that work on this is ongoing at https://github.com/ajs6f/jena/tree/JENA-1391.
Right now I've sketched in much of the API (though not all). There are no tests yet, and I still need to write an impl of dataset intersection and some more collectors. But comments eagerly welcomed! Particularly [~jaco0646] please let me know if this looks to be going in a direction that will support your needs.
> 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
>
> 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)