Skip to content

Commit

Permalink
Fixed a problem with selection head and tail IDs of an edge. Fixes #31.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRoeder committed Dec 21, 2021
1 parent d916200 commit abb25bc
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 44 deletions.
20 changes: 2 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<slf4j.version>1.7.15</slf4j.version>
<junit.version>4.11</junit.version>
<junit.version>4.13.2</junit.version>
</properties>

<repositories>
Expand Down Expand Up @@ -73,7 +73,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
<version>31.0.1-jre</version>
</dependency>

<!-- JMH Benchmark -->
Expand Down Expand Up @@ -111,22 +111,6 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<!-- JMH Benchmark -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>
<!-- End JMH Benchmark -->

<!-- ~~~~~~~~~~~~~~~~~~~ End Testing ~~~~~~~~~~~~~~~~~~~~~~ -->
</dependencies>

Expand Down
37 changes: 11 additions & 26 deletions src/main/java/org/aksw/simba/lemming/ColouredGraph.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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<Integer, Map<BitSet, List<String>>> mapVertexIdAndLiterals;

/*
/**
* map for storing type of literal accordingly to the data typed property edge
*/
protected Map<BitSet, String> mapLiteralTypes;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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&ouml;der ([email protected])
*
*/
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));
}
}
}
}
8 changes: 8 additions & 0 deletions src/test/resources/head_tail_edge_selection.n3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<http://example.org/entity1> <http://example.org/relation1> <http://example.org/entity2> .
<http://example.org/entity1> <http://example.org/relation1> <http://example.org/entity3> .
<http://example.org/entity14> <http://example.org/relation1> <http://example.org/entity2> .
<http://example.org/entity10> <http://example.org/relation1> <http://example.org/entity2> .
<http://example.org/entity10> <http://example.org/relation1> <http://example.org/entity3> .
<http://example.org/entity10> <http://example.org/relation2> <http://example.org/entity3> .
<http://example.org/entity10> <http://example.org/relation3> <http://example.org/entity2> .
<http://example.org/entity1> <http://example.org/relation4> <http://example.org/entity10> .

0 comments on commit abb25bc

Please sign in to comment.