This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-41
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-41 by this push:
new 8c60679 WIP.
8c60679 is described below
commit 8c60679164825ad2b9564790809876cc4f7f276c
Author: Sergey Kamov <[email protected]>
AuthorDate: Sun Jun 14 15:13:47 2020 +0300
WIP.
---
.../tools/suggestions/NCSuggestionsGenerator.scala | 31 +++++++---------------
1 file changed, 9 insertions(+), 22 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/suggestions/NCSuggestionsGenerator.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/suggestions/NCSuggestionsGenerator.scala
index 5e03016..0c2aae6 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/suggestions/NCSuggestionsGenerator.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/suggestions/NCSuggestionsGenerator.scala
@@ -234,9 +234,6 @@ object NCSuggestionsGeneratorImpl {
val nonEmptySuggs = allSuggs.asScala.map(p ⇒ p._1 →
p._2.asScala).filter(_._2.nonEmpty)
- val avgScores = nonEmptySuggs.map { case (elemId, suggs) ⇒ elemId →
(suggs.map(_.score).sum / suggs.size) }
- val counts = nonEmptySuggs.map { case (elemId, suggs) ⇒ elemId →
suggs.size }
-
val tbl = NCAsciiTable()
tbl #= (
@@ -249,7 +246,7 @@ object NCSuggestionsGeneratorImpl {
nonEmptySuggs.
foreach { case (elemId, elemSuggs) ⇒
- val seq: Seq[(Suggestion, Int)] = elemSuggs.
+ elemSuggs.
map(sugg ⇒ (sugg, toStem(sugg.word))).
groupBy { case (_, stem) ⇒ stem }.
filter { case (stem, _) ⇒ !allSynsStems.contains(stem) }.
@@ -259,24 +256,14 @@ object NCSuggestionsGeneratorImpl {
// Drops repeated.
(seq.head, seq.length)
}.
- toSeq
-
- val normFactor = seq.map(_._2).sum.toDouble / seq.size /
avgScores(elemId)
-
- seq.
- map { case (sugg, cnt) ⇒ (sugg, cnt, sugg.score *
normFactor * cnt.toDouble / counts(elemId)) }.
- sortBy { case (_, _, cumFactor) ⇒ -cumFactor }.
+ toSeq.
+ map { case (sugg, cnt) ⇒ (sugg, cnt, sugg.score * cnt /
elemSuggs.size) }.
+ sortBy { case (_, _, sumFactor) ⇒ -sumFactor }.
zipWithIndex.
- foreach { case ((sugg, cnt, cumFactor), sugIdx) ⇒
- def f(d: Double): String = "%1.3f" format d
-
- tbl += (
- if (sugIdx == 0) elemId else " ",
- sugg.word,
- f(sugg.score),
- cnt,
- f(cumFactor)
- )
+ foreach { case ((sugg, cnt, sumFactor), sugIdx) ⇒
+ def f(d: Double): String = "%1.5f" format d
+
+ tbl += (if (sugIdx == 0) elemId else "", sugg.word,
f(sugg.score), cnt, f(sumFactor))
}
}
@@ -310,7 +297,7 @@ object NCSuggestionsGeneratorImpl {
object NCSuggestionsGenerator extends App {
private lazy val DFLT_URL: String = "http://localhost:5000/suggestions"
- private lazy val DFLT_LIMIT: Int = 10
+ private lazy val DFLT_LIMIT: Int = 20
private lazy val DFLT_MIN_SCORE: Double = 0
private lazy val DFLT_DEBUG: Boolean = false