MultiPassGroupingCallBack extends GroupingCallBack<T> { @Override public void onMatch(Record record1, Record record2, MatchResult matchResult) { if (!matchResult.isMatch()) { return; } RichRecord richRecord1 = (RichRecord) record1; RichRecord richRecord2 = (RichRecord) record2; richRecord1.setConfidence(richRecord1.getScore()); richRecord2.setConfidence(richRecord2.getScore()); String grpId1 = richRecord1.getGroupId(); String grpId2 = richRecord2.getGroupId(); String oldgrpId1 = richRecord1.getGID() == null ? null : richRecord1.getGID().getValue(); String oldgrpId2 = richRecord2.getGID() == null ? null : richRecord2.getGID().getValue(); uniqueOldGroupQuality(record1, record2); if (grpId1 == null && grpId2 == null) { richRecord1.setGroupId(oldgrpId1); richRecord2.setGroupId(oldgrpId1); richRecord1.setGrpSize(0); richRecord2.setGrpSize(0); richRecord1.setMaster(false); richRecord2.setMaster(false); oldGID2New.put(oldgrpId2, oldgrpId1); updateNotMasteredRecords(oldgrpId2, oldgrpId1); output(richRecord1); output(richRecord2); } else if (grpId1 != null && grpId2 != null) { richRecord2.setGroupId(grpId1); updateNotMasteredRecords(grpId2, grpId1); oldGID2New.put(grpId2, grpId1); List<String> keysOfGID2 = oldGID2New.getKeys(grpId2); if (keysOfGID2 != null) { for (String key : keysOfGID2) { oldGID2New.put(key, grpId1); } } } else if (grpId1 == null) { richRecord1.setGroupId(grpId2); oldGID2New.put(grpId2, oldgrpId1); updateNotMasteredRecords(oldgrpId1, grpId2); richRecord1.setGrpSize(0); richRecord1.setMaster(false); output(richRecord1); } else { richRecord2.setGroupId(richRecord1.getGroupId()); updateNotMasteredRecords(oldgrpId2, richRecord1.getGroupId()); oldGID2New.put(grpId2, oldgrpId1); richRecord2.setGrpSize(0); richRecord2.setMaster(false); output(richRecord2); } } MultiPassGroupingCallBack(BidiMultiMap oldGID2New, AbstractRecordGrouping<T> recordGrouping,
            Map<String, List<List<DQAttribute<?>>>> groupRows); @Override void onDifferent(Record record1, Record record2, MatchResult matchResult); @Override void onEndRecord(Record record); void setGIDindex(int index); int getIndexGID(); int getIndexGQ(); @Override void onMatch(Record record1, Record record2, MatchResult matchResult); @Override void onRemoveMerge(Record record); @Override void onNewMerge(Record record); @Override void onSynResult(Record newRecord, Record originalRecord, MatchResult matchResult);  }
