Skip to content

Commit

Permalink
Fix sorting of stats list
Browse files Browse the repository at this point in the history
  • Loading branch information
ClockVapor committed Apr 1, 2019
1 parent b8d4ed5 commit b72a68d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>clockvapor.telegram.markov-telegram-bot</groupId>
<artifactId>markov-telegram-bot</artifactId>
<version>0.2.2</version>
<version>0.2.3</version>

<properties>
<kotlin.version>1.3.21</kotlin.version>
Expand Down
10 changes: 8 additions & 2 deletions src/main/kotlin/clockvapor/telegram/markov/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ fun scoreMostDistinguishingWords(user: Map<String, Int>, universe: Map<String, I
val userTotal = user.values.sum()
val universeTotal = universe.values.sum()
for ((word, count) in user) {
scores[word] = Math.pow(count.toDouble(), 1.1) / userTotal * (universeTotal / universe.getValue(word))
scores[word] = Math.pow(count.toDouble(), 1.1) / userTotal / (universe.getValue(word).toDouble() / universeTotal)
}
return scores.toList().sortedByDescending { it.second }.toMap()
return scores.toList().sortedWith(Comparator { a, b ->
val c = b.second.compareTo(a.second)
if (c == 0)
a.first.compareTo(b.first)
else
c
}).toMap()
}

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

0 comments on commit b72a68d

Please sign in to comment.