-
Notifications
You must be signed in to change notification settings - Fork 165
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
GH-405 add alt bag seq utility functions #2254
Conversation
Signed-off-by: Reeshabh Kumar Ranjan <reeshabhkumarranjan@gmail.com>
Signed-off-by: Reeshabh Kumar Ranjan <reeshabhkumarranjan@gmail.com>
There was a problem hiding this 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.
core/model/src/main/java/org/eclipse/rdf4j/model/util/RDFContainers.java
Outdated
Show resolved
Hide resolved
core/model/src/main/java/org/eclipse/rdf4j/model/util/RDFContainers.java
Show resolved
Hide resolved
core/model/src/main/java/org/eclipse/rdf4j/model/util/RDFContainers.java
Outdated
Show resolved
Hide resolved
*/ | ||
public class RDFContainers { | ||
|
||
public static <C extends Collection<Statement>> C asRDF(IRI containerType, Iterable<?> values, Resource container, C sink, |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
@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>
There was a problem hiding this 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.
core/model/src/main/java/org/eclipse/rdf4j/model/util/RDFContainers.java
Outdated
Show resolved
Hide resolved
core/model/src/main/java/org/eclipse/rdf4j/model/util/RDFContainers.java
Outdated
Show resolved
Hide resolved
core/model/src/main/java/org/eclipse/rdf4j/model/util/RDFContainers.java
Outdated
Show resolved
Hide resolved
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); | ||
} |
There was a problem hiding this comment.
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
.
if (statementSupplier.get(container, annotatedMembershipPredicate, null, contexts).equals(Optional.empty())) { | ||
break; | ||
} |
There was a problem hiding this comment.
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.
if (containerType.equals(RDF.ALT)) { | ||
if (encountered.contains(statement.getObject())) { | ||
throw exceptionSupplier.apply("rdf:alt cannot contain duplicate values").get(); | ||
} | ||
encountered.add(statement.getObject()); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
There was a problem hiding this 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.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
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. |
GitHub issue resolved: #405
We have referred
RDFCollections.java
to implement theconsumeContainer()
(analogous toconsumeCollection()
) in the newly createdRDFContainers.java
, and same forasRDF()
method. We are taking the type of collection from the input, and are checking that it should only be one out ofRDF.ALT
,RDF.BAG
andRDF.SEQ
.In the last
consumeContainer()
method, we have iterated over the suppliedvalues
iterable, and added 2 types of predicates for every element:value rdfs:member container
container rdf:_nnn value
In the above example,
container
is the actualResource
representing the container in RDF.