Santhosh has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/327167 )
Change subject: Use new recommendation tool API
......................................................................
Use new recommendation tool API
Introduce wgRecommendToolAPI configuration parameter
The campaign parameter from recommendation tool will have the algorithm
as suffix. For example: campaign=suggestion-type-5-related-articles
Bug: T153187
Change-Id: If3abe05ff62f0adef35fa8cd06dfa374b023702f
---
M ContentTranslation.hooks.php
M extension.json
M modules/dashboard/ext.cx.recommendtool.client.js
M modules/dashboard/ext.cx.suggestionlist.js
4 files changed, 27 insertions(+), 17 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/67/327167/1
diff --git a/ContentTranslation.hooks.php b/ContentTranslation.hooks.php
index b740ce8..2371072 100644
--- a/ContentTranslation.hooks.php
+++ b/ContentTranslation.hooks.php
@@ -173,7 +173,8 @@
$wgContentTranslationCampaigns,
$wgContentTranslationBrowserBlacklist,
$wgContentTranslationDefaultSourceLanguage,
- $wgContentTranslationTargetNamespace;
+ $wgContentTranslationTargetNamespace,
+ $wgRecommendToolAPI;
$vars['wgContentTranslationTranslateInTarget'] =
$wgContentTranslationTranslateInTarget;
$vars['wgContentTranslationDomainCodeMapping'] =
$wgContentTranslationDomainCodeMapping;
@@ -185,6 +186,7 @@
$vars['wgContentTranslationBrowserBlacklist'] =
$wgContentTranslationBrowserBlacklist;
$vars['wgContentTranslationDefaultSourceLanguage'] =
$wgContentTranslationDefaultSourceLanguage;
$vars['wgContentTranslationTargetNamespace'] =
$wgContentTranslationTargetNamespace;
+ $vars['wgRecommendToolAPI'] = $wgRecommendToolAPI;
}
/**
diff --git a/extension.json b/extension.json
index e991c32..c888ac6 100644
--- a/extension.json
+++ b/extension.json
@@ -150,7 +150,9 @@
"key": "",
"age": "3600"
},
- "ContentTranslationEnableSuggestions": false
+ "ContentTranslationEnableSuggestions": false,
+ "@RecommendToolAPI": "Web API for translation recommendation
tool",
+ "RecommendToolAPI":
"https://recommend-test.wmflabs.org/types/translation/v1/articles"
},
"ResourceModules": {
"Base64.js": {
diff --git a/modules/dashboard/ext.cx.recommendtool.client.js
b/modules/dashboard/ext.cx.recommendtool.client.js
index ad73ddd..8a3aa42 100644
--- a/modules/dashboard/ext.cx.recommendtool.client.js
+++ b/modules/dashboard/ext.cx.recommendtool.client.js
@@ -22,7 +22,6 @@
function RecommendTool( from, to ) {
this.sourceLanguage = from;
this.targetLanguage = to;
- this.algorithms = [ 'wiki', 'morelike' ];
this.seeds = null;
}
@@ -68,20 +67,21 @@
* @return {jQuery.Promise}
*/
RecommendTool.prototype.getSuggestionList = function () {
- var self = this,
- algorithm;
+ var self = this;
- // Choose a random algorithm
- algorithm = this.algorithms[ Math.floor( Math.random() *
this.algorithms.length ) ];
return this.getSeedPages().then( function ( seedPages ) {
- return $.get( 'https://recommend.wmflabs.org/api/', {
- s: self.sourceLanguage,
- t: self.targetLanguage,
- article: seedPages.join( '|' ),
+ var algorithms, algorithm;
+
+ algorithms = [ 'morelike', 'related_articles' ];
+ algorithm = algorithms[ Math.floor( Math.random() *
algorithms.length ) ];
+ return $.get( mw.config.get( 'wgRecommendToolAPI' ), {
+ source: self.sourceLanguage,
+ target: self.targetLanguage,
+ seed: seedPages.join( '|' ),
search: algorithm,
application: 'CX'
- } ).then( function ( response ) {
- return self.adapt( response.articles, algorithm
);
+ } ).then( function ( articles ) {
+ return self.adapt( articles, algorithm );
} );
} );
};
@@ -107,6 +107,7 @@
sourceLanguage: this.sourceLanguage,
targetLanguage: this.targetLanguage,
pageviews: articles[ i ].pageviews,
+ wikidataId: articles[ i ].wikidata_id,
listId: 'trex'
} );
}
diff --git a/modules/dashboard/ext.cx.suggestionlist.js
b/modules/dashboard/ext.cx.suggestionlist.js
index d8efdb1..526467b 100644
--- a/modules/dashboard/ext.cx.suggestionlist.js
+++ b/modules/dashboard/ext.cx.suggestionlist.js
@@ -726,7 +726,7 @@
var self = this;
this.$suggestionsContainer.on( 'click', '.cx-suggestionlist
.cx-slitem', function () {
- var cxSelector, suggestion, campaign;
+ var cxSelector, suggestion, campaign, type, algorithm;
cxSelector = $( this ).data( 'cxsourceselector' );
@@ -734,13 +734,18 @@
cxSelector.prefill();
} else {
suggestion = $( this ).find(
'.cx-slitem__translation-link' ).data( 'suggestion' );
- // Capture the list type for the campaign
identifier
- campaign = 'suggestions-type-' + self.lists[
suggestion.listId ].type;
+ // Capture the list type and algorithm if any,
for the campaign identifier
+ type = self.lists[ suggestion.listId ].type;
+ campaign = [ 'suggestions-type', type ];
+ algorithm = self.lists[ suggestion.listId
].algorithm;
+ if ( algorithm ) {
+ campaign.push( algorithm );
+ }
$( this ).cxSourceSelector( {
sourceLanguage:
suggestion.sourceLanguage,
targetLanguage:
suggestion.targetLanguage,
sourceTitle: suggestion.title,
- campaign: campaign
+ campaign: campaign.join( '-' )
} );
}
} );
--
To view, visit https://gerrit.wikimedia.org/r/327167
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If3abe05ff62f0adef35fa8cd06dfa374b023702f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Santhosh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits