diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java index dd3002b..03c1f83 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/ConditionWidget.java @@ -10,6 +10,9 @@ import org.gcube.portlets.user.td.expressionwidget.client.operation.Operation; import org.gcube.portlets.user.td.expressionwidget.client.operation.OperationProperties; import org.gcube.portlets.user.td.expressionwidget.client.operation.OperationsStore; import org.gcube.portlets.user.td.expressionwidget.client.resources.ExpressionResources; +import org.gcube.portlets.user.td.expressionwidget.client.threshold.Threshold; +import org.gcube.portlets.user.td.expressionwidget.client.threshold.ThresholdProperties; +import org.gcube.portlets.user.td.expressionwidget.client.threshold.ThresholdStore; import org.gcube.portlets.user.td.expressionwidget.shared.condition.ConditionTypeMap; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException; import org.gcube.portlets.user.td.gwtservice.shared.tr.ColumnData; @@ -61,6 +64,8 @@ public class ConditionWidget extends SimpleContainer { protected String itemIdSecondArg; protected String itemIdFirstArgDate; protected String itemIdSecondArgDate; + protected String itemIdComboThreshold; + protected String itemIdBtnAdd; protected String itemIdBtnDel; protected VerticalLayoutContainer vert; @@ -92,6 +97,7 @@ public class ConditionWidget extends SimpleContainer { itemIdSecondArg = "SecondArg" + column.getName(); itemIdFirstArgDate = "FirstArgDate" + column.getName(); itemIdSecondArgDate = "SecondArgDate" + column.getName(); + itemIdComboThreshold = "ComboThreshold" + column.getName(); itemIdBtnAdd = "BtnAdd" + column.getName(); itemIdBtnDel = "BtnDel" + column.getName(); @@ -122,7 +128,7 @@ public class ConditionWidget extends SimpleContainer { groupMatch.setValue(radioAll); vert = new VerticalLayoutContainer(); - //vert.setScrollMode(ScrollMode.AUTO); Set In GXT 3.0.1 + // vert.setScrollMode(ScrollMode.AUTO); Set In GXT 3.0.1 vert.setAdjustForScroll(true); setup(); @@ -156,6 +162,33 @@ public class ConditionWidget extends SimpleContainer { secondArgDate.setItemId(itemIdSecondArgDate); secondArgDate.setVisible(false); + // Combo Similarity and Levenshtein threshold + ThresholdProperties propsThreshold = GWT + .create(ThresholdProperties.class); + Log.debug("Props: " + propsThreshold); + final ListStore storeThreshold = new ListStore( + propsThreshold.id()); + Log.debug("StoreThreshold: " + storeThreshold); + storeThreshold.addAll(ThresholdStore.thresholdsLevenshtein); + + Log.debug("StoreThreshold created"); + final ComboBox comboThreshold = new ComboBox( + storeThreshold, propsThreshold.label()); + + Log.debug("Combo Threshold created"); + + comboThreshold.setEmptyText("Select a threshold..."); + comboThreshold.setItemId(itemIdComboThreshold); + comboThreshold.setWidth("100px"); + comboThreshold.setEditable(false); + comboThreshold.setTriggerAction(TriggerAction.ALL); + comboThreshold.setVisible(false); + + final HTML thresholdText = new HTML( + "
Threshold:
"); + thresholdText.setVisible(false); + + // Button final IconButton btnAdd = new IconButton(); btnAdd.setItemId(itemIdBtnAdd); btnAdd.setIcon(ExpressionResources.INSTANCE.add()); @@ -195,6 +228,7 @@ public class ConditionWidget extends SimpleContainer { }); btnDel.setVisible(false); + // Operation OperationProperties props = GWT.create(OperationProperties.class); Log.debug("Props: " + props); ListStore storeOp = new ListStore(props.id()); @@ -233,15 +267,19 @@ public class ConditionWidget extends SimpleContainer { case NOT_MATCH_REGEX: case IN: case NOT_IN: - case SOUNDEX: + case SOUNDEX: if (column.getDataTypeName().compareTo("Date") == 0) { firstArgDate.setVisible(true); andText.setVisible(false); secondArgDate.setVisible(false); + comboThreshold.setVisible(false); + thresholdText.setVisible(false); } else { firstArg.setVisible(true); andText.setVisible(false); secondArg.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } btnAdd.setVisible(true); btnDel.setVisible(true); @@ -252,10 +290,66 @@ public class ConditionWidget extends SimpleContainer { firstArgDate.setVisible(false); andText.setVisible(false); secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } else { firstArg.setVisible(true); andText.setVisible(true); secondArg.setVisible(true); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } + btnAdd.setVisible(true); + btnDel.setVisible(true); + break; + case LEVENSHTEIN: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArg.setVisible(true); + andText.setVisible(false); + secondArg.setVisible(false); + thresholdText.setVisible(true); + storeThreshold.clear(); + storeThreshold + .addAll(ThresholdStore.thresholdsLevenshtein); + storeThreshold.commitChanges(); + comboThreshold.clear(); + comboThreshold.reset(); + comboThreshold.setVisible(true); + comboThreshold.setValue(ThresholdStore + .defaultThresholdLevenshtein()); + + } + btnAdd.setVisible(true); + btnDel.setVisible(true); + break; + case SIMILARITY: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArg.setVisible(true); + andText.setVisible(false); + secondArg.setVisible(false); + thresholdText.setVisible(true); + storeThreshold.clear(); + storeThreshold + .addAll(ThresholdStore.thresholdsSimilarity); + storeThreshold.commitChanges(); + comboThreshold.clear(); + comboThreshold.reset(); + comboThreshold.setVisible(true); + comboThreshold.setValue(ThresholdStore + .defaultThresholdSimilarity()); + } btnAdd.setVisible(true); btnDel.setVisible(true); @@ -266,10 +360,14 @@ public class ConditionWidget extends SimpleContainer { firstArgDate.setVisible(false); andText.setVisible(false); secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } else { firstArg.setVisible(false); andText.setVisible(false); secondArg.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } btnAdd.setVisible(true); btnDel.setVisible(true); @@ -296,10 +394,14 @@ public class ConditionWidget extends SimpleContainer { horiz.add(firstArgDate, new BoxLayoutData(new Margins(0))); horiz.add(andText, new BoxLayoutData(new Margins(0))); horiz.add(secondArgDate, new BoxLayoutData(new Margins(0))); + horiz.add(thresholdText, new BoxLayoutData(new Margins(0))); + horiz.add(comboThreshold, new BoxLayoutData(new Margins(0))); } else { horiz.add(firstArg, new BoxLayoutData(new Margins(0))); horiz.add(andText, new BoxLayoutData(new Margins(0))); horiz.add(secondArg, new BoxLayoutData(new Margins(0))); + horiz.add(thresholdText, new BoxLayoutData(new Margins(0))); + horiz.add(comboThreshold, new BoxLayoutData(new Margins(0))); } horiz.add(btnAdd, new BoxLayoutData(new Margins(2, 0, 2, 0))); horiz.add(btnDel, new BoxLayoutData(new Margins(2, 0, 2, 0))); @@ -340,6 +442,35 @@ public class ConditionWidget extends SimpleContainer { secondArgDate.setItemId(itemIdSecondArgDate); secondArgDate.setVisible(false); + // Combo Similarity and Levenshtein threshold + ThresholdProperties propsThreshold = GWT + .create(ThresholdProperties.class); + Log.debug("Props: " + propsThreshold); + final ListStore storeThreshold = new ListStore( + propsThreshold.id()); + Log.debug("StoreThreshold: " + storeThreshold); + storeThreshold.addAll(ThresholdStore.thresholdsLevenshtein); + + Log.debug("StoreThreshold created"); + final ComboBox comboThreshold = new ComboBox( + storeThreshold, propsThreshold.label()); + + Log.debug("Combo Threshold created"); + + comboThreshold.setEmptyText("Select a threshold..."); + comboThreshold.setItemId(itemIdComboThreshold); + comboThreshold.setWidth("100px"); + comboThreshold.setEditable(false); + comboThreshold.setTriggerAction(TriggerAction.ALL); + comboThreshold.setVisible(false); + + + final HTML thresholdText = new HTML( + "
Threshold:
"); + thresholdText.setVisible(false); + + + // Button final IconButton btnAdd = new IconButton(); btnAdd.setItemId(itemIdBtnAdd); btnAdd.setIcon(ExpressionResources.INSTANCE.add()); @@ -415,15 +546,19 @@ public class ConditionWidget extends SimpleContainer { case NOT_MATCH_REGEX: case IN: case NOT_IN: - case SOUNDEX: + case SOUNDEX: if (column.getDataTypeName().compareTo("Date") == 0) { firstArgDate.setVisible(true); andText.setVisible(false); secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } else { firstArg.setVisible(true); andText.setVisible(false); secondArg.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } btnAdd.setVisible(true); btnDel.setVisible(true); @@ -434,24 +569,84 @@ public class ConditionWidget extends SimpleContainer { firstArgDate.setVisible(false); andText.setVisible(false); secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } else { firstArg.setVisible(true); andText.setVisible(true); secondArg.setVisible(true); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } btnAdd.setVisible(true); btnDel.setVisible(true); break; + case LEVENSHTEIN: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArg.setVisible(true); + andText.setVisible(false); + secondArg.setVisible(false); + thresholdText.setVisible(true); + storeThreshold.clear(); + storeThreshold + .addAll(ThresholdStore.thresholdsLevenshtein); + storeThreshold.commitChanges(); + comboThreshold.clear(); + comboThreshold.reset(); + comboThreshold.setVisible(true); + comboThreshold.setValue(ThresholdStore + .defaultThresholdLevenshtein()); + + } + btnAdd.setVisible(true); + btnDel.setVisible(true); + break; + case SIMILARITY: + if (column.getDataTypeName().compareTo("Date") == 0) { + firstArgDate.setVisible(false); + andText.setVisible(false); + secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); + } else { + firstArg.setVisible(true); + andText.setVisible(false); + secondArg.setVisible(false); + thresholdText.setVisible(true); + storeThreshold.clear(); + storeThreshold + .addAll(ThresholdStore.thresholdsSimilarity); + storeThreshold.commitChanges(); + comboThreshold.clear(); + comboThreshold.reset(); + comboThreshold.setVisible(true); + comboThreshold.setValue(ThresholdStore + .defaultThresholdSimilarity()); + + } + btnAdd.setVisible(true); + btnDel.setVisible(true); + break; case IS_NULL: case IS_NOT_NULL: if (column.getDataTypeName().compareTo("Date") == 0) { firstArgDate.setVisible(false); andText.setVisible(false); secondArgDate.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } else { firstArg.setVisible(false); andText.setVisible(false); secondArg.setVisible(false); + thresholdText.setVisible(false); + comboThreshold.setVisible(false); } btnAdd.setVisible(true); btnDel.setVisible(true); @@ -478,10 +673,14 @@ public class ConditionWidget extends SimpleContainer { horiz.add(firstArgDate, new BoxLayoutData(new Margins(0))); horiz.add(andText, new BoxLayoutData(new Margins(0))); horiz.add(secondArgDate, new BoxLayoutData(new Margins(0))); + horiz.add(thresholdText, new BoxLayoutData(new Margins(0))); + horiz.add(comboThreshold, new BoxLayoutData(new Margins(0))); } else { horiz.add(firstArg, new BoxLayoutData(new Margins(0))); horiz.add(andText, new BoxLayoutData(new Margins(0))); horiz.add(secondArg, new BoxLayoutData(new Margins(0))); + horiz.add(thresholdText, new BoxLayoutData(new Margins(0))); + horiz.add(comboThreshold, new BoxLayoutData(new Margins(0))); } horiz.add(btnAdd, new BoxLayoutData(new Margins(2, 0, 2, 0))); horiz.add(btnDel, new BoxLayoutData(new Margins(2, 0, 2, 0))); @@ -490,6 +689,8 @@ public class ConditionWidget extends SimpleContainer { } + + @SuppressWarnings("unchecked") public C_Expression getExpression() throws ConditionTypeMapException { C_Expression exp = null; readableExpression = new String(); @@ -499,6 +700,8 @@ public class ConditionWidget extends SimpleContainer { TextField secondArg; DateField firstArgDate; DateField secondArgDate; + ComboBox comboThreshold; + C_Expression expression; DateTimeFormat sdf = DateTimeFormat.getFormat("yyyy-MM-dd"); @@ -508,7 +711,6 @@ public class ConditionWidget extends SimpleContainer { HBoxLayoutContainer horiz; while (iteratorVert.hasNext()) { horiz = (HBoxLayoutContainer) iteratorVert.next(); - @SuppressWarnings("unchecked") ComboBox comboOp = (ComboBox) horiz .getItemByItemId(itemIdCombo); Log.debug("combo: " + comboOp.getCurrentValue().toString()); @@ -527,18 +729,22 @@ public class ConditionWidget extends SimpleContainer { expression = mapOp.map(column, comboOp.getCurrentValue() .getOperatorType(), firstDate == null ? null : sdf.format(firstDate), - secondDate == null ? null : sdf.format(secondDate)); + secondDate == null ? null : sdf.format(secondDate) + ,null); } else { firstArg = (TextField) horiz.getItemByItemId(itemIdFirstArg); secondArg = (TextField) horiz.getItemByItemId(itemIdSecondArg); + comboThreshold =(ComboBox) horiz.getItemByItemId(itemIdComboThreshold); + Log.debug("argLeft: " + firstArg.getCurrentValue() + " argRight: " + secondArg.getCurrentValue()); expression = mapOp.map(column, comboOp.getCurrentValue() .getOperatorType(), firstArg == null ? null : firstArg.getCurrentValue(), - secondArg == null ? null : secondArg.getCurrentValue()); + secondArg == null ? null : secondArg.getCurrentValue(), + comboThreshold.getCurrentValue()==null?null:comboThreshold.getCurrentValue()); } readableExpressionList.add(mapOp.getReadableExpression()); Log.debug(expression.toString()); diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/operation/OperationsStore.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/operation/OperationsStore.java index 7079a52..18c1306 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/operation/OperationsStore.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/operation/OperationsStore.java @@ -55,6 +55,8 @@ public class OperationsStore { add(new Operation(15,"IN","The value is in",C_OperatorType.IN)); add(new Operation(16,"NOT_IN","The value is not in",C_OperatorType.NOT_IN)); add(new Operation(17,"SOUNDEX","The soundex is equal to", C_OperatorType.SOUNDEX)); + add(new Operation(18,"LEVENSHTEIN","Levenshtein", C_OperatorType.LEVENSHTEIN)); + add(new Operation(19,"SIMILARITY","Similarity", C_OperatorType.SIMILARITY)); }}; protected ArrayList operationsBoolean = new ArrayList() { diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/threshold/Threshold.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/threshold/Threshold.java new file mode 100644 index 0000000..ea04521 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/threshold/Threshold.java @@ -0,0 +1,71 @@ +package org.gcube.portlets.user.td.expressionwidget.client.threshold; + +import java.io.Serializable; + + + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class Threshold implements Serializable { + + private static final long serialVersionUID = 3713817747863556150L; + + private Integer id; + private Float value; + private String label; + + + public Threshold(Integer id,Integer value,String label){ + this.id=id; + this.value=new Float(value); + this.label=label; + } + + public Threshold(Integer id,Float value, String label){ + this.id=id; + this.value=value; + this.label=label; + } + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Float getValue() { + return value; + } + + public Integer getIntegerValue() { + return value.intValue(); + } + + public void setValue(Float value) { + this.value = value; + } + + + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + @Override + public String toString() { + return "Threshold [id=" + id + ", value=" + value + ", label=" + label + + "]"; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/threshold/ThresholdProperties.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/threshold/ThresholdProperties.java new file mode 100644 index 0000000..b4df22c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/threshold/ThresholdProperties.java @@ -0,0 +1,21 @@ +package org.gcube.portlets.user.td.expressionwidget.client.threshold; + +import com.google.gwt.editor.client.Editor.Path; +import com.sencha.gxt.data.shared.LabelProvider; +import com.sencha.gxt.data.shared.ModelKeyProvider; +import com.sencha.gxt.data.shared.PropertyAccess; + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public interface ThresholdProperties extends PropertyAccess { + + @Path("id") + ModelKeyProvider id(); + + LabelProvider label(); + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/threshold/ThresholdStore.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/threshold/ThresholdStore.java new file mode 100644 index 0000000..83d561d --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/client/threshold/ThresholdStore.java @@ -0,0 +1,56 @@ +package org.gcube.portlets.user.td.expressionwidget.client.threshold; + +import java.util.ArrayList; + + + +/** + * + * @author "Giancarlo Panichi" + * g.panichi@isti.cnr.it + * + */ +public class ThresholdStore { + + + public static ArrayList thresholdsLevenshtein = new ArrayList() { + private static final long serialVersionUID = -6559885743626876431L; + { + add(new Threshold(1,1,"1")); + add(new Threshold(2,2,"2")); + add(new Threshold(3,3,"3")); + add(new Threshold(4,4,"4")); + add(new Threshold(5,5,"5")); + add(new Threshold(6,6,"6")); + add(new Threshold(7,7,"7")); + add(new Threshold(8,8,"8")); + add(new Threshold(9,9,"9")); + add(new Threshold(10,10,"10")); + }}; + + public static Threshold defaultThresholdLevenshtein(){ + return new Threshold(2,2,"2"); + } + + + public static ArrayList thresholdsSimilarity = new ArrayList() { + private static final long serialVersionUID = -6559885743626876431L; + { + add(new Threshold(1,0.0f,"0")); + add(new Threshold(2,0.1f,"0.1")); + add(new Threshold(3,0.2f,"0.2")); + add(new Threshold(4,0.3f,"0.3")); + add(new Threshold(5,0.4f,"0.4")); + add(new Threshold(6,0.5f,"0.5")); + add(new Threshold(7,0.6f,"0.6")); + add(new Threshold(8,0.7f,"0.7")); + add(new Threshold(9,0.8f,"0.8")); + add(new Threshold(10,0.9f,"0.9")); + }}; + + public static Threshold defaultThresholdSimilarity(){ + return new Threshold(9,0.8f,"0.8"); + } + + +} diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/C_ExpressionParser.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/C_ExpressionParser.java index 645d5df..220d6b9 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/C_ExpressionParser.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/server/C_ExpressionParser.java @@ -28,8 +28,10 @@ import org.gcube.data.analysis.tabulardata.expression.composite.comparable.NotEq import org.gcube.data.analysis.tabulardata.expression.composite.comparable.NotGreater; import org.gcube.data.analysis.tabulardata.expression.composite.comparable.NotLess; import org.gcube.data.analysis.tabulardata.expression.composite.text.Concat; +import org.gcube.data.analysis.tabulardata.expression.composite.text.Levenshtein; import org.gcube.data.analysis.tabulardata.expression.composite.text.Lower; import org.gcube.data.analysis.tabulardata.expression.composite.text.MD5; +import org.gcube.data.analysis.tabulardata.expression.composite.text.Similarity; import org.gcube.data.analysis.tabulardata.expression.composite.text.Soundex; import org.gcube.data.analysis.tabulardata.expression.composite.text.SubstringByIndex; import org.gcube.data.analysis.tabulardata.expression.composite.text.SubstringByRegex; @@ -92,8 +94,10 @@ import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.compar import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotLess; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.functions.C_Cast; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Concat; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Levenshtein; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Lower; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_MD5; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Similarity; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Soundex; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByIndex; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_SubstringByRegex; @@ -271,7 +275,14 @@ public class C_ExpressionParser { break; case "Soundex": ex = getSoundex(exp); - default: + break; + case "Levenshtein": + ex = getLevenshtein(exp); + break; + case "Similarity": + ex = getSimilarity(exp); + break; + default: break; } @@ -661,6 +672,27 @@ public class C_ExpressionParser { return soundex; } + protected Expression getLevenshtein(C_Expression exp) + throws ExpressionParserException { + C_Levenshtein e = (C_Levenshtein) exp; + Expression left = parse(e.getLeftArgument()); + Expression right = parse(e.getRightArgument()); + + Levenshtein levenshtein = new Levenshtein(left,right); + return levenshtein; + } + + protected Expression getSimilarity(C_Expression exp) + throws ExpressionParserException { + C_Similarity e = (C_Similarity) exp; + Expression left = parse(e.getLeftArgument()); + Expression right = parse(e.getRightArgument()); + + Similarity similarity = new Similarity(left,right); + return similarity; + } + + protected Expression getEquals(C_Expression exp) throws ExpressionParserException { diff --git a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/condition/ConditionTypeMap.java b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/condition/ConditionTypeMap.java index 2a56865..4660057 100644 --- a/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/condition/ConditionTypeMap.java +++ b/src/main/java/org/gcube/portlets/user/td/expressionwidget/shared/condition/ConditionTypeMap.java @@ -3,6 +3,8 @@ package org.gcube.portlets.user.td.expressionwidget.shared.condition; import java.util.ArrayList; import java.util.List; +import org.gcube.portlets.user.td.expressionwidget.client.threshold.Threshold; +import org.gcube.portlets.user.td.expressionwidget.client.threshold.ThresholdStore; import org.gcube.portlets.user.td.expressionwidget.shared.exception.ConditionTypeMapException; import org.gcube.portlets.user.td.expressionwidget.shared.model.C_OperatorType; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_Equals; @@ -13,6 +15,8 @@ import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.compar import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotEquals; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotGreater; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.comparable.C_NotLess; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Levenshtein; +import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Similarity; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_Soundex; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_TextBeginsWith; import org.gcube.portlets.user.td.expressionwidget.shared.model.composite.text.C_TextContains; @@ -51,21 +55,21 @@ public class ConditionTypeMap { } public C_Expression map(ColumnData column, C_OperatorType operatorType, - String firstArg, String secondArg) throws ConditionTypeMapException { + String firstArg, String secondArg, Threshold threshold) throws ConditionTypeMapException { Log.debug("ConditionTypeMap Map"); C_Expression exp = null; readableExpression = new String(); if (column.getTrId() == null) { - exp = mapPlaceHolder(column, operatorType, firstArg, secondArg); + exp = mapPlaceHolder(column, operatorType, firstArg, secondArg, threshold); } else { exp = mapTypedColumnReference(column, operatorType, firstArg, - secondArg); + secondArg, threshold); } return exp; } public C_Expression mapPlaceHolder(ColumnData column, - C_OperatorType operatorType, String firstArg, String secondArg) + C_OperatorType operatorType, String firstArg, String secondArg, Threshold threshold) throws ConditionTypeMapException { Log.debug("ConditionTypeMap Map Place Holder"); C_Expression exp = null; @@ -337,6 +341,37 @@ public class ConditionTypeMap { readableExpression = "Equals(Soundex(" + readablePlaceHolder + "),Soundex(" + firstArg + "))"; break; + case LEVENSHTEIN: + checkTypeArgument(column, firstArg); + C_Levenshtein levenshstein=new C_Levenshtein(placeHolder,new TD_Value(dataType, firstArg)); + Threshold thresholdLev; + + if(threshold==null){ + thresholdLev=ThresholdStore.defaultThresholdLevenshtein(); + } else { + thresholdLev=threshold; + } + exp= new C_LessOrEquals(levenshstein,new TD_Value(ColumnDataType.Integer, + thresholdLev.getIntegerValue().toString())); + readableExpression = "LessOrEquals(Levenshtein(" + readablePlaceHolder + ","+firstArg+")," + + thresholdLev.getIntegerValue().toString() + ")"; + break; + case SIMILARITY: + checkTypeArgument(column, firstArg); + C_Similarity similarity=new C_Similarity(placeHolder,new TD_Value(dataType, firstArg)); + Threshold thresholdSim; + + if(threshold==null){ + thresholdSim=ThresholdStore.defaultThresholdSimilarity(); + } else { + thresholdSim=threshold; + } + exp= new C_GreaterOrEquals(similarity,new TD_Value(ColumnDataType.Numeric, + thresholdSim.getLabel())); + readableExpression = "GreaterOrEquals(Similarity(" + readablePlaceHolder + ","+firstArg+")," + + thresholdSim.getLabel() + ")"; + break; + default: break; } @@ -345,7 +380,7 @@ public class ConditionTypeMap { } public C_Expression mapTypedColumnReference(ColumnData column, - C_OperatorType operatorType, String firstArg, String secondArg) + C_OperatorType operatorType, String firstArg, String secondArg, Threshold threshold) throws ConditionTypeMapException { Log.debug("ConditionTypeMap Map Typed Column Reference"); C_Expression exp = null; @@ -622,7 +657,37 @@ public class ConditionTypeMap { exp = new C_Equals(soundexPlaceHolder, soundexValue); readableExpression = "Equals(Soundex(" + columnReference + "),Soundex(" + firstArg + "))"; - break; + break; + case LEVENSHTEIN: + checkTypeArgument(column, firstArg); + C_Levenshtein levenshstein=new C_Levenshtein(columnReference,new TD_Value(dataType, firstArg)); + Threshold thresholdLev; + + if(threshold==null){ + thresholdLev=ThresholdStore.defaultThresholdLevenshtein(); + } else { + thresholdLev=threshold; + } + exp= new C_LessOrEquals(levenshstein,new TD_Value(ColumnDataType.Integer, + thresholdLev.getIntegerValue().toString())); + readableExpression = "LessOrEquals(Levenshtein(" + readableColumnReference + ","+firstArg+")," + + thresholdLev.getIntegerValue().toString() + ")"; + break; + case SIMILARITY: + checkTypeArgument(column, firstArg); + C_Similarity similarity=new C_Similarity(columnReference,new TD_Value(dataType, firstArg)); + Threshold thresholdSim; + + if(threshold==null){ + thresholdSim=ThresholdStore.defaultThresholdSimilarity(); + } else { + thresholdSim=threshold; + } + exp= new C_GreaterOrEquals(similarity,new TD_Value(ColumnDataType.Numeric, + thresholdSim.getLabel())); + readableExpression = "GreaterOrEquals(Similarity(" + readableColumnReference + ","+firstArg+")," + + thresholdSim.getLabel() + ")"; + break; default: break; }