@Test public void testTextDistanceMeasure() throws Exception { String[] directives = new String[] { "text-distance cosine string1 string2 cosine", "text-distance euclidean string1 string2 euclidean", "text-distance block-distance string1 string2 block_distance", "text-distance identity string1 string2 identity", "text-distance block string1 string2 block", "text-distance dice string1 string2 dice", "text-distance jaro string1 string2 jaro", "text-distance longest-common-subsequence string1 string2 lcs1", "text-distance longest-common-substring string1 string2 lcs2", "text-distance overlap-cofficient string1 string2 oc", "text-distance damerau-levenshtein string1 string2 dl", "text-distance simon-white string1 string2 sw", "text-distance levenshtein string1 string2 levenshtein", }; List<Row> results = TestingRig.execute(directives, ROWS); Assert.assertTrue(results.size() == 4); Assert.assertEquals(15, results.get(0).width()); Assert.assertEquals(15, results.get(1).width()); Assert.assertEquals(15, results.get(2).width()); Assert.assertEquals(14, results.get(3).width()); }
@Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx1 = row.find(column1); int idx2 = row.find(column2); if (idx1 == -1 || idx2 == -1) { row.add(destination, 0.0f); continue; } Object object1 = row.getValue(idx1); Object object2 = row.getValue(idx2); if (object1 == null || object2 == null) { row.add(destination, 0.0f); continue; } if (!(object1 instanceof String) || !(object2 instanceof String)) { row.add(destination, 0.0f); continue; } if (((String) object1).isEmpty() || ((String) object2).isEmpty()) { row.add(destination, 0.0f); continue; } row.add(destination, distance.distance((String) object1, (String) object2)); } return rows; }
TextDistanceMeasure implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx1 = row.find(column1); int idx2 = row.find(column2); if (idx1 == -1 || idx2 == -1) { row.add(destination, 0.0f); continue; } Object object1 = row.getValue(idx1); Object object2 = row.getValue(idx2); if (object1 == null || object2 == null) { row.add(destination, 0.0f); continue; } if (!(object1 instanceof String) || !(object2 instanceof String)) { row.add(destination, 0.0f); continue; } if (((String) object1).isEmpty() || ((String) object2).isEmpty()) { row.add(destination, 0.0f); continue; } row.add(destination, distance.distance((String) object1, (String) object2)); } return rows; } }
TextDistanceMeasure implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx1 = row.find(column1); int idx2 = row.find(column2); if (idx1 == -1 || idx2 == -1) { row.add(destination, 0.0f); continue; } Object object1 = row.getValue(idx1); Object object2 = row.getValue(idx2); if (object1 == null || object2 == null) { row.add(destination, 0.0f); continue; } if (!(object1 instanceof String) || !(object2 instanceof String)) { row.add(destination, 0.0f); continue; } if (((String) object1).isEmpty() || ((String) object2).isEmpty()) { row.add(destination, 0.0f); continue; } row.add(destination, distance.distance((String) object1, (String) object2)); } return rows; }  }
TextDistanceMeasure implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx1 = row.find(column1); int idx2 = row.find(column2); if (idx1 == -1 || idx2 == -1) { row.add(destination, 0.0f); continue; } Object object1 = row.getValue(idx1); Object object2 = row.getValue(idx2); if (object1 == null || object2 == null) { row.add(destination, 0.0f); continue; } if (!(object1 instanceof String) || !(object2 instanceof String)) { row.add(destination, 0.0f); continue; } if (((String) object1).isEmpty() || ((String) object2).isEmpty()) { row.add(destination, 0.0f); continue; } row.add(destination, distance.distance((String) object1, (String) object2)); } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); }
TextDistanceMeasure implements Directive, Lineage { @Override public List<Row> execute(List<Row> rows, ExecutorContext context) throws DirectiveExecutionException { for (Row row : rows) { int idx1 = row.find(column1); int idx2 = row.find(column2); if (idx1 == -1 || idx2 == -1) { row.add(destination, 0.0f); continue; } Object object1 = row.getValue(idx1); Object object2 = row.getValue(idx2); if (object1 == null || object2 == null) { row.add(destination, 0.0f); continue; } if (!(object1 instanceof String) || !(object2 instanceof String)) { row.add(destination, 0.0f); continue; } if (((String) object1).isEmpty() || ((String) object2).isEmpty()) { row.add(destination, 0.0f); continue; } row.add(destination, distance.distance((String) object1, (String) object2)); } return rows; }  @Override UsageDefinition define(); @Override void initialize(Arguments args); @Override void destroy(); @Override List<Row> execute(List<Row> rows, ExecutorContext context); @Override Mutation lineage(); static final String NAME; }