clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1530930 - /clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
Date Thu, 10 Oct 2013 11:50:05 GMT
Author: reto
Date: Thu Oct 10 11:50:05 2013
New Revision: 1530930

URL: http://svn.apache.org/r1530930
Log:
CLEREZZA-830: added method for owl:sameAs smushing

Modified:
    clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java

Modified: clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java?rev=1530930&r1=1530929&r2=1530930&view=diff
==============================================================================
--- clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java (original)
+++ clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java Thu
Oct 10 11:50:05 2013
@@ -36,6 +36,8 @@ import org.apache.clerezza.rdf.core.impl
 import org.apache.clerezza.rdf.core.impl.TripleImpl;
 import org.apache.clerezza.rdf.ontologies.OWL;
 import org.apache.clerezza.rdf.ontologies.RDF;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A utility to equate duplicate nodes in an Mgarph, currently only nodes with 
@@ -44,6 +46,8 @@ import org.apache.clerezza.rdf.ontologie
  * @author reto
  */
 public class Smusher {
+    
+    static final Logger log = LoggerFactory.getLogger(Smusher.class);
 
     /**
      * smush mGaph given the ontological facts. Currently it does only
@@ -76,6 +80,51 @@ public class Smusher {
         smush(mGraph, unitedEquivalenceSets);
     }
     
+    public static void sameAsSmush(MGraph mGraph, TripleCollection owlSameStatements) {
+    	
+    	log.info("Starting smushing");
+        
+    	// This hashmap contains a uri (key) and the set of equivalent uris (value)
+    	final Map<NonLiteral, Set<NonLiteral>> node2EquivalenceSet = new HashMap<NonLiteral,
Set<NonLiteral>>();
+    	
+    	log.info("Creating the sets of equivalent uris of each subject or object in the owl:sameAs
statements");
+    	// Determines for each subject and object in all the owl:sameAs statements the set of
ewquivalent uris 
+    	for (Iterator<Triple> it = owlSameStatements.iterator(); it.hasNext();) {    
       
+    		final Triple triple = it.next();
+            final UriRef predicate = triple.getPredicate();
+            if (!predicate.equals(OWL.sameAs)) {
+                throw new RuntimeException("Statements must use only <http://www.w3.org/2002/07/owl#sameAs>
predicate.");
+            }
+            final NonLiteral subject = triple.getSubject();
+            final NonLiteral object = (NonLiteral)triple.getObject();
+            
+            Set<NonLiteral> equivalentNodes = node2EquivalenceSet.get(subject);
+            
+            // if there is not a set of equivalent uris then create a new set
+            if (equivalentNodes == null) {
+            	equivalentNodes = node2EquivalenceSet.get(object);
+            	if (equivalentNodes == null) {
+                    equivalentNodes = new HashSet<NonLiteral>();
+                }
+            }
+            
+            // add both subject and object of the owl:sameAs statement to the set of equivalent
uris
+            equivalentNodes.add(subject);
+            equivalentNodes.add(object);
+            
+            // use both uris in the owl:sameAs statement as keys for the set of equivalent
uris
+            node2EquivalenceSet.put(subject, equivalentNodes);
+            node2EquivalenceSet.put(object, equivalentNodes);
+            
+            log.info("Sets of equivalent uris created.");
+        
+    	}
+    	
+    	// This set contains the sets of equivalent uris
+    	Set<Set<NonLiteral>> unitedEquivalenceSets = new HashSet<Set<NonLiteral>>(node2EquivalenceSet.values());
+        smush(mGraph, unitedEquivalenceSets);
+    }
+    
     public static void smush(MGraph mGraph, Set<Set<NonLiteral>> unitedEquivalenceSets)
{
         Map<NonLiteral, NonLiteral> current2ReplacementMap = new HashMap<NonLiteral,
NonLiteral>();
         final MGraph owlSameAsGraph = new SimpleMGraph();



Mime
View raw message