-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316 from LiUSemWeb/singleEdgeLabelMapping
Add SingleEdgeLabelMapping and its tests
- Loading branch information
Showing
6 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
.../se/liu/ida/hefquin/engine/wrappers/lpgwrapper/impl/SingleEdgeLabelMappingToURIsImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl; | ||
|
||
import org.apache.jena.graph.Node; | ||
import org.apache.jena.graph.NodeFactory; | ||
|
||
public class SingleEdgeLabelMappingToURIsImpl implements EdgeLabelMapping { | ||
|
||
protected final String label; | ||
protected final Node node; | ||
|
||
public SingleEdgeLabelMappingToURIsImpl(final String label, final String iri){ | ||
this.label=label; | ||
this.node = NodeFactory.createURI(iri); | ||
} | ||
|
||
@Override | ||
public Node map(final String label) { | ||
if (label.equals(this.label)) { | ||
return this.node; | ||
} | ||
else { | ||
throw new IllegalArgumentException("The given edge label (" + label + ") is not a supported label in the image of this edge label mapping."); | ||
} | ||
} | ||
|
||
public String unmap(final Node node) { | ||
if (!isPossibleResult(node)) | ||
throw new IllegalArgumentException("The given RDF term (" + node.toString() + ") is not an URI node or not in the image of this edge label mapping."); | ||
return this.label; | ||
} | ||
|
||
@Override | ||
public boolean isPossibleResult(final Node node) { | ||
return node.isURI() && node.getURI().equals(this.node.getURI()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...liu/ida/hefquin/engine/wrappers/lpgwrapper/impl/SingleEdgeLabelMappingToURIsImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl; | ||
|
||
import org.apache.jena.graph.Node; | ||
import org.apache.jena.graph.NodeFactory; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class SingleEdgeLabelMappingToURIsImplTest { | ||
|
||
protected final String label="DIRECTED"; | ||
protected final String iri="http://singleExample.org/directorOf"; | ||
protected final EdgeLabelMapping singleEdgeLabelMapping = new SingleEdgeLabelMappingToURIsImpl(label,iri); | ||
|
||
@Test | ||
public void mapSingleEdgeLabel() { | ||
final Node resultNode = singleEdgeLabelMapping.map("DIRECTED"); | ||
assertNotNull(resultNode); | ||
assertTrue(resultNode.isURI()); | ||
assertEquals(resultNode.getURI(),"http://singleExample.org/directorOf"); | ||
} | ||
|
||
@Test | ||
public void unmapSingleURIEdgeLabel(){ | ||
final Node node = NodeFactory.createURI("http://singleExample.org/directorOf"); | ||
final String resultString = singleEdgeLabelMapping.unmap(node); | ||
assertNotNull(resultString); | ||
assertEquals(resultString, "DIRECTED"); | ||
} | ||
|
||
@Test | ||
public void edgeLabelIsPossibleResult(){ | ||
final Node IRINode = NodeFactory.createURI("http://singleExample.org/directorOf"); | ||
final boolean IRIIsPossible = singleEdgeLabelMapping.isPossibleResult(IRINode); | ||
assertTrue(IRIIsPossible); | ||
} | ||
|
||
|
||
|
||
/* | ||
* In this test case, a node with an invalid URI is provided as an argument to the SingleEdgeLabelMappingToURIsImpl. | ||
*/ | ||
@Test(expected = IllegalArgumentException.class) | ||
public void unmapEdgeLabelWithInvalidURI(){ | ||
final Node node = NodeFactory.createURI("https://example.org/3"); | ||
singleEdgeLabelMapping.unmap(node); | ||
} | ||
|
||
/* | ||
* In this test case, a label which is not equal with the given label in SingleEdgeLabelMappingToURIsImpl. | ||
*/ | ||
@Test(expected = IllegalArgumentException.class) | ||
public void mapEdgeLabelWithUnmatchedLabel(){ | ||
final String label = "test"; | ||
singleEdgeLabelMapping.map(label); | ||
} | ||
|
||
} |