Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-405 add alt bag seq utility functions #2254

Merged
merged 10 commits into from
May 26, 2020

Conversation

reeshabhranjan
Copy link
Contributor

@reeshabhranjan reeshabhranjan commented May 21, 2020

GitHub issue resolved: #405

We have referred RDFCollections.java to implement the consumeContainer() (analogous to consumeCollection()) in the newly created RDFContainers.java, and same for asRDF() method. We are taking the type of collection from the input, and are checking that it should only be one out of RDF.ALT, RDF.BAG and RDF.SEQ.
In the last consumeContainer() method, we have iterated over the supplied values iterable, and added 2 types of predicates for every element:

  1. value rdfs:member container
  2. container rdf:_nnn value

In the above example, container is the actual Resource representing the container in RDF.

Signed-off-by: Reeshabh Kumar Ranjan <reeshabhkumarranjan@gmail.com>
Signed-off-by: Reeshabh Kumar Ranjan <reeshabhkumarranjan@gmail.com>
Copy link
Contributor

@abrokenjester abrokenjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks, good solution. The build failed on formatting issues that you will need to fix. Couple of inline comments and questions.

Also: needs a few unit tests in place, and fixing up the Javadoc.

*/
public class RDFContainers {

public static <C extends Collection<Statement>> C asRDF(IRI containerType, Iterable<?> values, Resource container, C sink,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a nice addition would be to also have conversion methods that pick the container type, e.g asAlt, asSeq, and asBag.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the containerType passed into the asRDF method is for that purpose only. We will use the containerType parameter in further implementations. Should we have those separate methods as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment on the use of “as”. Java has “toString” and that’s made me use “to” rather than “as” in other code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hmottestad I think in this case it's modeled off of the naming we use in the RDFCollections class for similar methods. I kind of agree with you that 'to' might have been a better choice ('as' to me suggests a view on an object rather than a new, converted, object), but to stay consistent I'm fine with sticking with this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hmottestad actually, coming back to it, I think you are right, and we might as well change this. @reeshabhkumarranjan do you think you could do a fix to change all the as... method names asRDF, asValues to to... method names (toRDF, toValues, etc.)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeenbroekstra Yes I can do this. Just to confirm, I have to do this only in RDFContainers.java, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct, only RDFContainers. We'll fix RDFCollections later, separately.

…, add untested code for consumeValues() method for RDFContainers.java (documentation pending)

Signed-off-by: Reeshabh Kumar Ranjan <reeshabhkumarranjan@gmail.com>
… (documentation pending)

Signed-off-by: Reeshabh Kumar Ranjan <reeshabhkumarranjan@gmail.com>
@reeshabhranjan
Copy link
Contributor Author

@jeenbroekstra I will format the file as per guidelines in the final commit, before that, please check my replies to your comments above. Also I have added all the necessary methods in the file. I will soon add the documentation.

Signed-off-by: Prince Sachdeva <prince17080@iiitd.ac.in>
Signed-off-by: Prince Sachdeva <prince17080@iiitd.ac.in>
…method

Signed-off-by: Prince Sachdeva <prince17080@iiitd.ac.in>
Copy link
Contributor

@abrokenjester abrokenjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work, looking really good. A couple of minor comments only.

Comment on lines 105 to 113
Pattern annotatedMembershipPredicatePattern = Pattern.compile("^" + vf.createIRI(RDF.NAMESPACE, "_") + "[1-9][0-9]*$");

extract(containerType, statementSupplier, container, st -> {
if (RDFS.MEMBER.equals(st.getPredicate()) ||
annotatedMembershipPredicatePattern.matcher(st.getPredicate().toString()).matches()) {
consumer.accept(st.getObject());
}
}, exceptionSupplier, contexts);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am using regex to find properties of type rdf:_nnn and simple .equals() to check for rdfs:member.

Comment on lines 145 to 147
if (statementSupplier.get(container, annotatedMembershipPredicate, null, contexts).equals(Optional.empty())) {
break;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will loop through the statements of the form ?s rdf:_nnn ?o until it exists.

Comment on lines 150 to 155
if (containerType.equals(RDF.ALT)) {
if (encountered.contains(statement.getObject())) {
throw exceptionSupplier.apply("rdf:alt cannot contain duplicate values").get();
}
encountered.add(statement.getObject());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for rdf:Alt, I have added this check to make sure that distinct elements are passed. Instead of throwing the exception, should I just skip adding the duplicate elements?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd actually leave this check out, completely. It may seem logical to test this, but there is nothing in the RDF specifications that says anything about the members of an rdf:Alt container having to be distinct.

…un mvn impsort:sort

Signed-off-by: Prince Sachdeva <prince17080@iiitd.ac.in>
Copy link
Contributor

@abrokenjester abrokenjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the latest update, looking good. See my previous response regarding the check you added for rdf:Alt containers.

Also, finally: can you add a few unit tests? Nothing too difficult, just some tests that create some simple containers from Java collections and vice versa. I think you can look at RDFCollectionsTest for inspiration.

@abrokenjester abrokenjester changed the base branch from master to develop May 25, 2020 01:22
@abrokenjester abrokenjester changed the title Gh 405 add alt bag seq GH-405 add alt bag seq May 25, 2020
@abrokenjester abrokenjester changed the title GH-405 add alt bag seq GH-405 add alt bag seq utility functions May 25, 2020
@reeshabhranjan
Copy link
Contributor Author

Thanks for the latest update, looking good. See my previous response regarding the check you added for rdf:Alt containers.

Also, finally: can you add a few unit tests? Nothing too difficult, just some tests that create some simple containers from Java collections and vice versa. I think you can look at RDFCollectionsTest for inspiration.

Sure, we will add the tests soon.

…ava, Remove distinct element check for rdf:alt in RDFContainers.java

Signed-off-by: Gaurav Aggarwal <gaurav17288@iiitd.ac.in>
Copy link
Contributor

@abrokenjester abrokenjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@abrokenjester
Copy link
Contributor

One final request: could you give your names as you'd like them mentioned for our release notes? We make it a point to mention who contributed to a release, and I want to make sure I get spelling right and include everyone who contributed. Please add a comment to #2235.

@abrokenjester abrokenjester merged commit 008e215 into eclipse-rdf4j:develop May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add rdf:Alt, rdf:Bag, rdf:Seq to org.eclipse.rdf4j.model
5 participants