You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Juan Sequeda <ju...@gmail.com> on 2015/09/23 17:06:04 UTC

Questions about Jena Model difference and isIsomorphicWith with Blank Nodes

All,

I was looking into the difference and isIsomorphicWith method of a Jena
Model when there are Blank Nodes.

The isIsomorphicWith returns the expected results when two RDF graphs with
blank nodes are effectively isomorphic. However, I would expect that if two
RDF graphs are isomorphic, then there shouldn't be a difference.  But when
blank nodes are in the graph, then all the triples that have blank nodes
are considered to be different. I assume then that the difference method
has been implemented in a way that it does take in account the labels of
the blank nodes (when the definition of isIsomorphicWith states the
opposite). Is my assumption correct?

This is example code


     String rdf1 = "<http://Alice> <http://knows> [].";

Model rdf1Model = ModelFactory.createDefaultModel();
rdf1Model.read(new ByteArrayInputStream( rdf1.getBytes()), null, "TTL");
String rdf2 = "<http://Alice> <http://knows> [].";
Model rdf2Model = ModelFactory.createDefaultModel();
rdf2Model.read(new ByteArrayInputStream( rdf2.getBytes()), null, "TTL");
boolean isIsomorphicWith = rdf1Model.isIsomorphicWith(rdf2Model);
Model diff = rdf1Model.difference(rdf2Model);
System.out.println("isIsomorphicWith = "+isIsomorphicWith); //returns true
diff.write(System.out, "TTL"); // returns "<http://Alice>  <http://knows>
 []  ." when I'm expecting an empty model because the graphs are isomorphic


Is there a way in Jena where difference follows the same definition of
isIsomorphicWith and ignores the labels on blank nodes.

Thanks!

--
Juan Sequeda, Ph.D
+1-575-SEQ-UEDA
www.juansequeda.com

Re: Questions about Jena Model difference and isIsomorphicWith with Blank Nodes

Posted by Rob Vesse <rv...@dotnetrdf.org>.
Juan

I've not done it in Jena but I have done it in dotNetRDF

The general approach is to treat triples with blank nodes separately from
those without.  For triples with no blank nodes you can simply do
contains() checks across the two models to find the differences.

For those with blank nodes divide them up into sub-graphs I.e.

- Start from an arbitrary triple that has a blank node create a new
sub-graph
 - Find all other blank node containing triples that also contain that
blank node and add them to that sub-graph
 - Iterate until no further triples can be added to the current sub-graph
being constructed
- If there are still triples with blank nodes build continue to build
sub-graph(s)

This will give you two sets of sub-graphs for the two models, you can then
use isIsomorphicWith() to check whether each sub-graph has an equivalent
sub-graph in the other model.  You can use the size of the sub-graphs to
reduce the size of the solution space to check.  Bear in mind that you
might end up with sub-graph(s) that have multiple possible isomorphic
sub-graphs in the other model (and vice versa) so you will need to take
that into account when determining the differences.

Hope this helps,

Rob

On 23/09/2015 16:19, "Juan Sequeda" <ju...@gmail.com> wrote:

>On Wed, Sep 23, 2015 at 5:12 PM, Chris Dollin
><ch...@epimorphics.com>
>wrote:
>
>> On 09/23/2015 04:06 PM, Juan Sequeda wrote:
>>
>> I was looking into the difference and isIsomorphicWith method of a Jena
>>> Model when there are Blank Nodes.
>>>
>>> The isIsomorphicWith returns the expected results when two RDF graphs
>>>with
>>> blank nodes are effectively isomorphic. However, I would expect that if
>>> two
>>> RDF graphs are isomorphic, then there shouldn't be a difference.  But
>>>when
>>> blank nodes are in the graph, then all the triples that have blank
>>>nodes
>>> are considered to be different. I assume then that the difference
>>>method
>>> has been implemented in a way that it does take in account the labels
>>>of
>>> the blank nodes (when the definition of isIsomorphicWith states the
>>> opposite). Is my assumption correct?
>>>
>>
>> Yes. Difference just compares nodes for equality; it doesn't treat
>> blank nodes as variables. Two blank nodes with different labels are
>> different blank nodes.
>>
>> Is there a way in Jena where difference follows the same definition of
>>> isIsomorphicWith and ignores the labels on blank nodes.
>>>
>>
>> Not as far as I'm aware.
>
>
>I guess I would have to implement this on my own.
>
>I'm sure somebody has tried to do this before :)
>
>
>>
>>
>> Chris
>>





Re: Questions about Jena Model difference and isIsomorphicWith with Blank Nodes

Posted by Juan Sequeda <ju...@gmail.com>.
On Wed, Sep 23, 2015 at 5:12 PM, Chris Dollin <ch...@epimorphics.com>
wrote:

> On 09/23/2015 04:06 PM, Juan Sequeda wrote:
>
> I was looking into the difference and isIsomorphicWith method of a Jena
>> Model when there are Blank Nodes.
>>
>> The isIsomorphicWith returns the expected results when two RDF graphs with
>> blank nodes are effectively isomorphic. However, I would expect that if
>> two
>> RDF graphs are isomorphic, then there shouldn't be a difference.  But when
>> blank nodes are in the graph, then all the triples that have blank nodes
>> are considered to be different. I assume then that the difference method
>> has been implemented in a way that it does take in account the labels of
>> the blank nodes (when the definition of isIsomorphicWith states the
>> opposite). Is my assumption correct?
>>
>
> Yes. Difference just compares nodes for equality; it doesn't treat
> blank nodes as variables. Two blank nodes with different labels are
> different blank nodes.
>
> Is there a way in Jena where difference follows the same definition of
>> isIsomorphicWith and ignores the labels on blank nodes.
>>
>
> Not as far as I'm aware.


I guess I would have to implement this on my own.

I'm sure somebody has tried to do this before :)


>
>
> Chris
>

Re: Questions about Jena Model difference and isIsomorphicWith with Blank Nodes

Posted by Chris Dollin <ch...@epimorphics.com>.
On 09/23/2015 04:06 PM, Juan Sequeda wrote:

> I was looking into the difference and isIsomorphicWith method of a Jena
> Model when there are Blank Nodes.
>
> The isIsomorphicWith returns the expected results when two RDF graphs with
> blank nodes are effectively isomorphic. However, I would expect that if two
> RDF graphs are isomorphic, then there shouldn't be a difference.  But when
> blank nodes are in the graph, then all the triples that have blank nodes
> are considered to be different. I assume then that the difference method
> has been implemented in a way that it does take in account the labels of
> the blank nodes (when the definition of isIsomorphicWith states the
> opposite). Is my assumption correct?

Yes. Difference just compares nodes for equality; it doesn't treat
blank nodes as variables. Two blank nodes with different labels are
different blank nodes.

> Is there a way in Jena where difference follows the same definition of
> isIsomorphicWith and ignores the labels on blank nodes.

Not as far as I'm aware.

Chris