View Javadoc

1   /*
2    * Created on Aug 4, 2006
3    *
4    */
5   package org.openrdf.elmo.smusher;
6   
7   import org.openrdf.model.URI;
8   import org.slf4j.Logger;
9   import org.slf4j.LoggerFactory;
10  
11  /** This smusher computes the transitive closure of a given predicate (by default
12   *  owl:sameAs). e.g if it finds that A owl:sameAs B and B owl:sameAs C then it 
13   *  returns A and C as a match. 
14   *  
15   *  This smusher itself does not iterate and thus it will
16   *  not return the complete closure. It needs to be used inside an IterativeSmusher
17   *  to compute the complete closure.
18   *  
19   *  As it uses a single query it works only on a single repository, not in 
20   *  cases when we need to smush things in different repositories.
21   * 
22   * @author Peter Mika (pmika@cs.vu.nl)
23   */
24  public class TransitivitySmusher extends FixedQuerySmusher {
25  
26       
27       private final static String TRANSITIVITY_QUERY = 
28              "SELECT DISTINCT res1, res3 FROM " +
29              "{res1} <###> {res2} <###> {res3} " +
30             // "{person1} owl:sameAs {person1other}, {person2} owl:sameAs {person2other} " +
31              "WHERE res1 != res3 AND res1 != res2 AND res2 != res3 ";
32       
33      protected final static Logger _logger = LoggerFactory.getLogger(TransitivitySmusher.class);
34  
35      protected URI _property = org.openrdf.model.vocabulary.OWL.SAMEAS;
36      
37      public TransitivitySmusher() {
38          super(TRANSITIVITY_QUERY.replaceAll("###", org.openrdf.model.vocabulary.OWL.SAMEAS.toString()));
39  
40      }
41      
42      public TransitivitySmusher(URI property) { 
43          super(TRANSITIVITY_QUERY.replaceAll("###", property.toString()));
44          _property = property;
45      }
46  
47  }