[MediaWiki-commits] [Gerrit] mediawiki...ORES[master]: Factor out Cache::$classMap into $wgOresModelClasses

2016-09-10 Thread jenkins-bot (Code Review)
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 
Gerrit-Reviewer: Ladsgroup 
Gerrit-Reviewer: Legoktm 
Gerrit-Reviewer: Thiemo Mättig (WMDE) 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] mediawiki...ORES[master]: Factor out Cache::$classMap into $wgOresModelClasses

2016-08-23 Thread Catrope (Code Review)
Catrope has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/306316

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, 26 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ORES 
refs/changes/16/306316/1

diff --git a/extension.json b/extension.json
index 1131189..6170c01 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 5061d96..edd7d46 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 ) {
@@ -56,8 +53,10 @@
$modelId = $this->getModelId( $model );
foreach ( $modelOutputs['probability'] as 
$class => $probability ) {
$ores_is_predicted = $prediction === 
$class;
-   $class = $this->classMap[$class];
+   $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: newchange
Gerrit-Change-Id: Ided72fb3241411a0ace3c8cbea99ef4e7c8bb4c0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ORES
Gerrit-Branch: master
Gerrit-Owner: Catrope 

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