change if to match

This commit is contained in:
denon1 2023-04-01 14:27:05 +02:00
parent ec83d01dca
commit e1691d5f25

View File

@ -120,15 +120,15 @@ object UpdateKnownFor {
clusterScoresToFinalScore: ClusterScoresForNode => Double, clusterScoresToFinalScore: ClusterScoresForNode => Double,
minNeighborsInCluster: Int minNeighborsInCluster: Int
): Option[(Int, Double)] = { ): Option[(Int, Double)] = {
val clusterToScores = statsOfClustersInNeighborhood.toList.flatMap { statsOfClustersInNeighborhood
.toList
.flatMap {
case (clusterId, statsInNeighborhood) => case (clusterId, statsInNeighborhood) =>
val clusterOverallStats = clusterOverallStatsMap(clusterId) val clusterOverallStats = clusterOverallStatsMap(clusterId)
if (statsInNeighborhood.nodeCount >= minNeighborsInCluster) { statsInNeighborhood match {
Some( case statsInNeighborhood if statsInNeighborhood.nodeCount < minNeighborsInCluster => None
( case _ =>
clusterId, val score = getScoresForCluster(
clusterScoresToFinalScore(
getScoresForCluster(
overallNeighborhoodStats, overallNeighborhoodStats,
statsInNeighborhood, statsInNeighborhood,
clusterOverallStats.nodeCount, clusterOverallStats.nodeCount,
@ -136,16 +136,12 @@ object UpdateKnownFor {
globalAvgEdgeWeight, globalAvgEdgeWeight,
truePositiveWtFactor truePositiveWtFactor
) )
) Some((clusterId, clusterScoresToFinalScore(score)))
)
)
} else {
None
} }
} match {
case scores if scores.isEmpty => None
case _ => Some(clusterToScores.maxBy(_._2))
} }
if (clusterToScores.nonEmpty) {
Some(clusterToScores.maxBy(_._2))
} else None
} }
def updateGeneric( def updateGeneric(
@ -170,10 +166,11 @@ object UpdateKnownFor {
collectInformationPerNode(graph, inputUserToClusters, avgMembershipScore) collectInformationPerNode(graph, inputUserToClusters, avgMembershipScore)
.mapValues { .mapValues {
case NodeInformation(originalClusters, overallStats, statsOfClustersInNeighborhood) => case NodeInformation(originalClusters, overallStats, statsOfClustersInNeighborhood) =>
val newClusterWithScoreOpt = if (overallStats.nodeCount < minNeighborsInCluster) { overallStats match {
case stats if (overallStats.nodeCount < minNeighborsInCluster) =>
nodesWithSmallDegree.inc() nodesWithSmallDegree.inc()
None None
} else { case _ =>
pickBestCluster( pickBestCluster(
overallStats, overallStats,
statsOfClustersInNeighborhood, statsOfClustersInNeighborhood,
@ -183,22 +180,18 @@ object UpdateKnownFor {
clusterScoresToFinalScore, clusterScoresToFinalScore,
minNeighborsInCluster minNeighborsInCluster
) )
} } match {
newClusterWithScoreOpt match {
case Some((newClusterId, score)) => case Some((newClusterId, score)) =>
if (originalClusters.isEmpty) { originalClusters match {
emptyToSomething.inc() case cluster if cluster.isEmpty => emptyToSomething.inc()
} else if (originalClusters.contains(newClusterId)) { case cluster if cluster.contains(newClusterId) => sameCluster.inc()
sameCluster.inc() case _ => diffCluster.inc()
} else {
diffCluster.inc()
} }
Array((newClusterId, score.toFloat)) Array((newClusterId, score.toFloat))
case None => case None =>
if (originalClusters.isEmpty) { originalClusters match {
emptyToEmpty.inc() case cluster if cluster.isEmpty => emptyToEmpty.inc()
} else { case _ => somethingToEmpty.inc()
somethingToEmpty.inc()
} }
Array.empty[(Int, Float)] Array.empty[(Int, Float)]
} }