Add and use new feature transformer (excl. tests)
authorVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Tue, 12 Dec 2017 21:59:57 +0000 (00:59 +0300)
committerVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Tue, 12 Dec 2017 21:59:57 +0000 (00:59 +0300)
plugins/stats-collector/src/com/intellij/completion/FeatureManager.kt
plugins/stats-collector/src/com/intellij/completion/FeatureManagerImpl.kt
plugins/stats-collector/src/com/intellij/sorting/MLCompletionSorter.kt

index 11e1ac2b53a57ae27beee0e0db25c680bec5f238..6808f19be9b7f9670f928c61196c8bdbf929aa68 100644 (file)
@@ -13,6 +13,7 @@ interface FeatureManager {
     val ignoredFactors: Set<String>
 
     val completionFactors: CompletionFactors
+    val featureArrayLength: Int
 
     fun isUserFeature(name: String): Boolean
     fun allFeatures(): List<Feature>
index e4b75943689ddf1227423d445489b2b13dc183ea..e27c0a1c90aaf6e137fda21712b3eb5c2a154661 100644 (file)
@@ -7,6 +7,8 @@ import com.jetbrains.completion.ranker.features.*
  * @author Vitaliy.Bibaev
  */
 class FeatureManagerImpl : FeatureManager, ApplicationComponent {
+    private var arrayLength = 0
+
     override lateinit var binaryFactors: List<BinaryFeature> private set
     override lateinit var doubleFactors: List<DoubleFeature> private set
     override lateinit var categorialFactors: List<CatergorialFeature> private set
@@ -14,6 +16,9 @@ class FeatureManagerImpl : FeatureManager, ApplicationComponent {
     override lateinit var ignoredFactors: Set<String> private set
     private lateinit var allFeatures: List<Feature>
 
+    override val featureArrayLength: Int
+        get() = arrayLength
+
     override fun isUserFeature(name: String): Boolean = false
 
     override fun initComponent() {
@@ -31,6 +36,7 @@ class FeatureManagerImpl : FeatureManager, ApplicationComponent {
 
         ignoredFactors = FeatureReader.ignoredFactors()
 
+        arrayLength = order.size
         val features: ArrayList<Feature> = ArrayList(binaryFactors)
         features.addAll(doubleFactors)
         features.addAll(categorialFactors)
index 7b85599752327eddd3d431edc9db0a67a790f1b0..799ea7b373d65fb2040526d778197a66cb1e3ffb 100644 (file)
  */
 package com.intellij.sorting
 
+import com.intellij.completion.FeatureManager
 import com.intellij.openapi.components.ApplicationComponent
 import com.intellij.openapi.components.ServiceManager
 import com.jetbrains.completion.ranker.CompletionRanker
-import com.jetbrains.completion.ranker.features.FeatureReader.binaryFactors
-import com.jetbrains.completion.ranker.features.FeatureReader.categoricalFactors
-import com.jetbrains.completion.ranker.features.FeatureReader.completionFactors
-import com.jetbrains.completion.ranker.features.FeatureReader.doubleFactors
-import com.jetbrains.completion.ranker.features.FeatureReader.featuresOrder
-import com.jetbrains.completion.ranker.features.FeatureReader.ignoredFactors
-import com.jetbrains.completion.ranker.features.FeatureTransformer
-import com.jetbrains.completion.ranker.features.IgnoredFactorsMatcher
+import com.jetbrains.completion.ranker.features.NewFeatureTransformer
 import com.jetbrains.completion.ranker.features.Transformer
 
 
@@ -49,27 +43,14 @@ class FeatureTransformerProvider : ApplicationComponent.Adapter() {
         private set
 
     override fun initComponent() {
-        val binary = binaryFactors()
-        val double = doubleFactors()
-        val categorical = categoricalFactors()
-        val factors = completionFactors()
-        val order = featuresOrder()
-        val ignored = ignoredFactors()
-//        featureTransformer = NewFeatureTransformer(FeatureManager.getInstance().allFeatures().associate { it.name to it })
-
-        featureTransformer = FeatureTransformer(
-                binary,
-                double,
-                categorical,
-                order,
-                factors,
-                IgnoredFactorsMatcher(ignored)
-        )
+        val featureManager = FeatureManager.getInstance()
+        val factors = featureManager.completionFactors
+        val ignored = featureManager.ignoredFactors
+        val features = featureManager.allFeatures().associate { it.name to it }
+        featureTransformer = NewFeatureTransformer(features, ignored, factors, featureManager.featureArrayLength)
     }
-
 }
 
-
 class MLRanker(val provider: FeatureTransformerProvider) : Ranker {
 
     private val featureTransformer = provider.featureTransformer