Use the new feature transformer in tests
authorVitaliy Bibaev <roenke54@gmail.com>
Wed, 13 Dec 2017 10:13:16 +0000 (13:13 +0300)
committerVitaliy Bibaev <roenke54@gmail.com>
Wed, 13 Dec 2017 10:13:16 +0000 (13:13 +0300)
plugins/stats-collector/src/com/intellij/completion/FeatureManagerImpl.kt
plugins/stats-collector/src/com/intellij/sorting/MLCompletionSorter.kt

index 1f292910c36ade7709853769576fba0609e09f4c..9f590d0c167dae9ec7e957faf70498f84b279630 100644 (file)
@@ -12,41 +12,24 @@ class FeatureManagerImpl : FeatureManager, ApplicationComponent {
         fun getInstance(): FeatureManager = ApplicationManager.getApplication().getComponent(FeatureManager::class.java)
     }
 
-    private var arrayLength = 0
+    private lateinit var manager: FeatureManager
 
-    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 val binaryFactors: List<BinaryFeature> get() = manager.binaryFactors
+    override val doubleFactors: List<DoubleFeature> get() = manager.doubleFactors
+    override val categorialFactors: List<CatergorialFeature> get() = manager.categorialFactors
+    override val ignoredFactors: Set<String> get() = manager.ignoredFactors
+    override val completionFactors: CompletionFactors get() = manager.completionFactors
+    override val featureOrder: Map<String, Int> get() = manager.featureOrder
 
-    override val featureArrayLength: Int
-        get() = arrayLength
+    override fun createTransformer(): Transformer {
+        return manager.createTransformer()
+    }
 
     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()
-                .map { (name, defaultValue) -> interpreter.double(name, defaultValue, order) }
-        categorialFactors = FeatureReader.categoricalFactors()
-                .map { (name, categories) -> interpreter.categorial(name, categories, order) }
-
-        completionFactors = FeatureReader.completionFactors()
-
-        ignoredFactors = FeatureReader.ignoredFactors()
-
-        arrayLength = order.size
-        val features: ArrayList<Feature> = ArrayList(binaryFactors)
-        features.addAll(doubleFactors)
-        features.addAll(categorialFactors)
-        allFeatures = features
+        manager = FeatureManagerFactory().createFeatureManager(FeatureReader, FeatureInterpreterImpl())
     }
 
-    override fun allFeatures(): List<Feature> = allFeatures
+    override fun allFeatures(): List<Feature> = manager.allFeatures()
 }
\ No newline at end of file
index 95af869c088abd68f627ae805c7ac3f95c1f1da9..8502d801bb727576f0118717183f4b67651c94d2 100644 (file)
@@ -38,15 +38,7 @@ interface Ranker {
 
 
 class FeatureTransformerProvider(featureManager: FeatureManager) : ApplicationComponent.Adapter() {
-
-    val featureTransformer: Transformer
-
-    init {
-        val factors = featureManager.completionFactors
-        val ignored = featureManager.ignoredFactors
-        val features = featureManager.allFeatures().associate { it.name to it }
-        featureTransformer = NewFeatureTransformer(features, ignored, factors, featureManager.featureArrayLength)
-    }
+    val featureTransformer: Transformer = featureManager.createTransformer()
 }
 
 class MLRanker(val provider: FeatureTransformerProvider) : Ranker {