Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NodeLabelMapping more flexible #321

Merged
merged 3 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion ExampleLPG2RDF.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ PREFIX ex: <http://example.org/>
#
#ex:IRIBasedNodeLabelMapping a rdfs:Class ;
# rdfs:subClassOf ex:NodeLabelMapping .

#
#ex:RegexIRIBasedNodeLabelMapping a rdfs:Class ;
# rdfs:subClassOf ex:NodeLabelMapping .
#
#ex:SingleLiteralBasedNodeLabelMapping a rdfs:Class ;
# rdfs:subClassOf ex:NodeLabelMapping .
#
#ex:SingleIRIBasedNodeLabelMapping a rdfs:Class ;
# rdfs:subClassOf ex:NodeLabelMapping .
#
#ex:CombinedNodeLabelMapping a rdfs:Class ;
# rdfs:subClassOf ex:NodeLabelMapping .

#ex:EdgeLabelMapping a rdfs:Class ;
#
Expand Down Expand Up @@ -71,6 +83,14 @@ PREFIX ex: <http://example.org/>
#ex:prefixOfIRIs a rdf:Property ;
# rdfs:range xsd:anyURI .

#ex:literal a rdf:Property ;
# rdfs:domain ex:SingleLiteralBasedNodeLabelMapping ;
# rdfs:range xsd:string .

#ex:nodeLabelMappings a rdf:Property ;
# rdfs:domain ex:CombinedNodeLabelMapping ;
# rdfs:range rdfs:List .

#ex:edgeLabelMapping a rdf:Property ;
# rdfs:domain ex:LPGtoRDFConfiguration ;
# rdfs:range ex:EdgeLabelMapping .
Expand Down Expand Up @@ -107,7 +127,12 @@ PREFIX ex: <http://example.org/>
ex:LPGtoRDFConfig a lr:LPGtoRDFConfiguration ;
lr:labelPredicate "http://www.w3.org/2000/01/rdf-schema#label"^^xsd:anyURI ;
lr:nodeMapping ex:IRINodeMapping ;
lr:nodeLabelMapping ex:IRINodeLabelMapping ;
# lr:nodeLabelMapping ex:LiteralNodeLabelMapping ;
# lr:nodeLabelMapping ex:IRINodeLabelMapping ;
# lr:nodeLabelMapping ex:RegexIRINodeLabelMapping ;
# lr:nodeLabelMapping ex:SingleLiteralNodeLabelMapping ;
# lr:nodeLabelMapping ex:SingleIRINodeLabelMapping ;
lr:nodeLabelMapping ex:CombinedNodeLabelMapping ;
# lr:edgeLabelMapping ex:IRIEdgeLabelMapping ;
# lr:edgeLabelMapping ex:RegexEdgeLabelMapping ;
# lr:edgeLabelMapping ex:SingleIRIEdgeLabelMapping ;
Expand All @@ -123,6 +148,23 @@ ex:IRINodeMapping a lr:IRIBasedNodeMapping ;
ex:IRINodeLabelMapping a lr:IRIBasedNodeLabelMapping ;
lr:prefixOfIRIs "https://example.org/label/"^^xsd:anyURI .

ex:LiteralNodeLabelMapping a lr:LiteralBasedNodeLabelMapping .

ex:RegexIRINodeLabelMapping a lr:RegexIRIBasedNodeLabelMapping ;
lr:regex "^\\w+" ;
lr:prefixOfIRIs "http://purl.org/dc/terms/"^^xsd:anyURI .

ex:SingleIRINodeLabelMapping a lr:SingleIRIBasedNodeLabelMapping ;
lr:label "DIRECTED" ;
lr:iri "http://dsgfrjlk.org/kdfj/directorOf"^^xsd:anyURI .

ex:SingleLiteralNodeLabelMapping a lr:SingleLiteralBasedNodeLabelMapping ;
lr:label "DIRECTED" ;
lr:literal "DirectorOf" .

ex:CombinedNodeLabelMapping a lr:CombinedNodeLabelMapping ;
lr:nodeLabelMappings (ex:SingleLiteralNodeLabelMapping ex:SingleIRINodeLabelMapping ex:RegexIRINodeLabelMapping ex:IRINodeLabelMapping) .

ex:IRIEdgeLabelMapping a lr:IRIBasedEdgeLabelMapping ;
lr:prefixOfIRIs "https://example.org/relationship/"^^xsd:anyURI .

Expand Down
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.UnSupportedNodeLabelException;

import java.util.List;

public class CombinedNodeLabelMappingImpl implements NodeLabelMapping {

protected final List<NodeLabelMapping> nodeLabelMappings;

public CombinedNodeLabelMappingImpl(final List<NodeLabelMapping> nodeLabelMappings){
this.nodeLabelMappings = nodeLabelMappings;
}

@Override
public Node map(final String label) {
for (final NodeLabelMapping nodeLabelMapping : nodeLabelMappings) {
try {
return nodeLabelMapping.map(label);
}
catch (final UnSupportedNodeLabelException e) {}
}
throw new UnSupportedNodeLabelException("The given node label (" + label + ") is not a supported label in the image of this node label mapping.");
}

public String unmap(final Node node) {
for (final NodeLabelMapping nodeLabelMapping : nodeLabelMappings) {
try {
return nodeLabelMapping.unmap(node);
}
catch (final UnSupportedNodeLabelException e) {}
}
throw new UnSupportedNodeLabelException("The given RDF term (" + node.toString() + ") is not an URI node or not in the image of this node label mapping.");
}

@Override
public boolean isPossibleResult(final Node node) {
for (final NodeLabelMapping nodeLabelMapping : nodeLabelMappings) {
if(nodeLabelMapping.isPossibleResult(node)){
return true;
}
}
return false;
}
}
Loading
Loading