Return-Path: X-Original-To: apmail-clerezza-commits-archive@www.apache.org Delivered-To: apmail-clerezza-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6C9FA10F40 for ; Thu, 10 Oct 2013 11:50:31 +0000 (UTC) Received: (qmail 71316 invoked by uid 500); 10 Oct 2013 11:50:30 -0000 Delivered-To: apmail-clerezza-commits-archive@clerezza.apache.org Received: (qmail 71285 invoked by uid 500); 10 Oct 2013 11:50:27 -0000 Mailing-List: contact commits-help@clerezza.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@clerezza.apache.org Delivered-To: mailing list commits@clerezza.apache.org Received: (qmail 71277 invoked by uid 99); 10 Oct 2013 11:50:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Oct 2013 11:50:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Oct 2013 11:50:26 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E42B2238899C; Thu, 10 Oct 2013 11:50:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@clerezza.apache.org From: reto@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131010115005.E42B2238899C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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> node2EquivalenceSet = new HashMap>(); + + 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 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 predicate."); + } + final NonLiteral subject = triple.getSubject(); + final NonLiteral object = (NonLiteral)triple.getObject(); + + Set 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(); + } + } + + // 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> unitedEquivalenceSets = new HashSet>(node2EquivalenceSet.values()); + smush(mGraph, unitedEquivalenceSets); + } + public static void smush(MGraph mGraph, Set> unitedEquivalenceSets) { Map current2ReplacementMap = new HashMap(); final MGraph owlSameAsGraph = new SimpleMGraph();