diff --git a/pom.xml b/pom.xml index 285d7d5d..41342c1f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ 1.8 1.8 1.7.15 - 4.11 + 4.13.2 @@ -73,7 +73,7 @@ com.google.guava guava - 23.6-jre + 31.0.1-jre @@ -111,22 +111,6 @@ ${junit.version} test - - - - org.openjdk.jmh - jmh-core - 1.19 - test - - - org.openjdk.jmh - jmh-generator-annprocess - 1.19 - test - - - diff --git a/src/main/java/org/aksw/simba/lemming/ColouredGraph.java b/src/main/java/org/aksw/simba/lemming/ColouredGraph.java index 2133e33f..f9430702 100644 --- a/src/main/java/org/aksw/simba/lemming/ColouredGraph.java +++ b/src/main/java/org/aksw/simba/lemming/ColouredGraph.java @@ -1,14 +1,6 @@ package org.aksw.simba.lemming; -import grph.DefaultIntSet; -import grph.Grph; -import grph.GrphAlgorithmCache; -import grph.algo.MultiThreadProcessing; -import grph.in_memory.InMemoryGrph; -import it.unimi.dsi.fastutil.ints.IntSet; - import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -25,6 +17,13 @@ import com.carrotsearch.hppc.BitSet; import com.carrotsearch.hppc.ObjectArrayList; +import grph.DefaultIntSet; +import grph.Grph; +import grph.GrphAlgorithmCache; +import grph.algo.MultiThreadProcessing; +import grph.in_memory.InMemoryGrph; +import it.unimi.dsi.fastutil.ints.IntSet; + public class ColouredGraph { private static final Logger LOGGER = LoggerFactory.getLogger(ColouredGraph.class); @@ -36,13 +35,13 @@ public class ColouredGraph { protected ColourPalette edgePalette; protected ColourPalette dtEdgePalette; - /* + /** * 1st key: vertex ID, 2nd key: data typed property and the values is the value * of the literal */ protected Map>> mapVertexIdAndLiterals; - /* + /** * map for storing type of literal accordingly to the data typed property edge */ protected Map mapLiteralTypes; @@ -324,25 +323,11 @@ public ColouredGraph copy() { } public int getTailOfTheEdge(int edgeId) { - IntSet vertices = graph.getVerticesIncidentToEdge(edgeId); - if (vertices.size() > 0) { - int[] arrVertIDs = vertices.toIntArray(); - return arrVertIDs[0]; - } - return -1; + return graph.getDirectedSimpleEdgeTail(edgeId); } public int getHeadOfTheEdge(int edgeId) { - IntSet vertices = graph.getVerticesIncidentToEdge(edgeId); - if (vertices.size() > 0) { - int[] arrVertIDs = vertices.toIntArray(); - if (arrVertIDs.length == 1) { - return arrVertIDs[0]; - } else { - return arrVertIDs[1]; - } - } - return -1; + return graph.getDirectedSimpleEdgeHead(edgeId); } /** diff --git a/src/test/java/org/aksw/simba/lemming/creation/EdgeHeadTailSelectionTest.java b/src/test/java/org/aksw/simba/lemming/creation/EdgeHeadTailSelectionTest.java new file mode 100644 index 00000000..4456eb24 --- /dev/null +++ b/src/test/java/org/aksw/simba/lemming/creation/EdgeHeadTailSelectionTest.java @@ -0,0 +1,54 @@ +package org.aksw.simba.lemming.creation; + +import java.io.IOException; +import java.io.InputStream; + +import org.aksw.simba.lemming.ColouredGraph; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; +import org.junit.Assert; +import org.junit.Test; + +import it.unimi.dsi.fastutil.ints.IntSet; + +/** + * This test checks whether the requested head and tail IDs for edges make + * sense. Related to issue #31 (https://github.com/dice-group/Lemming/issues/31). + * + * @author Michael Röder (michael.roeder@uni-paderborn.de) + * + */ +public class EdgeHeadTailSelectionTest { + + private static final String GRAPH_FILE1 = "head_tail_edge_selection.n3"; + + @Test + public void testcase1() throws IOException { + Model model = ModelFactory.createDefaultModel(); + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(GRAPH_FILE1);) { + model.read(is, null, "N3"); + } + + GraphCreator creator = new GraphCreator(); + ColouredGraph graph = creator.processModel(model); + + int numberOfVertices = graph.getVertices().size(); + IntSet edges; + for (int v = 0; v < numberOfVertices; ++v) { + edges = graph.getOutEdges(v); + for (int edge : edges) { + Assert.assertEquals( + "Found an outgoing edge of " + v + + " that has a tail with a different ID. That shouldn't happen!", + v, graph.getTailOfTheEdge(edge)); + } + edges = graph.getInEdges(v); + for (int edge : edges) { + Assert.assertEquals( + "Found an incoming edge of " + v + + " that has a head with a different ID. That shouldn't happen!", + v, graph.getHeadOfTheEdge(edge)); + } + } + } +} diff --git a/src/test/resources/head_tail_edge_selection.n3 b/src/test/resources/head_tail_edge_selection.n3 new file mode 100644 index 00000000..be622cac --- /dev/null +++ b/src/test/resources/head_tail_edge_selection.n3 @@ -0,0 +1,8 @@ + . + . + . + . + . + . + . + .