private SomeResource convert(Node n) { if ( n.isBlank() ) { SomeResource anon = anonLookup.get(n); if ( anon == null ) { anon = new AnonResource( n ); anonLookup.put(n,anon); } return anon; } else { return new FixedResource(n); } }
void bind(AnonResource pair) { bound = pair; if (!unboundAnonResources.remove(this)) impossible(); boundAnonResources.add(this); if ( pair.bound == null ) { trace( true, r.getBlankNodeId()+ "=" + pair.r.getBlankNodeId() + ", " ); pair.bind(this); // choice any arbitary number here // helps spread the bits. bound.boundHash= boundHash =random.nextInt(); // if ( myHash != bound.myHash ) // impossible(); // Sometimes they are different, after we have // guessed badly, changed bound.myHash and then // backtracked. } if ( bound.bound != this ) impossible(); } void unbind() {
while ( anons.hasNext() ) { AnonResource a = anons.next(); Integer hash = new Integer( a.myHashCode() ); Bucket bkt = table.get(hash); if ( bkt == null ) {
private boolean bind() { Set<AnonResource> locallyBound = obligBindings(); if (locallyBound==null) // Contradiction reached - fail. return false; check(HASH_OK); Bucket bkt = smallestBucket(); if ( bkt == null ) return true; // No smallest bucket - we are finished. Bucket otherBkt = other.matchBucket(bkt); if ( otherBkt != null ) { AnonResource v = bkt.aMember(); Iterator<AnonResource> candidates = otherBkt.members(); // System.out.println("Guessing"); while ( candidates.hasNext() ) { check(HASH_OK|HASH_BAD); AnonResource otherV = candidates.next(); trace(true,"Guess: "); if (!bkt.bind(v,otherBkt,otherV)) continue; if (bind()) return true; v.unbind(); } } unbindAll(locallyBound); return false; } /*
void unbind() { AnonResource pair = bound; bound = null; if (!boundAnonResources.remove(this)) impossible(); unboundAnonResources.add(this); if ( pair.bound != null ) { trace( false, r.getBlankNodeId() + "!=" + pair.r.getBlankNodeId() + ", " ); if ( pair.bound != this ) impossible(); pair.unbind(); } in(HASH_BAD); } boolean checkBinding( AnonResource pair ) {
private Set<StatementWrapper> wrapStatements() { if ( state == HASH_BAD ) { // We are already in(HASH_BAD). // We need to use AnonResource.myHashCodeFromStatement(). // That is OK as long as myHashLevel is 0 myHashLevel = 0; } Set<StatementWrapper> statements = CollectionFactory.createHashedSet(); // Add all our statements to the set. Iterator<AnonStatement> it = occursIn.iterator(); while ( it.hasNext() ) statements.add(wrapStatement(it.next())); return statements; } @Override
private void unbindAll(Set<AnonResource> s) { Iterator<AnonResource> rs = s.iterator(); while (rs.hasNext()) rs.next().unbind(); in(HASH_BAD); } private int prepare(Graph otherm) {
boolean checkBinding( AnonResource pair ) { if ( occursIn.size() != pair.occursIn.size() ) return false; Set<StatementWrapper> ourStatements = wrapStatements(); Set<StatementWrapper> otherStatements = pair.wrapStatements(); return ourStatements.removeAll(otherStatements) && ourStatements.isEmpty(); } private Set<StatementWrapper> wrapStatements() {
boolean bind(AnonResource mine,Bucket other,AnonResource binding) { if ( mine.checkBinding(binding) ) { mine.bind(binding); return true; } else { return false; } }