-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compute confidence for composite correlators
Also, the concept of correlator authority was replaced by correlator tiers. The dependencies between correlators are now checked thoroughly. Work in progress.
- Loading branch information
Showing
21 changed files
with
589 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
model/model-api/src/main/java/com/evolveum/midpoint/model/api/correlator/CandidateOwner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2010-2022 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.model.api.correlator; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import com.evolveum.midpoint.util.MiscUtil; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; | ||
|
||
/** | ||
* Equals/hashCode contract: looks after {@link #oid} and {@link #confidence} only. | ||
*/ | ||
public class CandidateOwner<O extends ObjectType> implements Serializable { | ||
|
||
@NotNull private final String oid; | ||
@NotNull private final O object; | ||
private Double confidence; | ||
|
||
CandidateOwner(@NotNull O object, Double confidence) { | ||
this.oid = MiscUtil.requireNonNull( | ||
object.getOid(), | ||
() -> new IllegalArgumentException("No oid of " + object)); | ||
this.object = object; | ||
this.confidence = confidence; | ||
} | ||
|
||
public @NotNull String getOid() { | ||
return oid; | ||
} | ||
|
||
public @NotNull O getObject() { | ||
return object; | ||
} | ||
|
||
public Double getConfidence() { | ||
return confidence; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CandidateOwner{" + | ||
"object=" + object + | ||
", confidence=" + confidence + | ||
'}'; | ||
} | ||
|
||
Double addMatching(CandidateOwner<O> another) { | ||
assert oid.equals(another.getOid()); | ||
Double anotherConfidence = another.getConfidence(); | ||
if (anotherConfidence != null) { | ||
if (confidence == null) { | ||
confidence = anotherConfidence; | ||
} else { | ||
confidence += anotherConfidence; | ||
} | ||
} | ||
return confidence; | ||
} | ||
|
||
public boolean isAtLeast(double threshold) { | ||
return threshold <= 0 | ||
|| confidence != null && confidence >= threshold; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
CandidateOwner<?> that = (CandidateOwner<?>) o; | ||
return oid.equals(that.oid) && Objects.equals(confidence, that.confidence); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(oid, confidence); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...model-api/src/main/java/com/evolveum/midpoint/model/api/correlator/CandidateOwnerMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2010-2022 Evolveum and contributors | ||
* | ||
* This work is dual-licensed under the Apache License 2.0 | ||
* and European Union Public License. See LICENSE file for details. | ||
*/ | ||
|
||
package com.evolveum.midpoint.model.api.correlator; | ||
|
||
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.Serializable; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class CandidateOwnerMap<O extends ObjectType> implements Serializable { | ||
|
||
@NotNull private final Map<String, CandidateOwner<O>> map = new HashMap<>(); | ||
|
||
public static <O extends ObjectType> CandidateOwnerMap<O> from(Collection<CandidateOwner<O>> source) { | ||
CandidateOwnerMap<O> map = new CandidateOwnerMap<>(); | ||
source.forEach(map::put); | ||
return map; | ||
} | ||
|
||
public void put(@NotNull O candidate, @Nullable Double confidence) { | ||
put(new CandidateOwner<>(candidate, confidence)); | ||
} | ||
|
||
public void put(@NotNull CandidateOwner<O> candidateOwner) { | ||
map.put(candidateOwner.getOid(), candidateOwner); | ||
} | ||
|
||
public @NotNull Collection<CandidateOwner<O>> values() { | ||
return map.values(); | ||
} | ||
|
||
public Double add(CandidateOwner<O> candidateOwner) { | ||
CandidateOwner<O> existing = map.get(candidateOwner.getOid()); | ||
if (existing != null) { | ||
return existing.addMatching(candidateOwner); | ||
} else { | ||
put(candidateOwner); | ||
return candidateOwner.getConfidence(); | ||
} | ||
} | ||
|
||
public @NotNull CandidateOwnerMap<O> copyAtLeast(double threshold) { | ||
CandidateOwnerMap<O> targetMap = new CandidateOwnerMap<>(); | ||
for (CandidateOwner<O> value : values()) { | ||
if (value.isAtLeast(threshold)) { | ||
targetMap.put(value); | ||
} | ||
} | ||
return targetMap; | ||
} | ||
|
||
public Collection<CandidateOwner<O>> selectWithConfidenceAtLeast(double threshold) { | ||
return map.values().stream() | ||
.filter(candidateOwner -> candidateOwner.isAtLeast(threshold)) | ||
.collect(Collectors.toSet()); | ||
} | ||
} |
Oops, something went wrong.