-
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.
Make PropertyNameMapping more flexible.
- Loading branch information
1 parent
05a1806
commit 0c1e89f
Showing
13 changed files
with
805 additions
and
33 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
46 changes: 46 additions & 0 deletions
46
...iu/ida/hefquin/engine/wrappers/lpgwrapper/impl/CombinedPropertyNameMappingToURIsImpl.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,46 @@ | ||
package se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl; | ||
|
||
import org.apache.jena.graph.Node; | ||
import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.exceptions.UnSupportedPropertyNameException; | ||
|
||
import java.util.List; | ||
|
||
public class CombinedPropertyNameMappingToURIsImpl implements PropertyNameMapping { | ||
|
||
protected final List<PropertyNameMapping> propertyNameMappings; | ||
|
||
public CombinedPropertyNameMappingToURIsImpl(final List<PropertyNameMapping> propertyNameMappings){ | ||
this.propertyNameMappings = propertyNameMappings; | ||
} | ||
|
||
@Override | ||
public Node map(final String propertyName) { | ||
for (final PropertyNameMapping propertyNameMapping : propertyNameMappings) { | ||
try { | ||
return propertyNameMapping.map(propertyName); | ||
} | ||
catch (UnSupportedPropertyNameException exception) {} | ||
} | ||
throw new UnSupportedPropertyNameException("The given property name (" + propertyName + ") is not a supported property name in the image of this property name mapping."); | ||
} | ||
|
||
public String unmap(final Node node) { | ||
for (final PropertyNameMapping propertyNameMapping : propertyNameMappings) { | ||
try { | ||
return propertyNameMapping.unmap(node); | ||
} | ||
catch (UnSupportedPropertyNameException exception) {} | ||
} | ||
throw new UnSupportedPropertyNameException("The given RDF term (" + node.toString() + ") is not an URI node or not in the image of this property name mapping."); | ||
} | ||
|
||
@Override | ||
public boolean isPossibleResult(final Node node) { | ||
for (final PropertyNameMapping propertyNameMapping : propertyNameMappings) { | ||
if(propertyNameMapping.isPossibleResult(node)){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
.../ida/hefquin/engine/wrappers/lpgwrapper/impl/RegexBasedPropertyNameMappingToURIsImpl.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,23 @@ | ||
package se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl; | ||
|
||
import org.apache.jena.graph.Node; | ||
import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.exceptions.UnSupportedPropertyNameException; | ||
|
||
public class RegexBasedPropertyNameMappingToURIsImpl extends PropertyNameMappingToURIsImpl { | ||
|
||
protected final String regex; | ||
|
||
public RegexBasedPropertyNameMappingToURIsImpl(final String regex, final String NSPROPERTY){ | ||
super(NSPROPERTY); | ||
this.regex = regex; | ||
} | ||
@Override | ||
public Node map(final String propertyName) { | ||
if (propertyName.matches(regex)) { | ||
return super.map(propertyName); | ||
} | ||
else { | ||
throw new UnSupportedPropertyNameException("The given property name (" + propertyName + ") is not a supported property name in the image of this property name mapping."); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
.../liu/ida/hefquin/engine/wrappers/lpgwrapper/impl/SinglePropertyNameMappingToURIsImpl.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; | ||
import se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.exceptions.UnSupportedPropertyNameException; | ||
|
||
public class SinglePropertyNameMappingToURIsImpl implements PropertyNameMapping { | ||
|
||
protected final String propertyName; | ||
protected final Node node; | ||
|
||
public SinglePropertyNameMappingToURIsImpl(final String propertyName, final String iri){ | ||
this.propertyName=propertyName; | ||
this.node = NodeFactory.createURI(iri); | ||
} | ||
@Override | ||
public Node map(final String propertyName) { | ||
if (propertyName.equals(this.propertyName)) { | ||
return this.node; | ||
} | ||
else { | ||
throw new UnSupportedPropertyNameException("The given property name (" + propertyName + ") is not a supported property name in the image of this property name mapping."); | ||
} | ||
} | ||
|
||
public String unmap(final Node node) { | ||
if (!isPossibleResult(node)) | ||
throw new UnSupportedPropertyNameException("The given RDF term (" + node.toString() + ") is not an URI node or not in the image of this property name mapping."); | ||
return this.propertyName; | ||
} | ||
|
||
@Override | ||
public boolean isPossibleResult(final Node node) { | ||
return node.isURI() && node.getURI().equals(this.node.getURI()); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
.../hefquin/engine/wrappers/lpgwrapper/impl/exceptions/UnSupportedPropertyNameException.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,8 @@ | ||
package se.liu.ida.hefquin.engine.wrappers.lpgwrapper.impl.exceptions; | ||
|
||
public class UnSupportedPropertyNameException extends IllegalArgumentException{ | ||
|
||
public UnSupportedPropertyNameException(final String message){ | ||
super(message); | ||
} | ||
} |
Oops, something went wrong.