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 3832517A6B for ; Thu, 19 Mar 2015 13:46:22 +0000 (UTC) Received: (qmail 70193 invoked by uid 500); 19 Mar 2015 13:46:16 -0000 Delivered-To: apmail-clerezza-commits-archive@clerezza.apache.org Received: (qmail 70131 invoked by uid 500); 19 Mar 2015 13:46:15 -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 70111 invoked by uid 99); 19 Mar 2015 13:46:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Mar 2015 13:46:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A6BD0E1925; Thu, 19 Mar 2015 13:46:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: reto@apache.org To: commits@clerezza.apache.org Date: Thu, 19 Mar 2015 13:46:17 -0000 Message-Id: <993e52419bee4fffa622f098b43beb7f@git.apache.org> In-Reply-To: <551c56288da54a478adaf182731064e7@git.apache.org> References: <551c56288da54a478adaf182731064e7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/3] clerezza-rdf-core git commit: CLEREZZA-959: moved graph isomorphisms tests to here CLEREZZA-959: moved graph isomorphisms tests to here Project: http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/repo Commit: http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/commit/df00e82d Tree: http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/tree/df00e82d Diff: http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/diff/df00e82d Branch: refs/heads/master Commit: df00e82df710bc6c29e8e9a9353a92131217af89 Parents: 94a9a13 Author: Reto Gmuer Authored: Thu Mar 19 13:45:35 2015 +0000 Committer: Reto Gmuer Committed: Thu Mar 19 13:45:35 2015 +0000 ---------------------------------------------------------------------- .../utils/graphmatching/GraphMatcherTest.java | 211 +++++++++++++++++++ .../utils/graphmatching/HashMatchingTest.java | 51 +++++ .../graphmatching/PermutationIteratorTest.java | 78 +++++++ .../impl/utils/graphmatching/Utils4Testing.java | 51 +++++ 4 files changed, 391 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/blob/df00e82d/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/GraphMatcherTest.java ---------------------------------------------------------------------- diff --git a/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/GraphMatcherTest.java b/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/GraphMatcherTest.java new file mode 100644 index 0000000..5c43c1b --- /dev/null +++ b/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/GraphMatcherTest.java @@ -0,0 +1,211 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.rdf.impl.utils.graphmatching; + +import org.apache.commons.rdf.impl.utils.graphmatching.GraphMatcher; +import java.util.Map; +import org.apache.commons.rdf.BlankNode; +import org.apache.commons.rdf.Graph; +import org.apache.commons.rdf.BlankNodeOrIri; +import org.apache.commons.rdf.RdfTerm; +import org.apache.commons.rdf.Triple; +import org.apache.commons.rdf.Graph; +import org.apache.commons.rdf.Iri; +import org.apache.commons.rdf.impl.utils.simple.SimpleMGraph; +import org.apache.commons.rdf.impl.utils.TripleImpl; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author reto + */ +public class GraphMatcherTest { + + final static Iri u1 = new Iri("http://example.org/u1"); + + @Test + public void testEmpty() { + Graph tc1 = new SimpleMGraph(); + Graph tc2 = new SimpleMGraph(); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNotNull(mapping); + Assert.assertEquals(0, mapping.size()); + } + + @Test + public void test2() { + Graph tc1 = new SimpleMGraph(); + tc1.add(new TripleImpl(u1, u1, u1)); + Graph tc2 = new SimpleMGraph(); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNull(mapping); + } + + @Test + public void test3() { + Graph tc1 = new SimpleMGraph(); + tc1.add(new TripleImpl(u1, u1, u1)); + Graph tc2 = new SimpleMGraph(); + tc2.add(new TripleImpl(u1, u1, u1)); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNotNull(mapping); + Assert.assertEquals(0, mapping.size()); + } + + @Test + public void test4() { + Graph tc1 = new SimpleMGraph(); + tc1.add(new TripleImpl(u1, u1, new BlankNode())); + Graph tc2 = new SimpleMGraph(); + tc2.add(new TripleImpl(u1, u1, new BlankNode())); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNotNull(mapping); + Assert.assertEquals(1, mapping.size()); + } + + @Test + public void test5() { + Graph tc1 = new SimpleMGraph(); + tc1.add(new TripleImpl(new BlankNode(), u1, new BlankNode())); + Graph tc2 = new SimpleMGraph(); + tc2.add(new TripleImpl(new BlankNode(), u1, new BlankNode())); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNotNull(mapping); + Assert.assertEquals(2, mapping.size()); + } + + @Test + public void test6() { + Graph tc1 = new SimpleMGraph(); + final BlankNode b11 = new BlankNode(); + tc1.add(new TripleImpl(new BlankNode(), u1,b11)); + tc1.add(new TripleImpl(new BlankNode(), u1,b11)); + Graph tc2 = new SimpleMGraph(); + tc2.add(new TripleImpl(new BlankNode(), u1, new BlankNode())); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNull(mapping); + } + + private Graph generateCircle(int size) { + return generateCircle(size, new BlankNode()); + } + + private Graph generateCircle(int size, final BlankNodeOrIri firstNode) { + if (size < 1) { + throw new IllegalArgumentException(); + } + Graph result = new SimpleMGraph(); + BlankNodeOrIri lastNode = firstNode; + for (int i = 0; i < (size-1); i++) { + final BlankNode newNode = new BlankNode(); + result.add(new TripleImpl(lastNode, u1, newNode)); + lastNode = newNode; + } + result.add(new TripleImpl(lastNode, u1, firstNode)); + return result; + } + + @Test + public void test7() { + Graph tc1 = generateCircle(2); + Graph tc2 = generateCircle(2); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNotNull(mapping); + Assert.assertEquals(2, mapping.size()); + } + + @Test + public void test8() { + Graph tc1 = generateCircle(5); + Graph tc2 = generateCircle(5); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNotNull(mapping); + Assert.assertEquals(5, mapping.size()); + } + + @Test + public void test9() { + BlankNodeOrIri crossing = new Iri("http://example.org/"); + Graph tc1 = generateCircle(2,crossing); + tc1.addAll(generateCircle(3,crossing)); + Graph tc2 = generateCircle(2,crossing); + tc2.addAll(generateCircle(3,crossing)); + Assert.assertEquals(5, tc1.size()); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNotNull(mapping); + //a circle of 2 with 1 bnode and one of 2 bnodes + Assert.assertEquals(3, mapping.size()); + } + + @Test + public void test10() { + BlankNodeOrIri crossing1 = new BlankNode(); + Graph tc1 = generateCircle(2,crossing1); + tc1.addAll(generateCircle(3,crossing1)); + BlankNodeOrIri crossing2 = new BlankNode(); + Graph tc2 = generateCircle(2,crossing2); + tc2.addAll(generateCircle(3,crossing2)); + Assert.assertEquals(5, tc1.size()); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNotNull(mapping); + //a circle of 2 and one of 3 with one common node + Assert.assertEquals(4, mapping.size()); + } + + @Test + public void test11() { + BlankNodeOrIri crossing1 = new BlankNode(); + Graph tc1 = generateCircle(2,crossing1); + tc1.addAll(generateCircle(4,crossing1)); + BlankNodeOrIri crossing2 = new BlankNode(); + Graph tc2 = generateCircle(3,crossing2); + tc2.addAll(generateCircle(3,crossing2)); + Assert.assertEquals(6, tc1.size()); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNull(mapping); + } + + @Test + public void test12() { + BlankNodeOrIri start1 = new BlankNode(); + Graph tc1 = Utils4Testing.generateLine(4,start1); + tc1.addAll(Utils4Testing.generateLine(5,start1)); + BlankNodeOrIri start2 = new BlankNode(); + Graph tc2 = Utils4Testing.generateLine(5,start2); + tc2.addAll(Utils4Testing.generateLine(4,start2)); + Assert.assertEquals(9, tc1.size()); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNotNull(mapping); + Assert.assertEquals(10, mapping.size()); + } + + @Test + public void test13() { + BlankNodeOrIri start1 = new BlankNode(); + Graph tc1 = Utils4Testing.generateLine(4,start1); + tc1.addAll(Utils4Testing.generateLine(5,start1)); + BlankNodeOrIri start2 = new BlankNode(); + Graph tc2 = Utils4Testing.generateLine(3,start2); + tc2.addAll(Utils4Testing.generateLine(3,start2)); + Assert.assertEquals(9, tc1.size()); + final Map mapping = GraphMatcher.getValidMapping(tc1, tc2); + Assert.assertNull(mapping); + } +} http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/blob/df00e82d/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/HashMatchingTest.java ---------------------------------------------------------------------- diff --git a/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/HashMatchingTest.java b/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/HashMatchingTest.java new file mode 100644 index 0000000..baac5b9 --- /dev/null +++ b/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/HashMatchingTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.commons.rdf.impl.utils.graphmatching; + + +import java.util.Map; + +import org.apache.commons.rdf.BlankNode; +import org.apache.commons.rdf.Graph; +import org.apache.commons.rdf.BlankNodeOrIri; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author reto + */ +public class HashMatchingTest { + + @Test + public void twoLine() throws GraphNotIsomorphicException { + BlankNodeOrIri start1 = new BlankNode(); + Graph tc1 = Utils4Testing.generateLine(4,start1); + tc1.addAll(Utils4Testing.generateLine(5,start1)); + BlankNodeOrIri start2 = new BlankNode(); + Graph tc2 = Utils4Testing.generateLine(5,start2); + tc2.addAll(Utils4Testing.generateLine(4,start2)); + Assert.assertEquals(9, tc1.size()); + final Map mapping = new HashMatching(tc1, tc2).getMatchings(); + Assert.assertNotNull(mapping); + Assert.assertEquals(10, mapping.size()); + } + +} http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/blob/df00e82d/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/PermutationIteratorTest.java ---------------------------------------------------------------------- diff --git a/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/PermutationIteratorTest.java b/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/PermutationIteratorTest.java new file mode 100644 index 0000000..6616060 --- /dev/null +++ b/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/PermutationIteratorTest.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.commons.rdf.impl.utils.graphmatching; + +import org.apache.commons.rdf.impl.utils.graphmatching.PermutationIterator; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author reto + */ +public class PermutationIteratorTest { + + @Test + public void simple() { + List list = new ArrayList(); + PermutationIterator pi = new PermutationIterator(list); + Assert.assertFalse(pi.hasNext()); + } + + @Test + public void lessSimple() { + List list = new ArrayList(); + list.add("Hasan"); + PermutationIterator pi = new PermutationIterator(list); + Assert.assertTrue(pi.hasNext()); + } + + @Test + public void regular() { + List list = new ArrayList(); + list.add("Hasan"); + list.add("Tsuy"); + PermutationIterator pi = new PermutationIterator(list); + Set> permutations = new HashSet>(); + while (pi.hasNext()) { + permutations.add(pi.next()); + } + Assert.assertEquals(2, permutations.size()); + } + + @Test + public void extended() { + List list = new ArrayList(); + list.add("Hasan"); + list.add("Tsuy"); + list.add("Llena"); + PermutationIterator pi = new PermutationIterator(list); + Set> permutations = new HashSet>(); + while (pi.hasNext()) { + permutations.add(pi.next()); + } + Assert.assertEquals(6, permutations.size()); + } + +} http://git-wip-us.apache.org/repos/asf/clerezza-rdf-core/blob/df00e82d/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/Utils4Testing.java ---------------------------------------------------------------------- diff --git a/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/Utils4Testing.java b/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/Utils4Testing.java new file mode 100644 index 0000000..3246575 --- /dev/null +++ b/impl.utils/src/test/java/org/apache/commons/rdf/impl/utils/graphmatching/Utils4Testing.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.commons.rdf.impl.utils.graphmatching; + +import org.apache.commons.rdf.BlankNode; +import org.apache.commons.rdf.Graph; +import org.apache.commons.rdf.BlankNodeOrIri; +import org.apache.commons.rdf.Iri; +import org.apache.commons.rdf.impl.utils.simple.SimpleMGraph; +import org.apache.commons.rdf.impl.utils.TripleImpl; + +/** + * + * @author reto + */ +public class Utils4Testing { + + static Graph generateLine(int size, final BlankNodeOrIri firstNode) { + if (size < 1) { + throw new IllegalArgumentException(); + } + Graph result = new SimpleMGraph(); + BlankNodeOrIri lastNode = firstNode; + for (int i = 0; i < size; i++) { + final BlankNode newNode = new BlankNode(); + result.add(new TripleImpl(lastNode, u1, newNode)); + lastNode = newNode; + } + return result; + } + + final static Iri u1 = new Iri("http://example.org/u1"); + +}