mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[stats-collector] Preprocess relevance factors before logging
GitOrigin-RevId: 14c2468605dbe6c0ae87e52fcb24123c85b978d5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8023c067d2
commit
d34b8a6f3b
-36
@@ -31,40 +31,4 @@ object FeatureUtils {
|
||||
|
||||
fun getOtherCategoryFeatureName(name: String): String = "$name=$OTHER"
|
||||
fun getUndefinedFeatureName(name: String): String = "$name=$UNDEFINED"
|
||||
|
||||
fun asRelevanceMap(relevanceObjects: List<Pair<String, Any?>>): MutableMap<String, Any> {
|
||||
val relevanceMap = mutableMapOf<String, Any>()
|
||||
for (pair in relevanceObjects) {
|
||||
val name = pair.first.normalized()
|
||||
val value = pair.second
|
||||
if (value == null) continue
|
||||
if (name == "proximity") {
|
||||
val proximityMap = value.toString().asProximityMap("prox")
|
||||
relevanceMap.putAll(proximityMap)
|
||||
}
|
||||
else {
|
||||
relevanceMap[name] = value
|
||||
}
|
||||
}
|
||||
|
||||
return relevanceMap
|
||||
}
|
||||
|
||||
fun normalizeFeatureName(name: String): String = name.normalized()
|
||||
|
||||
private fun String.normalized(): String {
|
||||
return substringBefore('@')
|
||||
}
|
||||
|
||||
/**
|
||||
* Proximity features now came like [samePsiFile=true, openedInEditor=false], need to convert to proper map
|
||||
*/
|
||||
private fun String.asProximityMap(prefix: String): Map<String, Any> {
|
||||
val items = this.replace("[", "").replace("]", "").split(",")
|
||||
|
||||
return items.map {
|
||||
val (key, value) = it.trim().split("=")
|
||||
"${prefix}_$key" to value
|
||||
}.toMap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.intellij.openapi.util.Pair
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.psi.util.PsiUtilCore
|
||||
import com.intellij.stats.completion.CompletionUtil
|
||||
import com.intellij.stats.completion.RelevanceUtil
|
||||
import com.intellij.stats.completion.prefixLength
|
||||
import com.intellij.stats.experiment.EmulatedExperiment
|
||||
import com.intellij.stats.experiment.WebServiceStatus
|
||||
@@ -109,7 +110,7 @@ class MLSorter : CompletionFinalSorter() {
|
||||
return items
|
||||
.mapIndexed { position, lookupElement ->
|
||||
positionsBefore[lookupElement] = position
|
||||
val relevance = buildRelevanceMap(lookupElement, relevanceObjects[lookupElement]?.map { it.first to it.second },
|
||||
val relevance = buildRelevanceMap(lookupElement, relevanceObjects[lookupElement],
|
||||
lookup.prefixLength(), position, parameters) ?: return null
|
||||
val rank: Double = calculateElementRank(ranker, lookupElement, position, relevance, userFactors, prefixLength) ?: return null
|
||||
|
||||
@@ -121,13 +122,13 @@ class MLSorter : CompletionFinalSorter() {
|
||||
}
|
||||
|
||||
private fun buildRelevanceMap(lookupElement: LookupElement,
|
||||
relevanceObjects: List<kotlin.Pair<String, Any?>>?,
|
||||
relevanceObjects: List<Pair<String, Any?>>?,
|
||||
prefixLength: Int,
|
||||
position: Int,
|
||||
parameters: CompletionParameters): Map<String, Any>? {
|
||||
if (relevanceObjects == null) return null
|
||||
|
||||
val relevanceMap = FeatureUtils.asRelevanceMap(relevanceObjects)
|
||||
val relevanceMap = RelevanceUtil.asRelevanceMap(relevanceObjects)
|
||||
|
||||
relevanceMap["position"] = position
|
||||
relevanceMap["query_length"] = prefixLength
|
||||
|
||||
@@ -71,10 +71,11 @@ class LookupStateManager {
|
||||
|
||||
private fun List<LookupElement>.toLookupInfos(lookup: LookupImpl): List<LookupEntryInfo> {
|
||||
val relevanceObjects = lookup.getRelevanceObjects(this, false)
|
||||
return this.map {
|
||||
val id = getElementId(it)!!
|
||||
val relevanceMap = relevanceObjects[it]?.associate { p -> FeatureUtils.normalizeFeatureName(p.first) to p.second?.toString() }
|
||||
LookupEntryInfo(id, it.lookupString.length, relevanceMap)
|
||||
return this.map { lookupElement ->
|
||||
val relevanceMap = relevanceObjects[lookupElement]?.let { objects ->
|
||||
RelevanceUtil.asRelevanceMap(objects).mapValues { entry -> entry.value.toString() }
|
||||
}
|
||||
LookupEntryInfo(getElementId(lookupElement)!!, lookupElement.lookupString.length, relevanceMap)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.intellij.stats.completion
|
||||
|
||||
object RelevanceUtil {
|
||||
fun asRelevanceMap(relevanceObjects: List<com.intellij.openapi.util.Pair<String, Any?>>): MutableMap<String, Any> {
|
||||
val relevanceMap = mutableMapOf<String, Any>()
|
||||
for (pair in relevanceObjects) {
|
||||
val name = pair.first.normalized()
|
||||
val value = pair.second
|
||||
if (value == null) continue
|
||||
if (name == "proximity") {
|
||||
val proximityMap = value.toString().asProximityMap("prox")
|
||||
relevanceMap.putAll(proximityMap)
|
||||
}
|
||||
else {
|
||||
relevanceMap[name] = value
|
||||
}
|
||||
}
|
||||
|
||||
return relevanceMap
|
||||
}
|
||||
|
||||
private fun String.normalized(): String {
|
||||
return substringBefore('@')
|
||||
}
|
||||
|
||||
/**
|
||||
* Proximity features now came like [samePsiFile=true, openedInEditor=false], need to convert to proper map
|
||||
*/
|
||||
private fun String.asProximityMap(prefix: String): Map<String, Any> {
|
||||
val items = this.replace("[", "").replace("]", "").split(",")
|
||||
|
||||
return items.map {
|
||||
val (key, value) = it.trim().split("=")
|
||||
"${prefix}_$key" to value
|
||||
}.toMap()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user