Update FeatureManager API
authorVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Tue, 12 Dec 2017 14:12:39 +0000 (17:12 +0300)
committerVitaliy.Bibaev <vitaliy.bibaev@jetbrains.com>
Tue, 12 Dec 2017 14:12:39 +0000 (17:12 +0300)
plugins/stats-collector/src/com/intellij/completion/FeatureManager.kt
plugins/stats-collector/src/com/intellij/completion/FeatureManagerImpl.kt

index 36c06fbebcc8a5dc7e042eb02a8cf15a02bc77e2..11e1ac2b53a57ae27beee0e0db25c680bec5f238 100644 (file)
@@ -1,24 +1,21 @@
 package com.intellij.completion
 
 import com.intellij.openapi.application.ApplicationManager
-import com.jetbrains.completion.ranker.features.BinaryFeatureInfo
-import com.jetbrains.completion.ranker.features.CategoricalFeatureInfo
-import com.jetbrains.completion.ranker.features.CompletionFactors
-import com.jetbrains.completion.ranker.features.DoubleFeatureInfo
+import com.jetbrains.completion.ranker.features.*
 
 /**
  * @author Vitaliy.Bibaev
  */
 interface FeatureManager {
-    val featuresOrder: Map<String, Int>
-    val binaryFactors: BinaryFeatureInfo
-    val doubleFactors: DoubleFeatureInfo
-    val categorialFactors: CategoricalFeatureInfo
+    val binaryFactors: List<BinaryFeature>
+    val doubleFactors: List<DoubleFeature>
+    val categorialFactors: List<CatergorialFeature>
     val ignoredFactors: Set<String>
 
-    val allFeatures: CompletionFactors
+    val completionFactors: CompletionFactors
 
     fun isUserFeature(name: String): Boolean
+    fun allFeatures(): List<Feature>
 
     companion object {
         fun getInstance(): FeatureManager = ApplicationManager.getApplication().getComponent(FeatureManager::class.java)
index c9036bd04fd318e94d075aba7fda0ac61ab4423b..e4b75943689ddf1227423d445489b2b13dc183ea 100644 (file)
@@ -7,21 +7,35 @@ import com.jetbrains.completion.ranker.features.*
  * @author Vitaliy.Bibaev
  */
 class FeatureManagerImpl : FeatureManager, ApplicationComponent {
-    override lateinit var binaryFactors: BinaryFeatureInfo private set
-    override lateinit var doubleFactors: DoubleFeatureInfo private set
-    override lateinit var categorialFactors: CategoricalFeatureInfo private set
-    override lateinit var allFeatures: CompletionFactors private set
-    override lateinit var featuresOrder: Map<String, Int> private set
+    override lateinit var binaryFactors: List<BinaryFeature> private set
+    override lateinit var doubleFactors: List<DoubleFeature> private set
+    override lateinit var categorialFactors: List<CatergorialFeature> private set
+    override lateinit var completionFactors: CompletionFactors private set
     override lateinit var ignoredFactors: Set<String> private set
+    private lateinit var allFeatures: List<Feature>
 
     override fun isUserFeature(name: String): Boolean = false
 
     override fun initComponent() {
+        val order = FeatureReader.featuresOrder()
+        val interpreter = FeatureInterpreterImpl()
+
         binaryFactors = FeatureReader.binaryFactors()
+                .map { (name, description) -> interpreter.binary(name, description, order) }
         doubleFactors = FeatureReader.doubleFactors()
-        allFeatures = FeatureReader.completionFactors()
+                .map { (name, defaultValue) -> interpreter.double(name, defaultValue, order) }
         categorialFactors = FeatureReader.categoricalFactors()
-        featuresOrder = FeatureReader.featuresOrder()
+                .map { (name, categories) -> interpreter.categorial(name, categories, order) }
+
+        completionFactors = FeatureReader.completionFactors()
+
         ignoredFactors = FeatureReader.ignoredFactors()
+
+        val features: ArrayList<Feature> = ArrayList(binaryFactors)
+        features.addAll(doubleFactors)
+        features.addAll(categorialFactors)
+        allFeatures = features
     }
+
+    override fun allFeatures(): List<Feature> = allFeatures
 }
\ No newline at end of file