Skip to content

Commit b72a68d

Browse files
committed
Fix sorting of stats list
1 parent b8d4ed5 commit b72a68d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>clockvapor.telegram.markov-telegram-bot</groupId>
99
<artifactId>markov-telegram-bot</artifactId>
10-
<version>0.2.2</version>
10+
<version>0.2.3</version>
1111

1212
<properties>
1313
<kotlin.version>1.3.21</kotlin.version>

src/main/kotlin/clockvapor/telegram/markov/Utils.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ fun scoreMostDistinguishingWords(user: Map<String, Int>, universe: Map<String, I
2121
val userTotal = user.values.sum()
2222
val universeTotal = universe.values.sum()
2323
for ((word, count) in user) {
24-
scores[word] = Math.pow(count.toDouble(), 1.1) / userTotal * (universeTotal / universe.getValue(word))
24+
scores[word] = Math.pow(count.toDouble(), 1.1) / userTotal / (universe.getValue(word).toDouble() / universeTotal)
2525
}
26-
return scores.toList().sortedByDescending { it.second }.toMap()
26+
return scores.toList().sortedWith(Comparator { a, b ->
27+
val c = b.second.compareTo(a.second)
28+
if (c == 0)
29+
a.first.compareTo(b.first)
30+
else
31+
c
32+
}).toMap()
2733
}
2834

2935
fun computeUniverse(wordCountsCollection: Collection<Map<String, Int>>): Map<String, Int> {

0 commit comments

Comments
 (0)