-
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 #315 from LiUSemWeb/flexibleEdgeLabelMapping
Add RegexBasedEdgeLabelMapping and its tests
- Loading branch information
Showing
6 changed files
with
195 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
24 changes: 24 additions & 0 deletions
24
...liu/ida/hefquin/engine/wrappers/lpgwrapper/impl/RegexBasedEdgeLabelMappingToURIsImpl.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,24 @@ | ||
package se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl; | ||
|
||
import org.apache.jena.graph.Node; | ||
import org.apache.jena.graph.NodeFactory; | ||
|
||
public class RegexBasedEdgeLabelMappingToURIsImpl extends EdgeLabelMappingToURIsImpl { | ||
|
||
protected final String regex; | ||
|
||
public RegexBasedEdgeLabelMappingToURIsImpl(final String regex, final String NSRELATIONSHIP){ | ||
super(NSRELATIONSHIP); | ||
this.regex = regex; | ||
} | ||
|
||
@Override | ||
public Node map(final String label) { | ||
if (label.matches(regex)) { | ||
return super.map(label); | ||
} | ||
else { | ||
throw new IllegalArgumentException("The given edge label (" + label + ") is not a supported label in the image of this edge label mapping."); | ||
} | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
...ida/hefquin/engine/wrappers/lpgwrapper/impl/RegexBasedEdgeLabelMappingToURIsImplTest.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,57 @@ | ||
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 RegexBasedEdgeLabelMappingToURIsImplTest { | ||
protected final String NSRELATIONSHIP = "https://example2.org/test/"; | ||
protected final String regex = "^[0-9]+"; | ||
|
||
protected final EdgeLabelMapping edgeLabelMapping = new RegexBasedEdgeLabelMappingToURIsImpl(regex, NSRELATIONSHIP); | ||
|
||
@Test | ||
public void mapEdgeLabel() { | ||
final String label = "0"; | ||
final Node resultNode = edgeLabelMapping.map(label); | ||
assertNotNull(resultNode); | ||
assertTrue(resultNode.isURI()); | ||
assertEquals(resultNode.getURI(), NSRELATIONSHIP + "0"); | ||
} | ||
|
||
@Test | ||
public void unmapURIEdgeLabel(){ | ||
final Node node = NodeFactory.createURI(NSRELATIONSHIP + "0"); | ||
final String resultString = edgeLabelMapping.unmap(node); | ||
assertNotNull(resultString); | ||
assertEquals(resultString, "0"); | ||
} | ||
|
||
@Test | ||
public void edgeLabelIsPossibleResult(){ | ||
final Node IRINode = NodeFactory.createURI(NSRELATIONSHIP + "0"); | ||
final boolean IRIIsPossible = edgeLabelMapping.isPossibleResult(IRINode); | ||
assertTrue(IRIIsPossible); | ||
} | ||
|
||
|
||
/* | ||
* In this test case, a node with an invalid URI is provided as an argument to the RegexBasedEdgeLabelMappingToURIsImpl. | ||
*/ | ||
@Test(expected = IllegalArgumentException.class) | ||
public void unmapEdgeLabelWithInvalidURI(){ | ||
final Node node = NodeFactory.createURI("https://example.org/3"); | ||
edgeLabelMapping.unmap(node); | ||
} | ||
|
||
/* | ||
* In this test case, a label which is not match with provided regex in the RegexBasedEdgeLabelMappingToURIsImpl. | ||
*/ | ||
@Test(expected = IllegalArgumentException.class) | ||
public void mapEdgeLabelWithUnmatchedLabel(){ | ||
final String label = "test"; | ||
edgeLabelMapping.map(label); | ||
} | ||
} |