private void processSameAs2and3(ISPO spo){
  SPO[] spos=new SPO[chunkSize];
  int numSPOs=0;
  Set<IV> sAndSames=getSelfAndSames(spo.s());
  Set<IV> oAndSames=getSelfAndSames(spo.o());
  if (sAndSames.size() == 1 && oAndSames.size() == 1) {
    return;
  }
  for (  IV s1 : sAndSames) {
    for (    IV o1 : oAndSames) {
      if (IVUtility.equals(spo.p(),sameAs) && IVUtility.equals(s1,o1)) {
        continue;
      }
      if (numSPOs == chunkSize) {
        boolean present=false;
        final IChunkedOrderedIterator<ISPO> absent=db.bulkFilterStatements(spos,numSPOs,present);
        if (absent.hasNext()) {
          if (sameAs2and3 == null) {
            sameAs2and3=createTempTripleStore();
          }
          db.addStatements(sameAs2and3,copyOnly,absent,null);
        }
        numSPOs=0;
      }
      spos[numSPOs++]=new SPO(s1,spo.p(),o1,StatementEnum.Inferred);
      dumpSPO(spos[numSPOs - 1]);
    }
  }
  if (numSPOs > 0) {
    boolean present=false;
    final IChunkedOrderedIterator<ISPO> absent=db.bulkFilterStatements(spos,numSPOs,present);
    if (absent.hasNext()) {
      if (sameAs2and3 == null) {
        sameAs2and3=createTempTripleStore();
      }
      db.addStatements(sameAs2and3,copyOnly,absent,null);
    }
  }
}

private void processSameAs2and3 ( ISPO spo ) { SPO [ ] spos = new SPO [ chunkSize ] ; int numSPOs = 0 ; Set < IV > sAndSames = getSelfAndSames ( spo . s ( ) ) ; Set < IV > oAndSames = getSelfAndSames ( spo . o ( ) ) ; if ( sAndSames . size ( ) == 1 && oAndSames . size ( ) == 1 ) { return ; } for ( IV s1 : sAndSames ) { for ( IV o1 : oAndSames ) { if ( IVUtility . equals ( spo . p ( ) , sameAs ) && IVUtility . equals ( s1 , o1 ) ) { continue ; } if ( numSPOs == chunkSize ) { boolean present = false ; final IChunkedOrderedIterator < ISPO > absent = db . bulkFilterStatements ( spos , numSPOs , present ) ; if ( absent . hasNext ( ) ) { if ( sameAs2and3 == null ) { sameAs2and3 = createTempTripleStore ( ) ; } db . addStatements ( sameAs2and3 , copyOnly , absent , null ) ; } numSPOs = 0 ; } spos [ numSPOs ++ ] = new SPO ( s1 , spo . p ( ) , o1 , StatementEnum . Inferred ) ; dumpSPO ( spos [ numSPOs - 1 ] ) ; } } if ( numSPOs > 0 ) { boolean present = false ; final IChunkedOrderedIterator < ISPO > absent = db . bulkFilterStatements ( spos , numSPOs , present ) ; if ( absent . hasNext ( ) ) { if ( sameAs2and3 == null ) { sameAs2and3 = createTempTripleStore ( ) ; } db . addStatements ( sameAs2and3 , copyOnly , absent , null ) ; } } }
we are essentially taking a cross product of the two sets { s , ? sameas s } and { o , ? sameas o } , and then inferring links between those { s , o } pairs . we can do this because s and o are unbound in this access path . we are simply using the connection that we know about ( the bound p ) , to connect up the { s , o } pairs . when p is unbound we are essentially visiting all predicates in the db and then doing the same thing .
