SimpleVSRRecordMatcher extends AbstractRecordMatcher { @Override public double getMatchingWeight(String[] record1, String[] record2) { double result = 0; if (blockedIndices != null) { for (int i = 0; i < super.blockedIndices.length; i++) { int blockedIdx = blockedIndices[i]; double pa = computeMatchingWeight(blockedIdx, record1, record2); if (pa < super.blockingThreshold) { return 0; } result += pa * attributeWeights[blockedIdx]; } } for (int j = 0; j < getUsedIndicesNotblocked().length; j++) { int usedIdx = usedIndicesNotblocked[j]; double pa = computeMatchingWeight(usedIdx, record1, record2); result += pa * attributeWeights[usedIdx]; } if (result > 1.0) { final BigDecimal l = new BigDecimal(Double.toString(result)); result = l.setScale(1, BigDecimal.ROUND_DOWN).doubleValue(); } return result; }  @Override double getMatchingWeight(String[] record1, String[] record2); @Override MatchResult getMatchingWeight(Record record1, Record record2);  }
@Test public void testGetMatchingWeightRcdSize() { int weightIdx = 0; IRecordMatcher match = RecordMatcherFactory.createMatcher(RecordMatcherType.simpleVSRMatcher); for (double[] attributeWeights : ALLATTRIBUTEWEIGHTS) { match.setRecordSize(3); assertEquals(true, match.setAttributeMatchers(new IAttributeMatcher[] { new ExactIgnoreCaseMatcher(), new JaroWinklerMatcher(), new ExactIgnoreCaseMatcher() })); if (!areValidAttributeWeitghts(match, attributeWeights)) { return; } int matchIdx = 0; for (String[] record1 : RECORDS1) { for (String[] record2 : RECORDS2_UNREG) { double matchingProba = 0d; try { matchingProba = match.getMatchingWeight(record1, record2); assertEquals(MATCH_PROBS[weightIdx][matchIdx], matchingProba, EPSILON); System.out.println( "P(" + printRecord(record1) + " = " + printRecord(record2) + ") =" + matchingProba); } catch (ArrayIndexOutOfBoundsException idxOutExc) { assertEquals(0d, matchingProba, EPSILON); } matchIdx++; } } weightIdx++; } }
@Test public void testGetMatchingWeightWithDistance() { IRecordMatcher recordMatcher = RecordMatcherFactory.createMatcher(RecordMatcherType.simpleVSRMatcher); int nbRecords = 3; recordMatcher.setRecordSize(nbRecords); int nbJoinKey = ATTRIBUTEMATCHERALGORITHMS.length; IAttributeMatcher[] attributeMatchers = new IAttributeMatcher[nbJoinKey]; for (int i = 0; i < attributeMatchers.length; i++) { attributeMatchers[i] = AttributeMatcherFactory.createMatcher(ATTRIBUTEMATCHERALGORITHMS[i]); } recordMatcher.setAttributeMatchers(attributeMatchers); assertTrue(recordMatcher.setAttributeWeights(ATTRIBUTEWEIGHTS)); List<Integer> listIndices = new ArrayList<Integer>(); for (int i = 0; i < attributeMatchers.length; i++) { AttributeMatcherType matchType = attributeMatchers[i].getMatchType(); if (AttributeMatcherType.EXACT.equals(matchType) || AttributeMatcherType.EXACT_IGNORE_CASE.equals(matchType)) { listIndices.add(i); } } int[] blockedVariableIndices = new int[listIndices.size()]; for (int i = 0; i < listIndices.size(); i++) { blockedVariableIndices[i] = listIndices.get(i); } recordMatcher.setBlockingAttributeMatchers(blockedVariableIndices); int idx = 0; for (String[] record1 : MAINRECORDS) { for (String[] record2 : LOOKUPRECORDS) { final double matchingProba = recordMatcher.getMatchingWeight(record1, record2); assertEquals(MATCH_PROBS_WITH_DISTINCE[idx], matchingProba, EPSILON); idx++; if (matchingProba >= ACCEPTABLE_THRESHOLD) { System.out.println( " MATCH P(" + printRecord(record1) + " = " + printRecord(record2) + ") =" + matchingProba + " DETAILS=" + printRecord(recordMatcher.getCurrentAttributeMatchingWeights())); continue; } if (UNACCEPTABLE_THRESHOLD < matchingProba && matchingProba < ACCEPTABLE_THRESHOLD) { System.out.println(" POSSIBLE MATCH P(" + printRecord(record1) + " = " + printRecord(record2) + ") =" + matchingProba + " DETAILS=" + printRecord(recordMatcher.getCurrentAttributeMatchingWeights())); continue; } System.out.println( "!match P(" + printRecord(record1) + " = " + printRecord(record2) + ") =" + matchingProba + " DETAILS=" + printRecord(recordMatcher.getCurrentAttributeMatchingWeights())); } } }
@Test public void testGetMatchingWeightWithDistance_2() { IRecordMatcher recordMatcher = RecordMatcherFactory.createMatcher(RecordMatcherType.simpleVSRMatcher); int nbRecords = 6; recordMatcher.setRecordSize(nbRecords); int nbJoinKey = 6; IAttributeMatcher[] attributeMatchers = new IAttributeMatcher[nbJoinKey]; for (int i = 0; i < attributeMatchers.length; i++) { attributeMatchers[i] = AttributeMatcherFactory.createMatcher("Exact"); } recordMatcher.setAttributeMatchers(attributeMatchers); double[] attributeWeight = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; assertTrue(recordMatcher.setAttributeWeights(attributeWeight)); String[] record1 = { "aTO1mK", "dXatJF", "6vVVQl", "5ILPaE", "cwBh91", "WEWkkS" }; String[] record2 = { "ThSymJ", "ymLm1u", "ZM7ilc", "0nCUz8", "SOPHs7", "boqY3Y" }; final double matchingProba = recordMatcher.getMatchingWeight(record1, record1); assertTrue(matchingProba >= 1.0); final double matchingProbb = recordMatcher.getMatchingWeight(record2, record2); assertTrue(matchingProbb >= 1.0); }
@Test public void testGetMatchingWeightWithDistance_3() { IRecordMatcher recordMatcher = RecordMatcherFactory.createMatcher(RecordMatcherType.simpleVSRMatcher); int nbRecords = 19; recordMatcher.setRecordSize(nbRecords); int nbJoinKey = 19; IAttributeMatcher[] attributeMatchers = new IAttributeMatcher[nbJoinKey]; for (int i = 0; i < attributeMatchers.length; i++) { attributeMatchers[i] = AttributeMatcherFactory.createMatcher("Exact"); } recordMatcher.setAttributeMatchers(attributeMatchers); double[] attributeWeight = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; assertTrue(recordMatcher.setAttributeWeights(attributeWeight)); String[] record1 = { "aTO1mK", "dXatJF", "6vVVQl", "5ILPaE", "cwBh91", "WEWkkS", "cIWupW", "2fj8BW", "melpcx", "8MOIxp", "NrJKCh", "XgFwsN", "f8OXQS", "iSJjtn", "Nflx4L", "lEEXi8", "mLi1Fy", "JiQvqQ", "onvRDZ", "JiQvqQ", "onvRDZ" }; String[] record2 = { "ThSymJ", "ymLm1u", "ZM7ilc", "0nCUz8", "SOPHs7", "boqY3Y", "OWzqig", "eypLAO", "rJzJGe", "fwhrJT", "j8Ekqm", "8q9Jcr", "sSKY7P", "SQxLve", "vQRPJd", "gqvZeq", "ENchvh", "YKHGxQ", "xgkjjf", "JiQvqQ", "onvRDZ" }; final double matchingProba = recordMatcher.getMatchingWeight(record1, record1); assertTrue(matchingProba >= 1.0); final double matchingProbb = recordMatcher.getMatchingWeight(record2, record2); assertTrue(matchingProbb >= 1.0); }
@Test public void testGetMatchingWeight() { int weightIdx = 0; IRecordMatcher match = RecordMatcherFactory.createMatcher(RecordMatcherType.simpleVSRMatcher); for (double[] attributeWeights : ALLATTRIBUTEWEIGHTS) { computeForWeights(attributeWeights, match, weightIdx); weightIdx++; } }
@Test public void testgetLabeledAttributeMatchWeights() { AttributeMatcherType type = AttributeMatcherType.JARO; IAttributeMatcher attMatcher = AttributeMatcherFactory.createMatcher(type); final String colName = "EMAIL"; attMatcher.setAttributeName(colName); IAttributeMatcher[] allAttMatchers = new IAttributeMatcher[] { attMatcher }; IRecordMatcher matcher = RecordMatcherFactory.createMatcher(RecordMatcherType.simpleVSRMatcher); matcher.setRecordSize(1); assertTrue(matcher.setAttributeMatchers(allAttMatchers)); matcher.setDisplayLabels(Boolean.TRUE); String labeledAttributeMatchWeights = matcher.getLabeledAttributeMatchWeights(); assertEquals("no computation done. Result should be 0", "EMAIL: 0.0", labeledAttributeMatchWeights); assertEquals(1.0d, matcher.getMatchingWeight(RECORDS1[1], RECORDS1[1]), EPSILON); labeledAttributeMatchWeights = matcher.getLabeledAttributeMatchWeights(); assertEquals("Computation done and exact match. Result should be 1", "EMAIL: 1.0", labeledAttributeMatchWeights); }