@Test public void testOnMatchNotMatchCase() { MultiPassGroupingCallBack<Object> mPGroupingCallBack = new MultiPassGroupingCallBack<>(oldGID2New, recordGrouping, groupRows); RichRecord record1 = new RichRecord("id1", new Date().getTime(), "source1"); RichRecord record2 = new RichRecord("id2", new Date().getTime(), "source2"); record1.setScore(0.1); record2.setScore(0.2); MatchResult matchResult = new MatchResult(1); matchResult.setScore(2, AttributeMatcherType.EXACT, 0.5, "id1", "value1", "id2", "value2"); matchResult.setThreshold(2, 0.6f); mPGroupingCallBack.onMatch(record1, record2, matchResult); Assert.assertEquals("The size of listResult should be 0", 0, listResult.size()); Assert.assertEquals("The Confidence of record1 should be 1.0", "1.0", "" + record1.getConfidence()); Assert.assertEquals("The Confidence of record1 should be 0.1", "0.1", "" + record1.getScore()); Assert.assertEquals("The Confidence of record2 should be 1.0", "1.0", "" + record2.getConfidence()); Assert.assertEquals("The Confidence of record1 should be 0.2", "0.2", "" + record2.getScore()); }
@Test public void testOnMatchBothIdIsNull() { MultiPassGroupingCallBack<Object> mPGroupingCallBack = new MultiPassGroupingCallBack<>(oldGID2New, recordGrouping, groupRows); RichRecord record1 = new RichRecord("id1", new Date().getTime(), "source1"); RichRecord record2 = new RichRecord("id2", new Date().getTime(), "source2"); record1.setScore(0.1); record2.setScore(0.2); MatchResult matchResult = new MatchResult(1); record1.setGroupId(null); record2.setGroupId(null); matchResult = new MatchResult(1); record1.setRecordSize(1); record2.setRecordSize(1); List<DQAttribute<?>> originRow1 = initOriginRow("GID1", 2, true, 0.21, "0.9"); List<DQAttribute<?>> originRow2 = initOriginRow("GID2", 2, true, 0.22, "0.8"); record1.setOriginRow(originRow1); record2.setOriginRow(originRow2); groupRows.put("GID2", new ArrayList<List<DQAttribute<?>>>()); Assert.assertEquals("The size of groupRows should be 1", 1, groupRows.size()); mPGroupingCallBack.onMatch(record1, record2, matchResult); Assert.assertEquals("The size of listResult should be 2", 2, listResult.size()); Assert.assertEquals("The Confidence value of record1 should be 0.1", "0.1", "" + listResult.get(0).getConfidence()); Assert.assertNotNull("The groupid of record1 should not be null", listResult.get(0).getGroupId()); Assert.assertEquals("The group size of record1 should be 0", 0, listResult.get(0).getGrpSize()); Assert.assertFalse("The master of record1 should be false", listResult.get(0).isMaster()); Assert.assertEquals("The Confidence value of record2 should be 0.2", "0.2", "" + listResult.get(1).getConfidence()); Assert.assertNotNull("The groupid of record2 should not be null", listResult.get(1).getGroupId()); Assert.assertEquals("The group size of record2 should be 0", 0, listResult.get(1).getGrpSize()); Assert.assertFalse("The master of record2 should be false", listResult.get(1).isMaster()); Assert.assertEquals("The size of groupRows should be 1", 1, groupRows.size()); Assert.assertEquals("The size of oldGID2New should be 1", 1, oldGID2New.size()); Assert.assertEquals("The result of oldGID2New.get(\"GID2\") should be GID1", "GID1", oldGID2New.get("GID2")); Assert.assertNotNull("The GID1 attributes should not be null", groupRows.get("GID1")); }
@Test public void testOnMatchBothIdNotNull() { MultiPassGroupingCallBack<Object> mPGroupingCallBack = new MultiPassGroupingCallBack<>(oldGID2New, recordGrouping, groupRows); RichRecord record1 = new RichRecord("id1", new Date().getTime(), "source1"); RichRecord record2 = new RichRecord("id2", new Date().getTime(), "source2"); record1.setScore(0.1); record2.setScore(0.2); MatchResult matchResult = new MatchResult(1); listResult.clear(); groupRows.clear(); oldGID2New.clear(); record1 = new RichRecord("id1", new Date().getTime(), "source1"); record2 = new RichRecord("id2", new Date().getTime(), "source2"); record1.setGroupId("id1"); record2.setGroupId("id2"); record1.setScore(0.1); record2.setScore(0.2); matchResult = new MatchResult(1); List<DQAttribute<?>> originRow1 = initOriginRow("GID1", 2, true, 0.21, "0.9"); List<DQAttribute<?>> originRow2 = initOriginRow("GID2", 2, true, 0.22, "0.8"); record1.setRecordSize(1); record2.setRecordSize(1); originRow1 = initOriginRow("GID1", 2, true, 0.21, "0.8"); originRow2 = initOriginRow("GID2", 2, true, 0.22, "0.9"); record1.setOriginRow(originRow1); record2.setOriginRow(originRow2); oldGID2New.put("id3", "id2"); oldGID2New.put("id4", "id2"); oldGID2New.put("id5", "id2"); oldGID2New.put("id6", "id2"); groupRows.put("id1", new ArrayList<List<DQAttribute<?>>>()); groupRows.put("id2", new ArrayList<List<DQAttribute<?>>>()); Assert.assertEquals("The size of groupRows should be 2", 2, groupRows.size()); mPGroupingCallBack.onMatch(record1, record2, matchResult); Assert.assertEquals("The size of listResult should be 0", 0, listResult.size()); Assert.assertEquals("The Confidence value of record1 should be 0.1", "0.1", "" + record1.getConfidence()); Assert.assertEquals("The groupid of record1 should be id1", "id1", record1.getGroupId()); Assert.assertFalse("The master of record1 should be false", record1.isMaster()); Assert.assertEquals("The Confidence value of record2 should be 0.2", "0.2", "" + record2.getConfidence()); Assert.assertEquals("The groupid of record2 should be id1", "id1", record2.getGroupId()); Assert.assertFalse("The master of record2 should be false", record2.isMaster()); Assert.assertEquals("The size of oldGID2New should be 5", 5, oldGID2New.size()); Assert.assertEquals("The size of mapping to id1 should be 5", 5, oldGID2New.getKeys("id1").size()); Assert.assertEquals("The size of groupRows should be 1", 1, groupRows.size()); Assert.assertNotNull("The id1 attributes should not be null", groupRows.get("id1")); }
@Test public void testOnMatchOnlyOneIdIsNull() { MultiPassGroupingCallBack<Object> mPGroupingCallBack = new MultiPassGroupingCallBack<>(oldGID2New, recordGrouping, groupRows); RichRecord record1 = new RichRecord("id1", new Date().getTime(), "source1"); RichRecord record2 = new RichRecord("id2", new Date().getTime(), "source2"); record1.setScore(0.1); record2.setScore(0.2); MatchResult matchResult = new MatchResult(1); listResult.clear(); groupRows.clear(); oldGID2New.clear(); record1 = new RichRecord("id1", new Date().getTime(), "source1"); record2 = new RichRecord("id2", new Date().getTime(), "source2"); record2.setGroupId("id2"); record1.setGroupId(null); record1.setGrpSize(1); record1.setMaster(true); record1.setScore(0.3); record2.setScore(0.3); mPGroupingCallBack.onMatch(record1, record2, matchResult); Assert.assertEquals("The size of listResult should be 1", 1, listResult.size()); Assert.assertEquals("The Confidence value of record1 should be 0.3", "0.3", "" + listResult.get(0).getConfidence()); Assert.assertEquals("The groupid of record1 should be id2", "id2", listResult.get(0).getGroupId()); Assert.assertEquals("The group size of record1 should be 0", 0, listResult.get(0).getGrpSize()); Assert.assertFalse("The master of record1 should be false", listResult.get(0).isMaster()); listResult.clear(); groupRows.clear(); oldGID2New.clear(); record1 = new RichRecord("id1", new Date().getTime(), "source1"); record2 = new RichRecord("id2", new Date().getTime(), "source2"); record1.setGroupId("id1"); record2.setGroupId(null); record2.setGrpSize(1); record2.setMaster(true); record1.setScore(0.3); record2.setScore(0.3); mPGroupingCallBack.onMatch(record1, record2, matchResult); Assert.assertEquals("The size of listResult should be 1", 1, listResult.size()); Assert.assertEquals("The Confidence value of record1 should be 0.3", "0.3", "" + listResult.get(0).getConfidence()); Assert.assertEquals("The groupid of record2 should be id1", "id1", listResult.get(0).getGroupId()); Assert.assertEquals("The group size of record2 should be 0", 0, listResult.get(0).getGrpSize()); Assert.assertFalse("The master of record2 should be false", listResult.get(0).isMaster()); }