You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commonsrdf.apache.org by an...@apache.org on 2015/03/30 03:10:08 UTC
[14/18] incubator-commonsrdf git commit: Return the Triple that was
actually added to Graph, including any mapped components as necessary
Return the Triple that was actually added to Graph, including any mapped
components as necessary
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/8d78597f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/8d78597f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/8d78597f
Branch: refs/heads/master
Commit: 8d78597f93925115fcb7647a6ce207882511c31b
Parents: 32ee522
Author: Peter Ansell <p_...@yahoo.com>
Authored: Sat Mar 28 21:32:06 2015 +1100
Committer: Peter Ansell <p_...@yahoo.com>
Committed: Sat Mar 28 21:32:06 2015 +1100
----------------------------------------------------------------------
.../main/java/org/apache/commons/rdf/api/Graph.java | 16 ++++++++++------
.../org/apache/commons/rdf/simple/GraphImpl.java | 15 ++++++++++-----
2 files changed, 20 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8d78597f/api/src/main/java/org/apache/commons/rdf/api/Graph.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/commons/rdf/api/Graph.java b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
index c4097b6..399a9bf 100644
--- a/api/src/main/java/org/apache/commons/rdf/api/Graph.java
+++ b/api/src/main/java/org/apache/commons/rdf/api/Graph.java
@@ -17,7 +17,6 @@
*/
package org.apache.commons.rdf.api;
-import java.util.function.Predicate;
import java.util.stream.Stream;
/**
@@ -29,15 +28,19 @@ import java.util.stream.Stream;
public interface Graph extends AutoCloseable {
/**
- * Add a triple to the graph.
+ * Add a triple to the graph, possibly mapping any of the components of the
+ * Triple to those supported by this Graph.
*
* @param triple
* The triple to add
+ * @return The Triple that was added to the graph, including any mapped
+ * components.
*/
- void add(Triple triple);
+ Triple add(Triple triple);
/**
- * Add a triple to the graph.
+ * Add a triple to the graph, possibly mapping any of the components to
+ * those supported by this Graph.
*
* @param subject
* The triple subject
@@ -45,8 +48,10 @@ public interface Graph extends AutoCloseable {
* The triple predicate
* @param object
* The triple object
+ * @return The Triple that was added to the graph, including any mapped
+ * components.
*/
- void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
+ Triple add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object);
/**
* Check if graph contains triple.
@@ -109,7 +114,6 @@ public interface Graph extends AutoCloseable {
/**
* Clear the graph, removing all triples.
- *
*/
void clear();
http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/8d78597f/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
----------------------------------------------------------------------
diff --git a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
index b0b3124..e67d263 100644
--- a/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
+++ b/simple/src/main/java/org/apache/commons/rdf/simple/GraphImpl.java
@@ -51,15 +51,17 @@ final class GraphImpl implements Graph {
}
@Override
- public void add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
+ public Triple add(BlankNodeOrIRI subject, IRI predicate, RDFTerm object) {
BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(subject);
IRI newPredicate = (IRI) internallyMap(predicate);
RDFTerm newObject = internallyMap(object);
- triples.add(factory.createTriple(newSubject, newPredicate, newObject));
+ Triple result = factory.createTriple(newSubject, newPredicate, newObject);
+ triples.add(result);
+ return result;
}
@Override
- public void add(Triple triple) {
+ public Triple add(Triple triple) {
BlankNodeOrIRI newSubject = (BlankNodeOrIRI) internallyMap(triple
.getSubject());
IRI newPredicate = (IRI) internallyMap(triple.getPredicate());
@@ -70,9 +72,12 @@ final class GraphImpl implements Graph {
&& newPredicate == triple.getPredicate()
&& newObject == triple.getObject()) {
triples.add(triple);
+ return triple;
} else {
- triples.add(factory.createTriple(newSubject, newPredicate,
- newObject));
+ Triple result = factory.createTriple(newSubject, newPredicate,
+ newObject);
+ triples.add(result);
+ return result;
}
}
Re: [14/18] incubator-commonsrdf git commit: Return the Triple that
was actually added to Graph, including any mapped components as necessary
Posted by Stian Soiland-Reyes <st...@apache.org>.
Yes, a Triple lookup would work fine just like that - but I am not
sure what this is useful for (unless you want to cast it to an
implementation subclass that provides additional methods).
So that only works if it is OK to query with the previously inserted
BlankNodes - which I would have hoped for to work, but which I can see
can get tricky if those BlankNodes came from a different
implementation and needs to be 'mapped' somehow.
Let's say there is an independent parser that produces Triples (using
simple.* instances) for
_:b1 foaf:knows _:b2 .
_:b2 foaf:knows _:b1 .
which you then add to a Graph from a secondary implementation, which
has its own BlankNode, Triple etc.
It might do its own BlankNode substitution on insert, e.g. like Jena
TDB who uses 64-bits integer to map to its disk-based indexes.
Obviously this would have to consistently map both statements to the
same substituted b1 and b2.
The substituted b1 and b2 (if you looked them up through getTriples)
might or might not have the same internalIdentifier() as the originals
- I don't think we require either now.
Now at a later stage you want add an additional statement about _:b1 -
I assume it would be OK to simply keep the original _:b1 instance in
memory and re-use that?
As we don't have a graph.addAll(Set<Triples>) or any kind of
'transaction' - then the Graph would have to support both of the above
and really can't tell which one it is.
Now with getTriples() I should presumably get back (in some form) the
expected triples I just added if I query/filter with that original b1
instance, which would be included in the results for statements with
predicate foaf:knows.
Is the original b1 .equal() to the substituted b1 instance returned
from that query? One should expect so - otherwise how did it pass the
filter?
Triple.equals() is defined from its constituent parts.
Now if all of the above is true - then why do you need to look up the
substituted Triple instance?
On 31 March 2015 at 12:02, Andy Seaborne <an...@apache.org> wrote:
> On 31/03/15 11:43, Stian Soiland-Reyes wrote:
>>
>> It might be that the Graph needs a method to look up blank nodes by
>> some measure, without having to query for a big graph pattern of what
>> was just inserted.
>
>
> You mean shorthand for
>
> graph
> .getTriples(t.getSubject(), t.getPrediate(), t.getObject())
> .findFirst.get() ;
>
> as the 3 elements are grounded, I'd expect that to be very fast.
>
>
>>
>> So now if you do
>>
>> String s = blankNode.internalIdentifier();
>> graph.add(blankNode, p, blankNode)
>>
>> and look it up again - than do I understand the contract correctly in
>> that Graph is not required to return the same internalIdentifier()?
>>
>> If I get those BlankNodes out again - are they still .equal() to the
>> inserted blankNode?
>>
>>
>> On 31 March 2015 at 10:52, Andy Seaborne <an...@apache.org> wrote:
>>>
>>> On 30/03/15 23:10, Peter Ansell wrote:
>>>>
>>>>
>>>> All of the BlankNode's in the Triple that was added may be internally
>>>> remapped during the add operation. Hence, the .equals will change when
>>>> the remapping occurs. Returning the mapped values enables a user to
>>>> get access to that information.
>>>>
>>>> Removing the return value is fine with me if it can't be supported in
>>>> a performant way. It just removes the simple way for a user to know
>>>> what BlankNode remapping occurred.
>>>
>>>
>>>
>>> Peter,
>>>
>>> Great - and I see the change in git.
>>>
>>> A simpler example would have been a parser not wanting to use the return
>>> from add() and an implementation that does not store Triple objects, but
>>> has
>>> data structures using the subject/predicate/object directly. Returned
>>> triples are just object churn albeit probably quite efficient churn.
>>>
>>> (hmm - interesting - so once mapped, the mapping is stable.)
>>>
>>> Andy
>>>
>>>
>>>>
>>>> On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>>>>>>
>>>>>>
>>>>>> - void add(Triple triple);
>>>>>> + Triple add(Triple triple);
>>>>>
>>>>>
>>>>>
>>>>> Returning something from add() does not work for me.
>>>>>
>>>>> (And even if it did, I would have expected "boolean" as to whether the
>>>>> triple was actually added or not.)
>>>>>
>>>>> 1/ I don't understand "possibly mapping" being in the API. A triple is
>>>>> a
>>>>> triple. What is the client supposed to do differently with .equals one
>>>>> returned (it is .equals?)
>>>>>
>>>>> 2/ I am finding that having a flow back from add operations difficult
>>>>> to
>>>>> deal with.
>>>>>
>>>>> A sequence of add(Triple) can be batched up and only need to be
>>>>> performed
>>>>> before another operation is called that can observe the change.
>>>>>
>>>>> In the case a remote destination, the overhead per add is significant
>>>>> (network rounds). But if it is delayed, then the return of anything is
>>>>> not
>>>>> available.
>>>>>
>>>>> For a general interface, this should be
>>>>>
>>>>> void add(Triple)
>>>>>
>>>>> Andy
>>>>>
>>>>>
>>>
>>
>>
>>
>
--
Stian Soiland-Reyes
Apache Taverna (incubating), Apache Commons RDF (incubating)
http://orcid.org/0000-0001-9842-9718
Re: [14/18] incubator-commonsrdf git commit: Return the Triple that
was actually added to Graph, including any mapped components as necessary
Posted by Andy Seaborne <an...@apache.org>.
On 31/03/15 11:43, Stian Soiland-Reyes wrote:
> It might be that the Graph needs a method to look up blank nodes by
> some measure, without having to query for a big graph pattern of what
> was just inserted.
You mean shorthand for
graph
.getTriples(t.getSubject(), t.getPrediate(), t.getObject())
.findFirst.get() ;
as the 3 elements are grounded, I'd expect that to be very fast.
>
> So now if you do
>
> String s = blankNode.internalIdentifier();
> graph.add(blankNode, p, blankNode)
>
> and look it up again - than do I understand the contract correctly in
> that Graph is not required to return the same internalIdentifier()?
>
> If I get those BlankNodes out again - are they still .equal() to the
> inserted blankNode?
>
>
> On 31 March 2015 at 10:52, Andy Seaborne <an...@apache.org> wrote:
>> On 30/03/15 23:10, Peter Ansell wrote:
>>>
>>> All of the BlankNode's in the Triple that was added may be internally
>>> remapped during the add operation. Hence, the .equals will change when
>>> the remapping occurs. Returning the mapped values enables a user to
>>> get access to that information.
>>>
>>> Removing the return value is fine with me if it can't be supported in
>>> a performant way. It just removes the simple way for a user to know
>>> what BlankNode remapping occurred.
>>
>>
>> Peter,
>>
>> Great - and I see the change in git.
>>
>> A simpler example would have been a parser not wanting to use the return
>> from add() and an implementation that does not store Triple objects, but has
>> data structures using the subject/predicate/object directly. Returned
>> triples are just object churn albeit probably quite efficient churn.
>>
>> (hmm - interesting - so once mapped, the mapping is stable.)
>>
>> Andy
>>
>>
>>>
>>> On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>>>>>
>>>>> - void add(Triple triple);
>>>>> + Triple add(Triple triple);
>>>>
>>>>
>>>> Returning something from add() does not work for me.
>>>>
>>>> (And even if it did, I would have expected "boolean" as to whether the
>>>> triple was actually added or not.)
>>>>
>>>> 1/ I don't understand "possibly mapping" being in the API. A triple is a
>>>> triple. What is the client supposed to do differently with .equals one
>>>> returned (it is .equals?)
>>>>
>>>> 2/ I am finding that having a flow back from add operations difficult to
>>>> deal with.
>>>>
>>>> A sequence of add(Triple) can be batched up and only need to be performed
>>>> before another operation is called that can observe the change.
>>>>
>>>> In the case a remote destination, the overhead per add is significant
>>>> (network rounds). But if it is delayed, then the return of anything is
>>>> not
>>>> available.
>>>>
>>>> For a general interface, this should be
>>>>
>>>> void add(Triple)
>>>>
>>>> Andy
>>>>
>>>>
>>
>
>
>
Re: [14/18] incubator-commonsrdf git commit: Return the Triple that
was actually added to Graph, including any mapped components as necessary
Posted by Stian Soiland-Reyes <st...@apache.org>.
It might be that the Graph needs a method to look up blank nodes by
some measure, without having to query for a big graph pattern of what
was just inserted.
So now if you do
String s = blankNode.internalIdentifier();
graph.add(blankNode, p, blankNode)
and look it up again - than do I understand the contract correctly in
that Graph is not required to return the same internalIdentifier()?
If I get those BlankNodes out again - are they still .equal() to the
inserted blankNode?
On 31 March 2015 at 10:52, Andy Seaborne <an...@apache.org> wrote:
> On 30/03/15 23:10, Peter Ansell wrote:
>>
>> All of the BlankNode's in the Triple that was added may be internally
>> remapped during the add operation. Hence, the .equals will change when
>> the remapping occurs. Returning the mapped values enables a user to
>> get access to that information.
>>
>> Removing the return value is fine with me if it can't be supported in
>> a performant way. It just removes the simple way for a user to know
>> what BlankNode remapping occurred.
>
>
> Peter,
>
> Great - and I see the change in git.
>
> A simpler example would have been a parser not wanting to use the return
> from add() and an implementation that does not store Triple objects, but has
> data structures using the subject/predicate/object directly. Returned
> triples are just object churn albeit probably quite efficient churn.
>
> (hmm - interesting - so once mapped, the mapping is stable.)
>
> Andy
>
>
>>
>> On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>>>>
>>>> - void add(Triple triple);
>>>> + Triple add(Triple triple);
>>>
>>>
>>> Returning something from add() does not work for me.
>>>
>>> (And even if it did, I would have expected "boolean" as to whether the
>>> triple was actually added or not.)
>>>
>>> 1/ I don't understand "possibly mapping" being in the API. A triple is a
>>> triple. What is the client supposed to do differently with .equals one
>>> returned (it is .equals?)
>>>
>>> 2/ I am finding that having a flow back from add operations difficult to
>>> deal with.
>>>
>>> A sequence of add(Triple) can be batched up and only need to be performed
>>> before another operation is called that can observe the change.
>>>
>>> In the case a remote destination, the overhead per add is significant
>>> (network rounds). But if it is delayed, then the return of anything is
>>> not
>>> available.
>>>
>>> For a general interface, this should be
>>>
>>> void add(Triple)
>>>
>>> Andy
>>>
>>>
>
--
Stian Soiland-Reyes
Apache Taverna (incubating), Apache Commons RDF (incubating)
http://orcid.org/0000-0001-9842-9718
Re: [14/18] incubator-commonsrdf git commit: Return the Triple that
was actually added to Graph, including any mapped components as necessary
Posted by Andy Seaborne <an...@apache.org>.
On 30/03/15 23:10, Peter Ansell wrote:
> All of the BlankNode's in the Triple that was added may be internally
> remapped during the add operation. Hence, the .equals will change when
> the remapping occurs. Returning the mapped values enables a user to
> get access to that information.
>
> Removing the return value is fine with me if it can't be supported in
> a performant way. It just removes the simple way for a user to know
> what BlankNode remapping occurred.
Peter,
Great - and I see the change in git.
A simpler example would have been a parser not wanting to use the return
from add() and an implementation that does not store Triple objects, but
has data structures using the subject/predicate/object directly.
Returned triples are just object churn albeit probably quite efficient
churn.
(hmm - interesting - so once mapped, the mapping is stable.)
Andy
>
> On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>>> - void add(Triple triple);
>>> + Triple add(Triple triple);
>>
>> Returning something from add() does not work for me.
>>
>> (And even if it did, I would have expected "boolean" as to whether the
>> triple was actually added or not.)
>>
>> 1/ I don't understand "possibly mapping" being in the API. A triple is a
>> triple. What is the client supposed to do differently with .equals one
>> returned (it is .equals?)
>>
>> 2/ I am finding that having a flow back from add operations difficult to
>> deal with.
>>
>> A sequence of add(Triple) can be batched up and only need to be performed
>> before another operation is called that can observe the change.
>>
>> In the case a remote destination, the overhead per add is significant
>> (network rounds). But if it is delayed, then the return of anything is not
>> available.
>>
>> For a general interface, this should be
>>
>> void add(Triple)
>>
>> Andy
>>
>>
Re: [14/18] incubator-commonsrdf git commit: Return the Triple that
was actually added to Graph, including any mapped components as necessary
Posted by Peter Ansell <an...@gmail.com>.
All of the BlankNode's in the Triple that was added may be internally
remapped during the add operation. Hence, the .equals will change when
the remapping occurs. Returning the mapped values enables a user to
get access to that information.
Removing the return value is fine with me if it can't be supported in
a performant way. It just removes the simple way for a user to know
what BlankNode remapping occurred.
On 31 March 2015 at 06:46, Andy Seaborne <an...@apache.org> wrote:
>> - void add(Triple triple);
>> + Triple add(Triple triple);
>
> Returning something from add() does not work for me.
>
> (And even if it did, I would have expected "boolean" as to whether the
> triple was actually added or not.)
>
> 1/ I don't understand "possibly mapping" being in the API. A triple is a
> triple. What is the client supposed to do differently with .equals one
> returned (it is .equals?)
>
> 2/ I am finding that having a flow back from add operations difficult to
> deal with.
>
> A sequence of add(Triple) can be batched up and only need to be performed
> before another operation is called that can observe the change.
>
> In the case a remote destination, the overhead per add is significant
> (network rounds). But if it is delayed, then the return of anything is not
> available.
>
> For a general interface, this should be
>
> void add(Triple)
>
> Andy
>
>
Re: [14/18] incubator-commonsrdf git commit: Return the Triple that
was actually added to Graph, including any mapped components as necessary
Posted by Andy Seaborne <an...@apache.org>.
> - void add(Triple triple);
> + Triple add(Triple triple);
Returning something from add() does not work for me.
(And even if it did, I would have expected "boolean" as to whether the
triple was actually added or not.)
1/ I don't understand "possibly mapping" being in the API. A triple is
a triple. What is the client supposed to do differently with .equals one
returned (it is .equals?)
2/ I am finding that having a flow back from add operations difficult to
deal with.
A sequence of add(Triple) can be batched up and only need to be
performed before another operation is called that can observe the change.
In the case a remote destination, the overhead per add is significant
(network rounds). But if it is delayed, then the return of anything is
not available.
For a general interface, this should be
void add(Triple)
Andy