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

- fixed CQL2Cypher tests

parent b61bcde0
......@@ -5,8 +5,8 @@ import de.uniwue.query.LanguageManager;
public class CypherLanguageManager extends LanguageManager {
public CypherLanguageManager(Model model) {
super(null, new Graph_2_Cypher_Mapper(model));
public CypherLanguageManager(Model model, boolean retrieveAllChildNodesInResult) {
super(null, new Graph_2_Cypher_Mapper(model, retrieveAllChildNodesInResult));
}
public static String system = "Cypher";
......
......@@ -29,6 +29,8 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
private CypherPart state;
private boolean retrieveAllChildNodesInResult;
private enum CypherPart {
MATCH, WITH, WHERE, RETURN
}
......@@ -52,8 +54,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, OperatorType.MATCHES, OperatorType.MATCHES_AQL }));
public Graph_2_Cypher_Mapper(Model model) {
public Graph_2_Cypher_Mapper(Model model, boolean retrieveAllChildNodesInResult) {
super(model);
this.retrieveAllChildNodesInResult = retrieveAllChildNodesInResult;
initializeOpMappings();
}
......@@ -131,9 +134,15 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
if (aConc.outputName != null) {
result += " as " + aConc.outputName;
}
if (resolveAlias.isConcept() && resolveAlias.hasToBeReturned()) {
if (resolveAlias.isConcept() && resolveAlias.hasToBeReturned() && retrieveAllChildNodesInResult) {
String alias = aliases.get(resolveAlias);
String output = StringUtilsUniWue.cleanStringFromSpecialCharacters(aConc.outputName);
String output;
if (aConc.outputName == null) {
output = alias;
} else {
output = aConc.outputName;
}
output = StringUtilsUniWue.cleanStringFromSpecialCharacters(output);
result += ", " + alias + "x as " + output + "x, " + alias + "p as " + output + "p, extract(r in relationships("
+ alias + "p) | type(r)) as " + output + "t, extract(n in nodes(" + alias + "p) | labels(n)) as "
+ output + "n";
......@@ -397,7 +406,7 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
String targetType = aRel.getParameters().get(1).asPrimitive().value;
String targetAlias = createAlias(aRel);
String result = "(" + sourceAlias + ")-[*]->(" + targetAlias + ":" + targetType + ")";
if (aRel.hasToBeReturned()) {
if (aRel.hasToBeReturned() && retrieveAllChildNodesInResult) {
result += ", " + targetAlias + "p = (" + targetAlias + ")-[*]->(" + targetAlias + "x)";
}
return result;
......@@ -492,7 +501,7 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
}
String alias = createAlias(aConc);
result += "(" + alias + ":" + aConc.getIteratorSelector() + ")";
if (aConc.hasToBeReturned()) {
if (aConc.hasToBeReturned() && retrieveAllChildNodesInResult) {
result += ", " + alias + "p = (" + alias + ")-[*]->(" + alias + "x)";
}
}
......
......@@ -52,7 +52,7 @@ public class Test_AQL_2_Cypher {
// just to initialize the operators
Model model = OpenEHRModelInitializer.loadModel();
aqlLangManager = new AQLLanguageManager(model);
cypherLangManager = new CypherLanguageManager(model);
cypherLangManager = new CypherLanguageManager(model, true);
OperatorType.doTypeChecking = false;
}
......
......@@ -84,7 +84,7 @@ public class Test_CQL_2_Cypher {
private void initialize() throws IOException {
Model model = FHIRModelInitializer.loadModel();
cqlLangManager = new CQLLanguageManager(model);
cypherLangManager = new CypherLanguageManager(model);
cypherLangManager = new CypherLanguageManager(model, false);
graphTransformer_cql_2_cypher = new CQL_2_CypherQueryGraphTransformer(
cqlLangManager.system_2_graph_mapper, cypherLangManager.graph_2_system_mapper);
}
......
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