|
From: Mike P. <mrp...@us...> - 2007-07-13 22:24:01
|
Update of /cvsroot/cweb/rdf-generic/src/java/org/CognitiveWeb/sesame/sailimpl/generic/reasoner/backward In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv6910/rdf-generic/src/java/org/CognitiveWeb/sesame/sailimpl/generic/reasoner/backward Modified Files: GBackwardChainer.java Log Message: Fixed owl:sameAs Index: GBackwardChainer.java =================================================================== RCS file: /cvsroot/cweb/rdf-generic/src/java/org/CognitiveWeb/sesame/sailimpl/generic/reasoner/backward/GBackwardChainer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** GBackwardChainer.java 3 Oct 2006 13:22:50 -0000 1.6 --- GBackwardChainer.java 13 Jul 2007 22:23:51 -0000 1.7 *************** *** 13,16 **** --- 13,17 ---- import org.CognitiveWeb.sesame.sailimpl.generic.model.GBNode; import org.CognitiveWeb.sesame.sailimpl.generic.model.GGraph; + import org.CognitiveWeb.sesame.sailimpl.generic.model.GLiteral; import org.CognitiveWeb.sesame.sailimpl.generic.model.GResource; import org.CognitiveWeb.sesame.sailimpl.generic.model.GStatement; *************** *** 25,29 **** import org.CognitiveWeb.sesame.sailimpl.generic.reasoner.backward.core.rules.RdfsRuleModel; import org.apache.log4j.Logger; - import org.openrdf.model.BNode; import org.openrdf.model.Literal; import org.openrdf.model.Resource; --- 26,29 ---- *************** *** 523,535 **** } - private void accessSO - ( GResource sSkin, GValue oSkin, - GStatementIterator stmts ) - { - - throw new RuntimeException( "not yet implemented" ); - - } - private void accessPO ( GURI pSkin, GValue oSkin, --- 523,526 ---- *************** *** 547,552 **** Set inferred = new TreeSet(); - - Set all = new TreeSet(); --- 538,541 ---- *************** *** 788,800 **** } - private void accessP - ( GURI pSkin, - GStatementIterator stmts ) - { - - throw new RuntimeException( "not yet implemented" ); - - } - private void accessO ( GValue oSkin, --- 777,780 ---- *************** *** 813,816 **** --- 793,893 ---- } + private void accessP + ( GURI pSkin, + GStatementIterator stmts ) + { + + throw new RuntimeException( "not yet implemented" ); + + } + + private void accessSO + ( GResource sSkin, GValue oSkin, + GStatementIterator stmts ) + { + + // john loves mary + // jonathan adores mary + // jonathan loves mary + // john sameAs jonathan + // answer: loves, adores + + // john loves mary + // john adores meridith + // mary sameAs meridith + // answer: loves, adores + + // john loves mary + // jonathan adores meridith + // john sameAs jonathan + // mary sameAs meridith + // answer: loves, adores + + IGeneric s = sSkin.asGeneric(); + + IGeneric o = oSkin.asGeneric(); + + GGraph graph = getGraph(); + + Set sSames = getSames( s ); + + Set oSames = getSames( o ); + + Set soTuples = new HashSet(); + + // calculate cross product + + for ( Iterator sSamesIt = sSames.iterator(); sSamesIt.hasNext(); ) { + + IGeneric sSame = (IGeneric) sSamesIt.next(); + + GValue sSameSkin = (GValue) sSame.asClass( sSkin.getClass() ); + + for ( Iterator oSamesIt = oSames.iterator(); oSamesIt.hasNext(); ) { + + IGeneric oSame = (IGeneric) oSamesIt.next(); + + GValue oSameSkin = (GValue) oSame.asClass( oSkin.getClass() ); + + soTuples.add( new Tuple( sSameSkin, oSameSkin ) ); + + } + + } + + // calculate the inferences + + for ( Iterator soIt = soTuples.iterator(); soIt.hasNext(); ) { + + Tuple soTuple = (Tuple) soIt.next(); + + StatementIterator it = graph.search( soTuple.a, null, soTuple.b ); + + while ( it.hasNext() ) { + + GStatement stmt = (GStatement) it.next(); + + GURI pSkin = stmt.getGPredicate(); + + // ignore explicit answers to the question + + if ( graph.lookup( s, pSkin.asGeneric(), o ) == null ) { + + stmts.add + ( new TransientInference + ( sSkin, + pSkin, + oSkin + ) + ); + + } + + } + + } + + } + private class POTuple implements Comparable { *************** *** 975,978 **** --- 1052,1119 ---- } + private class Tuple implements Comparable + { + + public GValue aSkin, bSkin; + + public IGeneric a, b; + + private int hashCode; + + private String toString; + + public Tuple( GValue aSkin, GValue bSkin ) + { + + this.aSkin = aSkin; + + this.bSkin = bSkin; + + this.a = aSkin.asGeneric(); + + this.b = bSkin.asGeneric(); + + this.hashCode = ( a.identity() + b.identity() ).hashCode(); + + this.toString = "(" + a.identity() + ", " + b.identity() + ")"; + + } + + public int hashCode() + { + + return hashCode; + + } + + public String toString() + { + + return toString; + + } + + public boolean equals( Object obj ) + { + + return compareTo( obj ) == 0; + + } + + public int compareTo( Object obj ) + { + + if ( obj == this ) { + + return 0; + + } + + return obj.toString().compareTo( toString ); + + } + + } + private Set getSames( IGeneric g ) { |