-
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 #314 from LiUSemWeb/propertyMapping
Add PropertyMapping and corresponding tests
- Loading branch information
Showing
9 changed files
with
382 additions
and
29 deletions.
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
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
35 changes: 35 additions & 0 deletions
35
src/main/java/se/liu/ida/hefquin/engine/wrappers/lpgwrapper/impl/PropertyNameMapping.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,35 @@ | ||
package se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl; | ||
|
||
import org.apache.jena.graph.Node; | ||
|
||
|
||
/** | ||
* This interface captures the notion of a property name mapping that is part of the notion of an LPG-to-RDF configuration, | ||
* where such a property name mapping is an injective function from names of properties in LPGs to IRIs nodes as | ||
* can occur in RDF graphs. | ||
* This interface contains the functions: | ||
* -map: map String of properties to IRIs properties | ||
* -unmap: map IRIs properties to String | ||
* -isPossibleResult: Check if the given RDF term is in the image of this property mapping | ||
*/ | ||
public interface PropertyNameMapping { | ||
/** | ||
* Returns the IRI (in the form of a Jena {@link Node} object) that is the result of | ||
* applying this property name mapping to the given property name. | ||
*/ | ||
Node map(String property); | ||
|
||
/** | ||
* Returns the String that corresponds to the given RDF term. | ||
* It applies the inverse of this property mapping to the given RDF term (which is assumed to be | ||
* an IRI) in order to obtain the corresponding String. | ||
*/ | ||
String unmap(Node node); | ||
|
||
/** | ||
* Check if the given RDF term is in the image of this property mapping and, | ||
* thus, may be one of the RDF terms returned by the {@link #map(String)} | ||
* function for some String. | ||
*/ | ||
boolean isPossibleResult(Node node); | ||
} |
31 changes: 31 additions & 0 deletions
31
...ava/se/liu/ida/hefquin/engine/wrappers/lpgwrapper/impl/PropertyNameMappingToURIsImpl.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,31 @@ | ||
package se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl; | ||
|
||
import org.apache.jena.graph.Node; | ||
import org.apache.jena.graph.NodeFactory; | ||
|
||
public class PropertyNameMappingToURIsImpl implements PropertyNameMapping { | ||
|
||
protected final String NSPROPERTY; | ||
|
||
|
||
public PropertyNameMappingToURIsImpl(final String NSPROPERTY){ | ||
this.NSPROPERTY=NSPROPERTY ; | ||
} | ||
|
||
@Override | ||
public Node map(final String propertyName) { | ||
return NodeFactory.createURI(NSPROPERTY + propertyName); | ||
} | ||
|
||
@Override | ||
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 property name mapping."); | ||
return node.getURI().replaceAll(NSPROPERTY, ""); | ||
} | ||
|
||
@Override | ||
public boolean isPossibleResult(final Node node) { | ||
return node.isURI() && node.getURI().startsWith(NSPROPERTY); | ||
} | ||
} |
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
Oops, something went wrong.