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

Simple draft about introduction of guards (using JEval) on triples #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<dependency>
<groupId>net.antidot</groupId>
<artifactId>db2triples</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.sun.org.apache</groupId>
Expand All @@ -103,6 +103,11 @@
<version>2.0.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>net.sourceforge.jeval</groupId>
<artifactId>jeval</artifactId>
<version>0.9.4</version>
</dependency>
</dependencies>

</project>
29 changes: 21 additions & 8 deletions src/main/java/be/ugent/mmlab/rml/core/RMLMappingFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private static Map<Resource, TriplesMap> extractTripleMapResources(
// with referencing objects
{
triplesMapResources.put(s.getSubject(), new StdTriplesMap(
null, null, null, s.getSubject().stringValue()));
null, null, null, s.getSubject().stringValue(),null));
}
}
}
Expand Down Expand Up @@ -281,6 +281,11 @@ private static void extractTriplesMap(SesameDataSet r2rmlMappingGraph,
triplesMapResources);
log.debug("[RMLMappingFactory:extractTriplesMap] Current number of created graphMaps : "
+ graphMaps.size());


log.debug("[RMLMappingFactory:extractTriplesMap] Current number of created graphMaps : "
+ graphMaps.size());

// Fill triplesMap
for (PredicateObjectMap predicateObjectMap : predicateObjectMaps) {
result.addPredicateObjectMap(predicateObjectMap);
Expand Down Expand Up @@ -507,13 +512,15 @@ private static Set<JoinCondition> extractJoinConditions(
R2RMLTerm.CHILD);
String parent = extractLiteralFromTermMap(r2rmlMappingGraph,
jc, R2RMLTerm.PARENT);
String guard = extractLiteralFromTermMap(r2rmlMappingGraph,
jc, R2RMLTerm.GUARD);
if (parent == null || child == null) {
throw new InvalidR2RMLStructureException(
"[RMLMappingFactory:extractReferencingObjectMap] "
+ object.stringValue()
+ " must have exactly two properties child and parent. ");
}
result.add(new StdJoinCondition(child, parent));
result.add(new StdJoinCondition(child, parent,guard));
}
} catch (ClassCastException e) {
throw new InvalidR2RMLStructureException(
Expand All @@ -540,6 +547,8 @@ private static ObjectMap extractObjectMap(SesameDataSet r2rmlMappingGraph,
object, R2RMLTerm.TEMPLATE);
String languageTag = extractLiteralFromTermMap(r2rmlMappingGraph,
object, R2RMLTerm.LANGUAGE);
String stringGuard = extractLiteralFromTermMap(r2rmlMappingGraph,
object, R2RMLTerm.GUARD);
URI termType = (URI) extractValueFromTermMap(r2rmlMappingGraph, object,
R2RMLTerm.TERM_TYPE);
URI dataType = (URI) extractValueFromTermMap(r2rmlMappingGraph, object,
Expand All @@ -551,8 +560,8 @@ private static ObjectMap extractObjectMap(SesameDataSet r2rmlMappingGraph,
ReferenceIdentifier referenceValue = extractReferenceIdentifier(r2rmlMappingGraph, object);

StdObjectMap result = new StdObjectMap(null, constantValue, dataType,
languageTag, stringTemplate, termType, inverseExpression,
referenceValue);
languageTag, stringTemplate, termType, stringGuard,
inverseExpression, referenceValue);
log.debug("[RMLMappingFactory:extractObjectMap] Extract object map done.");
return result;
}
Expand Down Expand Up @@ -587,6 +596,7 @@ private static PredicateMap extractPredicateMap(
object, R2RMLTerm.CONSTANT);
String stringTemplate = extractLiteralFromTermMap(r2rmlMappingGraph,
object, R2RMLTerm.TEMPLATE);
String stringGuard = extractLiteralFromTermMap(r2rmlMappingGraph,object, R2RMLTerm.GUARD);
URI termType = (URI) extractValueFromTermMap(r2rmlMappingGraph, object,
R2RMLTerm.TERM_TYPE);

Expand All @@ -597,7 +607,7 @@ private static PredicateMap extractPredicateMap(
ReferenceIdentifier referenceValue = extractReferenceIdentifier(r2rmlMappingGraph, object);

PredicateMap result = new StdPredicateMap(null, constantValue,
stringTemplate, inverseExpression, referenceValue, termType);
stringTemplate, stringGuard, inverseExpression, referenceValue, termType);
log.debug("[RMLMappingFactory:extractPredicateMap] Extract predicate map done.");
return result;
}
Expand Down Expand Up @@ -649,7 +659,8 @@ private static SubjectMap extractSubjectMap(
subjectMap, R2RMLTerm.TERM_TYPE);
String inverseExpression = extractLiteralFromTermMap(r2rmlMappingGraph,
subjectMap, R2RMLTerm.INVERSE_EXPRESSION);

String stringGuard = extractLiteralFromTermMap(r2rmlMappingGraph,
subjectMap, R2RMLTerm.GUARD);
//MVS: Decide on ReferenceIdentifier
ReferenceIdentifier referenceValue = extractReferenceIdentifier(r2rmlMappingGraph, subjectMap);
Set<URI> classIRIs = extractURIsFromTermMap(r2rmlMappingGraph,
Expand Down Expand Up @@ -678,7 +689,7 @@ private static SubjectMap extractSubjectMap(
}
}
SubjectMap result = new StdSubjectMap(ownTriplesMap, constantValue,
stringTemplate, termType, inverseExpression, referenceValue,
stringTemplate, termType,stringGuard, inverseExpression, referenceValue,
classIRIs, graphMaps);
log.debug("[RMLMappingFactory:extractSubjectMap] Subject map extracted.");
return result;
Expand All @@ -696,6 +707,8 @@ private static GraphMap extractGraphMap(SesameDataSet r2rmlMappingGraph,
graphMap, R2RMLTerm.CONSTANT);
String stringTemplate = extractLiteralFromTermMap(r2rmlMappingGraph,
graphMap, R2RMLTerm.TEMPLATE);
String stringGuard = extractLiteralFromTermMap(r2rmlMappingGraph,
graphMap, R2RMLTerm.GUARD);
String inverseExpression = extractLiteralFromTermMap(r2rmlMappingGraph,
graphMap, R2RMLTerm.INVERSE_EXPRESSION);

Expand All @@ -706,7 +719,7 @@ private static GraphMap extractGraphMap(SesameDataSet r2rmlMappingGraph,
graphMap, R2RMLTerm.TERM_TYPE);

GraphMap result = new StdGraphMap(constantValue, stringTemplate,
inverseExpression, referenceValue, termType);
stringGuard, inverseExpression, referenceValue, termType);
log.debug("[RMLMappingFactory:extractPredicateObjectMaps] Graph map extracted.");
return result;
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/be/ugent/mmlab/rml/model/AbstractTermMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@ public abstract class AbstractTermMap implements TermMap {
private String stringTemplate;
private ReferenceIdentifier referenceValue;
private String inverseExpression;
private String stringGuard;

protected AbstractTermMap(Value constantValue, URI dataType,
String languageTag, String stringTemplate, URI termType,
String inverseExpression, ReferenceIdentifier referenceValue)
String stringGuard, String inverseExpression, ReferenceIdentifier referenceValue)
throws R2RMLDataError, InvalidR2RMLStructureException,
InvalidR2RMLSyntaxException {

setConstantValue(constantValue);
setReferenceValue(referenceValue);
setLanguageTag(languageTag);
setStringTemplate(stringTemplate);
setStringGuard(stringGuard);
setTermType(termType, dataType);
setDataType(dataType);

Expand Down Expand Up @@ -205,6 +207,14 @@ private void setStringTemplate(String stringTemplate)

this.stringTemplate = stringTemplate;
}

