Commit ec114c30 authored by Georg Fette's avatar Georg Fette
Browse files

added ethercis test cases

added a lot of openEHR reference model stuff
fixed bugs
parent 0299b114
......@@ -82,21 +82,23 @@ import org.cqframework.cql.gen.cqlParser.WithClauseContext;
import de.uniwue.misc.util.RegexUtil;
import de.uniwue.model.Model;
import de.uniwue.query.OperatorType;
import de.uniwue.query.Primitive;
import de.uniwue.query.PrimitiveDateTime;
import de.uniwue.query.QueryOperator;
import de.uniwue.query.System_2_Graph_Mapper;
import de.uniwue.query.opInterfaces.OperatorType;
public class CQL_2_Graph_Mapper extends System_2_Graph_Mapper {
private boolean parsingRetrieveClause;
public CQL_2_Graph_Mapper() {
super(cqlParser.ruleNames);
public CQL_2_Graph_Mapper(Model model) {
super(model, cqlParser.ruleNames);
Graph_2_CQL_Mapper reverseMapper = new Graph_2_CQL_Mapper(model);
copyOpMappings(reverseMapper.opMap);
}
public static String getSystem() {
public String getSystem() {
return Graph_2_CQL_Mapper.system;
}
......@@ -262,7 +264,7 @@ public class CQL_2_Graph_Mapper extends System_2_Graph_Mapper {
for (SortByItemContext anItem : sortByItem) {
ExpressionTermContext expressionTerm = anItem.expressionTerm();
// the first parameter is the operator returning the list to be sorted
String alias = getNewAliasName();
String alias = getNewAliasName();
queryOp.alias = alias;
startPathWithAliasRef(alias);
parseExpressionTerm(expressionTerm);
......
......@@ -7,12 +7,12 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import de.uniwue.model.Model;
import de.uniwue.query.Expression;
import de.uniwue.query.Graph_2_System_Mapper;
import de.uniwue.query.OperatorMap;
import de.uniwue.query.OperatorType;
import de.uniwue.query.Primitive;
import de.uniwue.query.QueryOperator;
import de.uniwue.query.opInterfaces.OperatorType;
public class Graph_2_CQL_Mapper extends Graph_2_System_Mapper {
......@@ -44,9 +44,9 @@ public class Graph_2_CQL_Mapper extends Graph_2_System_Mapper {
OperatorType.LOG, OperatorType.ROUND, OperatorType.TRUNCATE, OperatorType.DATETIME,
OperatorType.TIME, OperatorType.NOW, OperatorType.TIMEOFDAY, OperatorType.TODAY }));
public Graph_2_CQL_Mapper() {
super(system);
initializeOpMappings(opMap);
public Graph_2_CQL_Mapper(Model model) {
super(model, system);
initializeOpMappings();
}
@Override
......@@ -394,9 +394,6 @@ public class Graph_2_CQL_Mapper extends Graph_2_System_Mapper {
result += " " + opString + " ";
String string2 = writeExpr(anOp.getParameters().get(1));
result += string2;
} else if (anOp.type == OperatorType.LIST) {
String intString = writeList(anOp);
result += intString;
} else if (anOp.type == OperatorType.IS) {
String value = writeExpr(anOp.getParameters().get(0));
result += value + " " + opString + " " + anOp.getParameters().get(1).asPrimitive().value;
......@@ -421,11 +418,14 @@ public class Graph_2_CQL_Mapper extends Graph_2_System_Mapper {
String exp = writeExpr(anOp.getParameters().get(0));
if ((anOp.type == OperatorType.END) || (anOp.type == OperatorType.START)) {
result += exp + " " + opString;
} else if (anOp.type == OperatorType.TO_LIST) {
} else if (anOp.type == OperatorType.LIST) {
result += exp;
} else {
throw new RuntimeException("unexpected");
}
} else if (anOp.type == OperatorType.LIST) {
String intString = writeList(anOp);
result += intString;
} else if (anOp.getParameters().size() == 0) {
result += opString;
} else {
......@@ -449,78 +449,76 @@ public class Graph_2_CQL_Mapper extends Graph_2_System_Mapper {
return result;
}
public static String getSystem() {
public String getSystem() {
return Graph_2_CQL_Mapper.system;
}
public static void initializeOpMappings(OperatorMap aMap) {
initializeStdOpMappings(aMap);
aMap.addOp("is", OperatorType.IS);
aMap.addOp("sort by", OperatorType.SORT);
aMap.addOp("exists", OperatorType.EXISTS);
aMap.addOp("", OperatorType.QUANTITY);
aMap.addOp("", OperatorType.DURATION);
aMap.addOp("", OperatorType.LIST);
aMap.addOp("", OperatorType.TO_LIST);
aMap.addOp("return", OperatorType.RETURN);
aMap.addOp("and", OperatorType.AND);
aMap.addOp("or", OperatorType.OR);
aMap.addOp("not", OperatorType.NOT);
aMap.addOp("alltrue", OperatorType.ALLTRUE);
aMap.addOp("anytrue", OperatorType.ANYTRUE);
aMap.addOp("First", OperatorType.FIRST);
aMap.addOp("Last", OperatorType.LAST);
aMap.addOp("In", OperatorType.IN);
aMap.addOp("contains", OperatorType.CONTAINS);
aMap.addOp("in", OperatorType.IN_VALUE_SET);
aMap.addOp("Now", OperatorType.NOW);
aMap.addOp("Today", OperatorType.TODAY);
aMap.addOp("TimeOfDay", OperatorType.TIMEOFDAY);
aMap.addOp("Time", OperatorType.TIME);
aMap.addOp("Datetime", OperatorType.DATETIME);
aMap.addOp("Interval", OperatorType.INTERVAL);
aMap.addOp("during", OperatorType.DURING);
aMap.addOp("after", OperatorType.AFTER);
aMap.addOp("ends", OperatorType.END);
aMap.addOp("=", OperatorType.EQUALS);
aMap.addOp("<", OperatorType.LESS);
aMap.addOp("<=", OperatorType.LESS_OR_EQUAL);
aMap.addOp(">", OperatorType.MORE);
aMap.addOp(">=", OperatorType.MORE_OR_EQUAL);
aMap.addOp("Avg", OperatorType.AVG);
aMap.addOp("Count", OperatorType.COUNT);
aMap.addOp("Min", OperatorType.MIN);
aMap.addOp("Max", OperatorType.MAX);
aMap.addOp("Median", OperatorType.MEDIAN);
aMap.addOp("Sum", OperatorType.SUM);
aMap.addOp("StdDev", OperatorType.STDDEV);
aMap.addOp("Variance", OperatorType.VARIANCE);
aMap.addOp("-", OperatorType.NEGATE);
aMap.addOp("^", OperatorType.POWER);
aMap.addOp("Round", OperatorType.ROUND);
aMap.addOp("Abs", OperatorType.ABS);
aMap.addOp("Exp", OperatorType.EXP);
aMap.addOp("Log", OperatorType.LOG);
aMap.addOp("Ln", OperatorType.LN);
aMap.addOp("Truncate", OperatorType.TRUNCATE);
aMap.addOp("Floor", OperatorType.FLOOR);
aMap.addOp("Ceiling", OperatorType.CEILING);
aMap.addOp("+", OperatorType.ADD);
aMap.addOp("-", OperatorType.SUBTRACT);
aMap.addOp("*", OperatorType.MULTIPLY);
aMap.addOp("/", OperatorType.DIVIDE);
aMap.addOp("div", OperatorType.TRUNCATED_DIVIDE);
aMap.addOp("mod", OperatorType.MODULO);
private void initializeOpMappings() {
initializeStdOpMappings();
addOpType("is", OperatorType.IS);
addOpType("sort by", OperatorType.SORT);
addOpType("exists", OperatorType.EXISTS);
addOpType("", OperatorType.QUANTITY);
addOpType("", OperatorType.DURATION);
addOpType("", OperatorType.LIST);
addOpType("return", OperatorType.RETURN);
addOpType("and", OperatorType.AND);
addOpType("or", OperatorType.OR);
addOpType("not", OperatorType.NOT);
addOpType("alltrue", OperatorType.ALLTRUE);
addOpType("anytrue", OperatorType.ANYTRUE);
addOpType("First", OperatorType.FIRST);
addOpType("Last", OperatorType.LAST);
addOpType("In", OperatorType.IN);
addOpType("contains", OperatorType.CONTAINS);
addOpType("in", OperatorType.IN_VALUE_SET);
addOpType("Now", OperatorType.NOW);
addOpType("Today", OperatorType.TODAY);
addOpType("TimeOfDay", OperatorType.TIMEOFDAY);
addOpType("Time", OperatorType.TIME);
addOpType("Datetime", OperatorType.DATETIME);
addOpType("during", OperatorType.DURING);
addOpType("after", OperatorType.AFTER);
addOpType("ends", OperatorType.END);
addOpType("=", OperatorType.EQUALS);
addOpType("<", OperatorType.LESS);
addOpType("<=", OperatorType.LESS_OR_EQUAL);
addOpType(">", OperatorType.MORE);
addOpType(">=", OperatorType.MORE_OR_EQUAL);
addOpType("Avg", OperatorType.AVG);
addOpType("Count", OperatorType.COUNT);
addOpType("Min", OperatorType.MIN);
addOpType("Max", OperatorType.MAX);
addOpType("Median", OperatorType.MEDIAN);
addOpType("Sum", OperatorType.SUM);
addOpType("StdDev", OperatorType.STDDEV);
addOpType("Variance", OperatorType.VARIANCE);
addOpType("-", OperatorType.NEGATE);
addOpType("^", OperatorType.POWER);
addOpType("Round", OperatorType.ROUND);
addOpType("Abs", OperatorType.ABS);
addOpType("Exp", OperatorType.EXP);
addOpType("Log", OperatorType.LOG);
addOpType("Ln", OperatorType.LN);
addOpType("Truncate", OperatorType.TRUNCATE);
addOpType("Floor", OperatorType.FLOOR);
addOpType("Ceiling", OperatorType.CEILING);
addOpType("+", OperatorType.ADD);
addOpType("-", OperatorType.SUBTRACT);
addOpType("*", OperatorType.MULTIPLY);
addOpType("/", OperatorType.DIVIDE);
addOpType("div", OperatorType.TRUNCATED_DIVIDE);
addOpType("mod", OperatorType.MODULO);
}
}
package de.uniwue.query;
import de.uniwue.model.Concept;
import de.uniwue.query.opInterfaces.OperatorType;
public abstract class Expression {
......
package de.uniwue.query;
import de.uniwue.model.Model;
import de.uniwue.query.opInterfaces.OperatorType;
public class Fuzzer {
private Model model;
private QueryOperator currentOp;
public Fuzzer(Model model) {
this.model = model;
}
public QueryOperator createQuery() {
QueryOperator result = new QueryOperator(OperatorType.QUERY, model);
currentOp = result;
addOp();
return result;
}
private void addOp() {
}
}
package de.uniwue.query;
public abstract class Graph_2_System_Mapper extends Mapper {
import de.uniwue.model.Model;
public abstract class Graph_2_System_Mapper extends QueryMapper {
protected String targetSystemName;
public Graph_2_System_Mapper(String aTargetSystemName) {
super();
public Graph_2_System_Mapper(Model model, String aTargetSystemName) {
super(model);
this.targetSystemName = aTargetSystemName;
}
......@@ -28,4 +30,6 @@ public abstract class Graph_2_System_Mapper extends Mapper {
public void dispose() {
}
public abstract String getSystem();
}
package de.uniwue.query;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class OperatorMap {
import de.uniwue.model.Model;
import de.uniwue.query.opInterfaces.OperatorType;
public class OperatorManager {
private Map<OperatorType, String> graph_2_system_operatorMap = new HashMap<OperatorType, String>();
private Map<String, OperatorType> system_2_graph_operatorMap = new HashMap<String, OperatorType>();
public void addOp(String anOpString, OperatorType opType) {
public void addOp(String anOpString, OperatorType opType, Model model) {
graph_2_system_operatorMap.put(opType, anOpString);
system_2_graph_operatorMap.put(anOpString, opType);
}
public List<OperatorType> getOpTypes() {
List<OperatorType> result = new ArrayList<OperatorType>();
for (OperatorType aType : graph_2_system_operatorMap.keySet()) {
result.add(aType);
}
return result;
}
public OperatorType getOpType(String anOpString) {
OperatorType opType = system_2_graph_operatorMap.get(anOpString);
if (opType == null) {
......@@ -21,7 +34,7 @@ public class OperatorMap {
}
return opType;
}
public String getOpString(OperatorType anOpType) {
String opString = graph_2_system_operatorMap.get(anOpType);
if (opString == null) {
......@@ -29,5 +42,5 @@ public class OperatorMap {
}
return opString;
}
}
package de.uniwue.query;
import de.uniwue.model.Model;
import de.uniwue.query.opInterfaces.OperatorType;
public class Mapper {
public class QueryMapper {
private Model model;
protected QueryOperator query;
protected OperatorMap opMap = new OperatorMap();
public OperatorManager opMap = new OperatorManager();
public static String graphSystemName = "Graph";
......@@ -14,12 +17,13 @@ public class Mapper {
protected QueryOperator lastPathElem;
public Mapper() {
public QueryMapper(Model model) {
this.model = model;
initialize();
}
public Model getModel() {
return query.getModel();
return model;
}
protected QueryOperator addAliasRef(QueryOperator container, String alias) {
......@@ -59,14 +63,25 @@ public class Mapper {
lastPathElem = null;
}
public static void initializeStdOpMappings(OperatorMap opMap) {
opMap.addOp("", OperatorType.FILTER);
opMap.addOp("", OperatorType.ITERATE);
opMap.addOp("", OperatorType.EXISTS);
opMap.addOp("", OperatorType.FIELD);
opMap.addOp("", OperatorType.ALIAS_REF);
opMap.addOp("", OperatorType.RETURN);
opMap.addOp("", OperatorType.QUERY);
public void copyOpMappings(OperatorManager anotherMap) {
for (OperatorType aKey : anotherMap.getOpTypes()) {
String displayString = anotherMap.getOpString(aKey);
opMap.addOp(displayString, aKey, getModel());
}
}
protected void addOpType(String displayString, OperatorType type) {
opMap.addOp(displayString, type, getModel());
}
protected void initializeStdOpMappings() {
addOpType("", OperatorType.FILTER);
addOpType("", OperatorType.ITERATE);
addOpType("", OperatorType.EXISTS);
addOpType("", OperatorType.FIELD);
addOpType("", OperatorType.ALIAS_REF);
addOpType("", OperatorType.RETURN);
addOpType("", OperatorType.QUERY);
}
protected String getNewAliasName() {
......
......@@ -9,6 +9,7 @@ import java.util.Set;
import de.uniwue.misc.util.StringUtilsUniWue;
import de.uniwue.model.Concept;
import de.uniwue.model.Model;
import de.uniwue.query.opInterfaces.OperatorType;
public class QueryOperator extends Expression {
......@@ -153,32 +154,12 @@ public class QueryOperator extends Expression {
return result;
}
public void checkConsistency() {
public void checkProblems() {
checkDuplicateAliases();
checkParentChildSynchonicity();
checkAliasExistenceForAliasRefs();
checkInterface();
type.checkProblems(this);
for (QueryOperator anOp : getOperators()) {
anOp.checkConsistency();
}
}
private void checkInterface() {
OperatorInterfaces.check(this);
}
private void checkAliasExistenceForAliasRefs() {
if (type == OperatorType.ALIAS_REF) {
String alias = getParameters().get(0).asPrimitive().value;
boolean aliasExists = false;
for (QueryOperator anOp : getRoot().getOpsRecursive()) {
if ((anOp.alias != null) && anOp.alias.equals(alias)) {
aliasExists = true;
}
}
if (!aliasExists) {
throw new RuntimeException("ALIAS_REF has no matching alias");
}
anOp.checkProblems();
}
}
......@@ -474,7 +455,7 @@ public class QueryOperator extends Expression {
@Override
public Concept getDataType() {
return OperatorInterfaces.getReturnDataType(this);
return type.getReturnDataType(this);
}
public String getNewAliasName() {
......
......@@ -4,14 +4,15 @@ import java.util.Arrays;
import org.antlr.v4.runtime.tree.ParseTree;
import de.uniwue.model.Model;
import de.uniwue.query.CQL.TreeUtils;
public class System_2_Graph_Mapper extends Mapper {
public abstract class System_2_Graph_Mapper extends QueryMapper {
private String[] ruleNames;
public System_2_Graph_Mapper(String[] ruleNames) {
super();
public System_2_Graph_Mapper(Model model, String[] ruleNames) {
super(model);
this.ruleNames = ruleNames;
}
......@@ -20,4 +21,6 @@ public class System_2_Graph_Mapper extends Mapper {
return prettyTree;
}
public abstract String getSystem();
}
......@@ -9,13 +9,13 @@ import java.util.Set;
import de.uniwue.model.Concept;
import de.uniwue.model.ConceptField;
import de.uniwue.model.Model;
import de.uniwue.query.Expression;
import de.uniwue.query.Graph_2_System_Mapper;
import de.uniwue.query.OperatorMap;
import de.uniwue.query.OperatorType;
import de.uniwue.query.Primitive;
import de.uniwue.query.PrimitiveDateTime;
import de.uniwue.query.QueryOperator;
import de.uniwue.query.opInterfaces.OperatorType;
public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
......@@ -56,9 +56,9 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
Arrays.asList(new OperatorType[] { OperatorType.EQUALS, OperatorType.MORE,
OperatorType.MORE_OR_EQUAL, OperatorType.LESS, OperatorType.LESS_OR_EQUAL }));
public Graph_2_Cypher_Mapper() {
super(system);
initializeOpMappings(opMap);
public Graph_2_Cypher_Mapper(Model model) {
super(model, system);
initializeOpMappings();
}
protected void initialize() {
......@@ -422,58 +422,57 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
return result.trim();
}
public static String getSystem() {
public String getSystem() {
return Graph_2_Cypher_Mapper.system;
}
public static void initializeOpMappings(OperatorMap aMap) {
initializeStdOpMappings(aMap);
aMap.addOp("exists", OperatorType.EXISTS);
aMap.addOp("AND", OperatorType.AND);
aMap.addOp("OR", OperatorType.OR);
aMap.addOp("count", OperatorType.COUNT);
aMap.addOp("avg", OperatorType.AVG);
aMap.addOp("In", OperatorType.IN);
aMap.addOp("contains", OperatorType.CONTAINS);
aMap.addOp("max", OperatorType.MAX);
aMap.addOp("min", OperatorType.MIN);
aMap.addOp("", OperatorType.COLLECT);
aMap.addOp("In", OperatorType.IN_VALUE_SET);
aMap.addOp("Now()", OperatorType.NOW);
aMap.addOp("Today()", OperatorType.TODAY);
aMap.addOp("TimeOfDay()", OperatorType.TIMEOFDAY);
aMap.addOp("Interval", OperatorType.INTERVAL);
aMap.addOp("during", OperatorType.DURING);
aMap.addOp(">", OperatorType.AFTER);
aMap.addOp("ends", OperatorType.END);
aMap.addOp("=", OperatorType.EQUALS);
aMap.addOp("<", OperatorType.LESS);
aMap.addOp("<=", OperatorType.LESS_OR_EQUAL);
aMap.addOp(">", OperatorType.MORE);
aMap.addOp(">=", OperatorType.MORE_OR_EQUAL);
aMap.addOp("^", OperatorType.POWER);
aMap.addOp("Round", OperatorType.ROUND);
aMap.addOp("Abs", OperatorType.ABS);
aMap.addOp("Exp", OperatorType.EXP);
aMap.addOp("Log", OperatorType.LOG);
aMap.addOp("Log", OperatorType.LN);
aMap.addOp("Truncate", OperatorType.TRUNCATE);
aMap.addOp("Floor", OperatorType.FLOOR);
aMap.addOp("Ceiling", OperatorType.CEILING);
aMap.addOp("+", OperatorType.ADD);