Commit f66ceccb authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

bug fix for expression parser.

parent d9d53034
......@@ -75,19 +75,18 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
this.pedestrianColorTableModel = new PedestrianColorTableModel();
this.steps = new ArrayList<>();
for (int i = 0; i < 5; i++) {
/*for (int i = 0; i < 5; i++) {
try {
colorEvalFunctions.put(i, new JsonLogicParser("false").parse());
} catch (ParseException e) {
e.printStackTrace();
}
}
}*/
this.pedestrianColorTableModel.addTableModelListener(
e -> {
for (int row = e.getFirstRow(); row <= e.getLastRow(); row++) {
if (row >= 0 && colorEvalFunctions.containsKey(row)
&& e.getColumn() == PedestrianColorTableModel.CIRTERIA_COLUMN) {
if (row >= 0 && e.getColumn() == PedestrianColorTableModel.CIRTERIA_COLUMN) {
try {
VPredicate<JsonNode> evaluator = new JsonLogicParser(
pedestrianColorTableModel.getValueAt(row, e.getColumn()).toString()).parse();
......
......@@ -9,7 +9,16 @@ import java.util.Set;
/**
* This {@link org.vadere.util.io.parser.JsonLogicParser} is able to generate a {@linkg VPredicate}
* based on a logical expression ({@link String})
* that tests a Object of type {@link com.google.gson.JsonObject}.
* that tests a Object of type {@link JsonNode}.
*
* Example expressions:
* attributes.id : {1,2,3,4,5,6,7,8,9,10}
* attributes.id != 5
* position.x > 5.3 && position.x <= 10
* position.x < 4 || position.x > 10
* targetIds:{1,3,4}
* {1,2,3}:targetIds
* (position.x < 4 || position.x > 10) || position.x > 5.3 && position.x <= 10
*
*/
public class JsonLogicParser extends LogicalParser<JsonNode> {
......@@ -26,6 +35,7 @@ public class JsonLogicParser extends LogicalParser<JsonNode> {
} else if (expression.equals("true")) {
return jsonObj -> true;
} else if (expression.contains(":")) {
// {0,1,2}:targetIds is true if targetIds is a superset of {0,1,2}
String[] split = expression.split(":");
// superset
if (split[0].contains("{")) {
......@@ -41,6 +51,7 @@ public class JsonLogicParser extends LogicalParser<JsonNode> {
};
} // subset
else {
// targetIds:{0,1,2} is true if targetIds is a subset of {0,1,2}
return (JsonNode jsonObj) -> {
Set<Double> set = getSetFromString(split[1]);
JsonNode element = getJsonElement(split[0], jsonObj);
......
......@@ -82,11 +82,13 @@ public abstract class LogicalParser<T> {
String reformatText = text.replaceAll("\\(", " ( ");
reformatText = reformatText.replaceAll("\\)", " ) ");
reformatText = reformatText.replaceAll("\\s==\\s", "==");
reformatText = reformatText.replaceAll("\\s<\\s", "!=");
reformatText = reformatText.replaceAll("\\s<\\s", "<");
reformatText = reformatText.replaceAll("\\s<=\\s", "<=");
reformatText = reformatText.replaceAll("\\s>=\\s", ">=");
reformatText = reformatText.replaceAll("\\s>\\s", ">");
reformatText = reformatText.replaceAll("\\s<\\s", "<");
reformatText = reformatText.replaceAll("\\s!=\\s", "!=");
reformatText = reformatText.replaceAll("\\s:\\s", ":");
if (!reformatText.startsWith("(") || !reformatText.endsWith(")")) {
reformatText = "( " + reformatText + " )";
}
......
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