Commit f5cbff6a authored by rwm's avatar rwm
Browse files

otherwise rule implemented for condition/choose

parent b5caf524
......@@ -56,8 +56,8 @@
skos:notation "source3" ;
dwh:mapFact [
dwh:choose ([rdf:value "1"; dwh:target :t1] [rdf:value "2"; dwh:target :t2]) ;
dwh:modify dwh:removeValue ;
dwh:otherwise [dwh:target :t3 ; dwh:modify dwh:removeValue]; # pulmonary arterial hypertension
dwh:modify dwh:removeValue
] .
......
......@@ -307,6 +307,11 @@ public class Store implements Ontology, Plugin {
}while( rdfList != null );
}
private Rule loadOtherwiseRule(Resource r) throws SKOSException, RepositoryException{
Value targ = RDFUtils.getObject(rc, r, HIStreamOntology.DWH_TARGET);
if( targ == null )throw new SKOSException(r, "dwh:otherwise must include a dwh:target");
return new Rule(null,ConditionType.Otherwise,new ConceptImpl(this, (Resource)targ), null);
}
private Rule loadMapFactRule(Resource r, boolean disableChoose) throws OntologyException, RepositoryException{
final Value[] v = new Value[6];
forEachStatement(r, null, s -> {
......@@ -334,8 +339,13 @@ public class Store implements Ontology, Plugin {
// load condition
if( !(v[0] instanceof Literal) )throw new SKOSException(r, "dwh:condition needs literal object");
Literal condition = (Literal)v[0];
// TODO: load otherwise
return Rule.forCondition(condition, new ConceptImpl(this, (Resource)v[2]));
// load otherwise
Rule otherwise = null;
if( v[5] != null ){
otherwise = loadOtherwiseRule((Resource)v[5]);
}
return Rule.forCondition(condition, new ConceptImpl(this, (Resource)v[2]), otherwise);
}else if( v[1] != null ){
// choose specified
......@@ -354,15 +364,12 @@ public class Store implements Ontology, Plugin {
}
});
// load otherwise
Rule otherwise = null;
if( v[5] != null ){
// TODO move to separate method to reuse this code
Value targ = RDFUtils.getObject(rc, (Resource)v[5], HIStreamOntology.DWH_TARGET);
if( targ == null )throw new SKOSException(r, "dwh:otherwise must include a dwh:target");
// TODO: load otherwise into a rule
otherwise = loadOtherwiseRule((Resource)v[5]);
}
if( errors.isEmpty() ){
return new Rule(list.toArray(new Rule[list.size()]), null);
return new Rule(list.toArray(new Rule[list.size()]), otherwise);
}else{
final Throwable first = errors.get(0);
SKOSException error = new SKOSException(first);
......@@ -377,7 +384,8 @@ public class Store implements Ontology, Plugin {
if( v[2] == null )throw new SKOSException(r, "dwh:mapFact with rdf:value must also contain dwh:target");
Literal value = (Literal)v[4];
if( !value.getDatatype().equals(XMLSchema.STRING) )throw new SKOSException(r, "rdf:value for comparison must have datatype xsd:string");
return new Rule(value.stringValue(), ConditionType.StringValueEquals, new ConceptImpl(this, (Resource)v[2]));
// no otherwise allowed, use null
return new Rule(value.stringValue(), ConditionType.StringValueEquals, new ConceptImpl(this, (Resource)v[2]), null);
//return Rule.forCondition(value, new ConceptImpl(this, (Resource)v[2]));
}else{
// unsupported mapping
......
package de.sekmi.histream.ontology.skos.transform;
public enum ConditionType {
XPath, ECMAScript, StringValueEquals
XPath, ECMAScript, StringValueEquals, Otherwise
}
......@@ -15,29 +15,31 @@ public class Rule {
protected Rule otherwise;
public static Rule forCondition(Literal condition, ConceptImpl target)throws SKOSException{
public static Rule forCondition(Literal condition, ConceptImpl target, Rule otherwise)throws SKOSException{
URI datatype = condition.getDatatype();
if( datatype == null ){
throw new SKOSException(target.getResource(), "Expression without datatype");
}
else if( datatype.equals(HIStreamOntology.DWH_XPATH) ){
// set xpath
return new Rule(condition.stringValue(), ConditionType.XPath, target);
return new Rule(condition.stringValue(), ConditionType.XPath, target, otherwise);
}else if( datatype.equals(HIStreamOntology.DWH_ECMASCRIPT) ){
// use ecmascript
return new Rule(condition.stringValue(), ConditionType.ECMAScript, target);
return new Rule(condition.stringValue(), ConditionType.ECMAScript, target, otherwise);
}else{
throw new SKOSException(target.getResource(), "Unsupported expression datatype: "+datatype.stringValue());
}
}
public Rule (String condition, ConditionType type, ConceptImpl target){
public Rule (String condition, ConditionType type, ConceptImpl target, Rule otherwise){
this.condition = condition;
this.conditionType = type;
this.target = target;
this.otherwise = otherwise;
}
public Rule(Rule[] choose, Rule otherwise){
this.choose = choose;
this.otherwise = otherwise;
}
public ConceptImpl getTarget(){
return target;
......
......@@ -74,13 +74,12 @@ public class TransformationRuleTest {
o2 = t.transform(o, null);
Assert.assertEquals("T:t2", o2.getConceptId());
// TODO implement choose+otherwise
/*
// test choose+otherwise
o = s.get();
Assert.assertEquals("source3", o.getConceptId());
o2 = t.transform(o, null);
Assert.assertEquals("T:t3", o2.getConceptId());
*/
s.close();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment