jenkins-bot has submitted this change and it was merged.

Change subject: Factor out Cache::$classMap into $wgOresModelClasses
......................................................................


Factor out Cache::$classMap into $wgOresModelClasses

This makes the class mapping configurable and makes it
possible to have different mappings for different models.

Change-Id: Ided72fb3241411a0ace3c8cbea99ef4e7c8bb4c0
---
M extension.json
M includes/Cache.php
2 files changed, 32 insertions(+), 5 deletions(-)

Approvals:
  Ladsgroup: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index 358ee3a..eb096bc 100644
--- a/extension.json
+++ b/extension.json
@@ -90,6 +90,28 @@
                        "reverted": true,
                        "wp10": true
                },
+               "OresModelClasses": {
+                       "damaging": {
+                               "false": 0,
+                               "true": 1
+                       },
+                       "goodfaith": {
+                               "false": 0,
+                               "true": 1
+                       },
+                       "reverted": {
+                               "false": 0,
+                               "true": 1
+                       },
+                       "wp10": {
+                               "B": 0,
+                               "C": 1,
+                               "FA": 2,
+                               "GA": 3,
+                               "Start": 4,
+                               "Stub": 5
+                       }
+               },
                "OresDamagingThresholds": {
                        "soft": 0.70,
                        "hard": 0.50
diff --git a/includes/Cache.php b/includes/Cache.php
index 52f7c61..baccb45 100644
--- a/includes/Cache.php
+++ b/includes/Cache.php
@@ -6,13 +6,9 @@
 
 class Cache {
        static protected $modelIds;
-       protected $classMap;
        protected $errorCallback;
 
        public function __construct() {
-               $this->classMap = [ 'true' => 1, 'false' => 0,
-                       'B' => 0, 'C' => 1, 'FA' => 2, 'GA' => 3,
-                       'Start' => 4, 'Stub' => 5 ];
                $this->setErrorCallback( function ( $mssg, $revision ) {
                        throw new RuntimeException( "Model contains an error 
for $revision: $mssg" );
                } );
@@ -36,6 +32,7 @@
         * @throws RuntimeException
         */
        public function storeScores( $scores ) {
+               global $wgOresModelClasses;
                // Map to database fields.
                $dbData = [];
                foreach ( $scores as $revision => $revisionData ) {
@@ -54,10 +51,18 @@
                                }
 
                                $modelId = $this->getModelId( $model );
+                               if ( !isset( $wgOresModelClasses[ $model ] ) ) {
+                                       throw new RuntimeException( "Model 
$model is not configured" );
+                               }
                                foreach ( $modelOutputs['probability'] as 
$class => $probability ) {
                                        $ores_is_predicted = $prediction === 
$class;
-                                       $class = $this->classMap[$class];
+                                       if ( !isset( $wgOresModelClasses[ 
$model ][ $class ] ) ) {
+                                               throw new RuntimeException( 
"Class $class in model $model is not configured" );
+                                       }
+                                       $class = $wgOresModelClasses[ $model ][ 
$class ];
                                        if ( $class === 0 ) {
+                                               // We don't store rows for 
class 0, because we can compute the class 0 probability by
+                                               // subtracting the sum of the 
probabilities of the other classes from 1
                                                continue;
                                        }
                                        $dbData[] = [

-- 
To view, visit https://gerrit.wikimedia.org/r/306316
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ided72fb3241411a0ace3c8cbea99ef4e7c8bb4c0
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Catrope <roan.katt...@gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to