Merge pull request #2156 from jamesagnew/2155-Incorrect_EMPI_normalized_score_calculation
Fixed score calculation to use selected bits in the vector. Addresses…
This commit is contained in:
commit
382c0f2119
|
@ -26,6 +26,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
|
|||
* This data object captures the final outcome of an EMPI match
|
||||
*/
|
||||
public final class EmpiMatchOutcome {
|
||||
|
||||
public static final EmpiMatchOutcome POSSIBLE_DUPLICATE = new EmpiMatchOutcome(null, null).setMatchResultEnum(EmpiMatchResultEnum.POSSIBLE_DUPLICATE);
|
||||
public static final EmpiMatchOutcome NO_MATCH = new EmpiMatchOutcome(null, null).setMatchResultEnum(EmpiMatchResultEnum.NO_MATCH);
|
||||
public static final EmpiMatchOutcome NEW_PERSON_MATCH = new EmpiMatchOutcome(null, null).setMatchResultEnum(EmpiMatchResultEnum.MATCH).setNewPerson(true);
|
||||
|
@ -58,6 +59,11 @@ public final class EmpiMatchOutcome {
|
|||
*/
|
||||
private EmpiMatchResultEnum myMatchResultEnum;
|
||||
|
||||
/**
|
||||
* Total number of EMPI rules checked for this outcome
|
||||
*/
|
||||
private int myEmpiRuleCount;
|
||||
|
||||
public EmpiMatchOutcome(Long theVector, Double theScore) {
|
||||
vector = theVector;
|
||||
score = theScore;
|
||||
|
@ -99,6 +105,29 @@ public final class EmpiMatchOutcome {
|
|||
return myEidMatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of EMPI rules checked for this match outcome
|
||||
*
|
||||
* @param theEmpiRuleCount
|
||||
* Number of EMPI rules that were checked for this match outcome
|
||||
* @return
|
||||
* Returns this instance
|
||||
*/
|
||||
public EmpiMatchOutcome setEmpiRuleCount(int theEmpiRuleCount) {
|
||||
myEmpiRuleCount = theEmpiRuleCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of EMPI rules checked for this match outcome
|
||||
*
|
||||
* @return
|
||||
* Returns the number of rules
|
||||
*/
|
||||
public int getEmpiRuleCount() {
|
||||
return myEmpiRuleCount;
|
||||
}
|
||||
|
||||
/** @param theEidMatch the link was established via a shared EID */
|
||||
public EmpiMatchOutcome setEidMatch(boolean theEidMatch) {
|
||||
myEidMatch = theEidMatch;
|
||||
|
@ -112,17 +141,10 @@ public final class EmpiMatchOutcome {
|
|||
* Returns the normalized score
|
||||
*/
|
||||
public Double getNormalizedScore() {
|
||||
if (vector == 0) {
|
||||
if (myEmpiRuleCount == 0) {
|
||||
return 0.0;
|
||||
} else if (score > vector) {
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
double retVal = score / vector;
|
||||
if (retVal < 0) {
|
||||
retVal = 0.0;
|
||||
}
|
||||
return retVal;
|
||||
return score / myEmpiRuleCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -125,6 +125,9 @@ public class EmpiResourceMatcherSvc {
|
|||
}
|
||||
score += matchEvaluation.score;
|
||||
}
|
||||
return new EmpiMatchOutcome(vector, score);
|
||||
|
||||
EmpiMatchOutcome retVal = new EmpiMatchOutcome(vector, score);
|
||||
retVal.setEmpiRuleCount(myFieldMatchers.size());
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,22 +6,20 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||
|
||||
class EmpiMatchOutcomeTest {
|
||||
|
||||
public static final double DELTA = 0.0001;
|
||||
|
||||
@Test
|
||||
void testNormalizedScore() {
|
||||
EmpiMatchOutcome outcome = new EmpiMatchOutcome(0l, 0.0);
|
||||
assertEquals(0.0, outcome.getNormalizedScore());
|
||||
|
||||
outcome = new EmpiMatchOutcome(10l, 10.0);
|
||||
assertEquals(1.0, outcome.getNormalizedScore());
|
||||
outcome = new EmpiMatchOutcome(null, 10.0);
|
||||
outcome.setEmpiRuleCount(10);
|
||||
assertEquals(1.0, outcome.getNormalizedScore(), DELTA);
|
||||
|
||||
outcome = new EmpiMatchOutcome(10l, -10.0);
|
||||
assertEquals(0.0, outcome.getNormalizedScore());
|
||||
|
||||
outcome = new EmpiMatchOutcome(3l, 2.0);
|
||||
assertEquals(2.0 / 3.0, outcome.getNormalizedScore(), 0.0001);
|
||||
|
||||
outcome = new EmpiMatchOutcome(5l, 19.0);
|
||||
assertEquals(1.0, outcome.getNormalizedScore());
|
||||
outcome = new EmpiMatchOutcome(null, 2.0);
|
||||
outcome.setEmpiRuleCount(3);
|
||||
assertEquals(2.0 / 3.0, outcome.getNormalizedScore(), DELTA);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue