clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1538946 - in /clerezza/trunk/rdf.utils/src: main/java/org/apache/clerezza/rdf/utils/Smusher.java main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
Date Tue, 05 Nov 2013 11:26:15 GMT
Author: reto
Date: Tue Nov  5 11:26:14 2013
New Revision: 1538946

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

Added:
    clerezza/trunk/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
      - copied, changed from r1538922, clerezza/trunk/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
Modified:
    clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/Smusher.java
    clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.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=1538946&r1=1538945&r2=1538946&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 Tue
Nov  5 11:26:14 2013
@@ -50,6 +50,12 @@ public class Smusher {
         smush(lockable(mGraph), tBox);
     }
 
+    /**
+     * Smushes the specified graph adding owl:sameAs statements pointing to the new canonical
IRI
+     * 
+     * @param mGraph
+     * @param owlSameStatements 
+     */
     public static void sameAsSmush(MGraph mGraph, TripleCollection owlSameStatements) {
         sameAsSmush(lockable(mGraph), owlSameStatements);
     }

Modified: clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java?rev=1538946&r1=1538945&r2=1538946&view=diff
==============================================================================
--- clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
(original)
+++ clerezza/trunk/rdf.utils/src/main/java/org/apache/clerezza/rdf/utils/smushing/SameAsSmusher.java
Tue Nov  5 11:26:14 2013
@@ -48,7 +48,7 @@ public class SameAsSmusher extends BaseS
      * to the preferedIri as returned by {@code getPreferedIri}
      * @param mGraph
      * @param owlSameStatements 