private void setStringGuard(String stringGuard)
throws InvalidR2RMLSyntaxException, InvalidR2RMLStructureException {
// he value of the rr:template property MUST be a
// valid string template.

this.stringGuard = stringGuard;
}

/**
* A string template is a format string that can be used to build
Expand Down Expand Up @@ -358,6 +368,10 @@ public Set<ReferenceIdentifier> getReferencedSelectors() {
public String getStringTemplate() {
return stringTemplate;
}

public String getStringGuard() {
return stringGuard;
}

public TermMapType getTermMapType() {
if (constantValue != null) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/be/ugent/mmlab/rml/model/JoinCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ public interface JoinCondition {
* Parent reference must be a reference in the language defined by the parent triples map and exist there.
*/
public String getParent();

public String getGuard();

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public interface PredicateObjectMap {
public Set<GraphMap> getGraphMaps();
public void setGraphMaps(Set<GraphMap> graphmaps);

public String getGuardMaps();

public void setGuardMaps(String guardMaps);

}
4 changes: 2 additions & 2 deletions src/main/java/be/ugent/mmlab/rml/model/StdGraphMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ public class StdGraphMap extends AbstractTermMap implements GraphMap {


public StdGraphMap(Value constantValue,
String stringTemplate, String inverseExpression,
String stringTemplate, String guard, String inverseExpression,
ReferenceIdentifier referenceValue, URI termType) throws R2RMLDataError,
InvalidR2RMLStructureException, InvalidR2RMLSyntaxException {
// No Literal term type
// ==> No datatype
// ==> No specified language tag
// Only termType possible : IRI => by default
super(constantValue, null, null, stringTemplate,
termType, inverseExpression, referenceValue);
termType,guard, inverseExpression, referenceValue);

}

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/be/ugent/mmlab/rml/model/StdJoinCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ public class StdJoinCondition implements JoinCondition {

private String child;
private String parent;
private String guard;

public StdJoinCondition(String child, String parent)
public StdJoinCondition(String child, String parent,String guard)
throws InvalidR2RMLStructureException, InvalidR2RMLSyntaxException {
setChild(child);
setParent(parent);
setGuard(guard);
}

private void setParent(String parent)
Expand Down Expand Up @@ -86,5 +88,14 @@ public String getChild() {
public String getParent() {
return parent;
}

public String getGuard(){
return guard;
}

private void setGuard(String guard) {
if (guard != null)
this.guard=guard;
}

}
4 changes: 2 additions & 2 deletions src/main/java/be/ugent/mmlab/rml/model/StdObjectMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public class StdObjectMap extends AbstractTermMap implements TermMap, ObjectMap

public StdObjectMap(PredicateObjectMap predicateObjectMap,
Value constantValue, URI dataType, String languageTag,
String stringTemplate, URI termType, String inverseExpression,
String stringTemplate, URI termType, String stringGuard,String inverseExpression,
ReferenceIdentifier referenceValue) throws R2RMLDataError,
InvalidR2RMLStructureException, InvalidR2RMLSyntaxException {
super(constantValue, dataType, languageTag, stringTemplate, termType,
super(constantValue, dataType, languageTag, stringTemplate, termType, stringGuard,
inverseExpression, referenceValue);
setPredicateObjectMap(predicateObjectMap);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/be/ugent/mmlab/rml/model/StdPredicateMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class StdPredicateMap extends AbstractTermMap implements TermMap,
private PredicateObjectMap predicateObjectMap;

public StdPredicateMap(PredicateObjectMap predicateObjectMap,
Value constantValue, String stringTemplate,
Value constantValue, String stringTemplate, String guard,
String inverseExpression, ReferenceIdentifier referenceValue, URI termType)
throws R2RMLDataError, InvalidR2RMLStructureException,
InvalidR2RMLSyntaxException {
Expand All @@ -53,7 +53,7 @@ public StdPredicateMap(PredicateObjectMap predicateObjectMap,
// ==> No specified language tag
// No class IRI
super(constantValue, null, null, stringTemplate, termType,
inverseExpression, referenceValue);
guard, inverseExpression, referenceValue);
setPredicateObjectMap(predicateObjectMap);
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/be/ugent/mmlab/rml/model/StdPredicateObjectMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class StdPredicateObjectMap implements PredicateObjectMap {
private Set<ObjectMap> objectMaps;
private Set<ReferencingObjectMap> refObjectMaps;
private Set<PredicateMap> predicateMaps;
private String guardMaps;
protected TriplesMap ownTriplesMap;
private HashSet<GraphMap> graphMaps;

Expand Down Expand Up @@ -126,5 +127,16 @@ public void setGraphMaps(Set<GraphMap> graphMaps) {
this.graphMaps = new HashSet<GraphMap>(graphMaps);
}

@Override
public String getGuardMaps() {
// TODO Auto-generated method stub
return guardMaps;
}

@Override
public void setGuardMaps(String guard) {
this.guardMaps=guard;

}

}
4 changes: 2 additions & 2 deletions src/main/java/be/ugent/mmlab/rml/model/StdSubjectMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public class StdSubjectMap extends AbstractTermMap implements SubjectMap {
protected TriplesMap ownTriplesMap;

public StdSubjectMap(TriplesMap ownTriplesMap, Value constantValue,
String stringTemplate, URI termType, String inverseExpression,
String stringTemplate, URI termType, String guard, String inverseExpression,
ReferenceIdentifier referenceValue, Set<URI> classIRIs, Set<GraphMap> graphMaps)
throws R2RMLDataError, InvalidR2RMLStructureException,
InvalidR2RMLSyntaxException {
// No Literal term type
// ==> No datatype
// ==> No specified language tag
super(constantValue, null, null, stringTemplate, termType,
super(constantValue, null, null, stringTemplate, termType,guard,
inverseExpression, referenceValue);
setClassIRIs(classIRIs);
setGraphMaps(graphMaps);
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/be/ugent/mmlab/rml/model/StdTriplesMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ public class StdTriplesMap implements TriplesMap {
private SubjectMap subjectMap;
private LogicalSource logicalSource;
private String name;
private String guard;

public StdTriplesMap(LogicalSource logicalSource,
Set<StdPredicateObjectMap> predicateObjectMaps,
StdSubjectMap subjectMap, String name) throws InvalidR2RMLStructureException {
StdSubjectMap subjectMap, String name,String guard) throws InvalidR2RMLStructureException {
setSubjectMap(subjectMap);
setLogicalSource(logicalSource);
setPredicateObjectMap(predicateObjectMaps);
setName(name);
setGuardObjectMap(guard);
}

private void setGuardObjectMap(String guard) {
this.guard=guard;

}

public void setLogicalSource(LogicalSource logicalTable) {
Expand Down Expand Up @@ -106,4 +113,5 @@ public void setName(String name) {

}


}
1 change: 1 addition & 0 deletions src/main/java/be/ugent/mmlab/rml/model/TermMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public enum TermMapType {
* curly braces. Only if TEMPLATE_VALUED type.
*/
public String getStringTemplate();
public String getStringGuard();

/**
* If the term map has an optional rr:termType property, then its term type
Expand Down
Loading