-     * @param addCanonicalSameAsStatements if true owl:sameAsSteemntes with the preferedIri
as object will be added
+     * @param addCanonicalSameAsStatements if true owl:sameAsStatements with the preferedIri
as object will be added
      */
     public void smush(LockableMGraph mGraph, 
             TripleCollection owlSameStatements,

Copied: clerezza/trunk/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
(from r1538922, clerezza/trunk/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java)
URL: http://svn.apache.org/viewvc/clerezza/trunk/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java?p2=clerezza/trunk/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java&p1=clerezza/trunk/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java&r1=1538922&r2=1538946&rev=1538946&view=diff
==============================================================================
--- clerezza/trunk/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/IfpSmushTest.java
(original)
+++ clerezza/trunk/rdf.utils/src/test/java/org/apache/clerezza/rdf/utils/SameAsSmushTest.java
Tue Nov  5 11:26:14 2013
@@ -18,9 +18,14 @@
  */
 package org.apache.clerezza.rdf.utils;
 
+import java.util.Iterator;
 import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Literal;
 import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.PlainLiteral;
+import org.apache.clerezza.rdf.core.Triple;
 import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
 import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
 import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
 import org.apache.clerezza.rdf.core.impl.TripleImpl;
@@ -35,81 +40,41 @@ import org.junit.Test;
  *
  * @author reto
  */
-public class IfpSmushTest {
+public class SameAsSmushTest {
+    
+    private final UriRef uriA = new UriRef("http://example.org/A");
+    private final UriRef uriB = new UriRef("http://example.org/B");
+    private final Literal lit = new PlainLiteralImpl("That's me (and you)");
 
-    private MGraph ontology = new SimpleMGraph();
+    private MGraph sameAsStatements = new SimpleMGraph();
     {
-        ontology.add(new TripleImpl(FOAF.mbox, RDF.type, OWL.InverseFunctionalProperty));
+        sameAsStatements.add(new TripleImpl(uriA, OWL.sameAs, uriB));
     }
-
-    @Test
-    public void simpleBNode()  {
-        MGraph mGraph = new SimpleMGraph();
-        UriRef mbox1 = new UriRef("mailto:foo@example.org");
-        final BNode bNode1 = new BNode();
-        mGraph.add(new TripleImpl(bNode1, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode1, RDFS.comment, 
-                new PlainLiteralImpl("a comment")));
-        final BNode bNode2 = new BNode();
-        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode2, RDFS.comment, 
-                new PlainLiteralImpl("another comment")));
-        Smusher.smush(mGraph, ontology);
-        Assert.assertEquals(3, mGraph.size());
-    }
-
-    @Test
-    public void overlappingEquivalenceClasses()  {
-        MGraph mGraph = new SimpleMGraph();
-        UriRef mbox1 = new UriRef("mailto:foo@example.org");
-        final BNode bNode1 = new BNode();
-        mGraph.add(new TripleImpl(bNode1, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode1, RDFS.comment,
-                new PlainLiteralImpl("a comment")));
-        final BNode bNode2 = new BNode();
-        UriRef mbox2 = new UriRef("mailto:bar@example.org");
-        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox2));
-        mGraph.add(new TripleImpl(bNode2, RDFS.comment,
-                new PlainLiteralImpl("another comment")));
-        final BNode bNode3 = new BNode();
-        mGraph.add(new TripleImpl(bNode3, FOAF.mbox, mbox2));
-        mGraph.add(new TripleImpl(bNode3, RDFS.comment,
-                new PlainLiteralImpl("yet another comment")));
-        Smusher.smush(mGraph, ontology);
-        Assert.assertEquals(5, mGraph.size());
-    }
-
-    @Test
-    public void oneUriRef()  {
-        MGraph mGraph = new SimpleMGraph();
-        UriRef mbox1 = new UriRef("mailto:foo@example.org");
-        final UriRef resource = new UriRef("http://example.org/");
-        mGraph.add(new TripleImpl(resource, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(resource, RDFS.comment,
-                new PlainLiteralImpl("a comment")));
-        final BNode bNode2 = new BNode();
-        mGraph.add(new TripleImpl(bNode2, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(bNode2, RDFS.comment,
-                new PlainLiteralImpl("another comment")));
-        Smusher.smush(mGraph, ontology);
-        Assert.assertEquals(3, mGraph.size());
+    
+    private MGraph  dataGraph = new SimpleMGraph();
+    {
+        dataGraph.add(new TripleImpl(uriA, FOAF.knows, uriB));
+        dataGraph.add(new TripleImpl(uriB, RDFS.label, lit));
+        dataGraph.add(new TripleImpl(uriA, RDFS.label, lit));
     }
 
     @Test
-    public void twoUriRefs()  {
-        MGraph mGraph = new SimpleMGraph();
-        UriRef mbox1 = new UriRef("mailto:foo@example.org");
-        final UriRef resource1 = new UriRef("http://example.org/");
-        mGraph.add(new TripleImpl(resource1, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(resource1, RDFS.comment,
-                new PlainLiteralImpl("a comment")));
-        final UriRef resource2 = new UriRef("http://2.example.org/");
-        mGraph.add(new TripleImpl(resource2, FOAF.mbox, mbox1));
-        mGraph.add(new TripleImpl(resource2, RDFS.comment,
-                new PlainLiteralImpl("another comment")));
-        Smusher.smush(mGraph, ontology);
-        Assert.assertEquals(4, mGraph.size());
+    public void simple()  {
+        Assert.assertEquals(3, dataGraph.size());
+        Smusher.sameAsSmush(dataGraph, sameAsStatements);
+        Assert.assertEquals(3, dataGraph.size());
+        Assert.assertTrue(dataGraph.filter(null, OWL.sameAs, null).hasNext());
+        //exactly one statement with literal 
+        Iterator<Triple> litStmts = dataGraph.filter(null, null, lit);
+        Assert.assertTrue(litStmts.hasNext());
+        Triple litStmt = litStmts.next();
+        Assert.assertFalse(litStmts.hasNext());
+        Iterator<Triple> knowsStmts = dataGraph.filter(null, FOAF.knows, null);
+        Assert.assertTrue(knowsStmts.hasNext());
+        Triple knowStmt = knowsStmts.next();
+        Assert.assertEquals(knowStmt.getSubject(), knowStmt.getObject());
+        Assert.assertEquals(litStmt.getSubject(), knowStmt.getObject());
+        Assert.assertEquals(litStmt.getSubject(), dataGraph.filter(null, OWL.sameAs, null).next().getObject());
     }
 
 }



Mime
View raw message