Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/130050
Change subject: Experiment: Apertium APY webservice based MT backend ...................................................................... Experiment: Apertium APY webservice based MT backend Not for review. Change-Id: I4f81f9198df2d54ec132a0b1c9a11fe907d6620a --- M index.js A mt/providers/Apertium.js M tests/index.js A tests/mt/Apertium/Apertium.test.js A tests/mt/Apertium/Apertium.test.json 5 files changed, 90 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver refs/changes/50/130050/1 diff --git a/index.js b/index.js index ffff889..6da44c2 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ module.exports = { Segmenter: require( './segmentation/CXSegmenter.js' ).CXSegmenter, - Rot13Service: require( './mt/providers/Rot13.js' ).Rot13Service + Rot13Service: require( './mt/providers/Rot13.js' ).Rot13Service, + ApertiumService: require( './mt/providers/Apertium.js' ).ApertiumService }; diff --git a/mt/providers/Apertium.js b/mt/providers/Apertium.js new file mode 100644 index 0000000..9a696fa --- /dev/null +++ b/mt/providers/Apertium.js @@ -0,0 +1,48 @@ +/** + *Apertium Translation service + * + * A dummy interface to test the CX MT + */ + +'use strict'; + +var Q = require( 'q' ), + request = require( 'request' ); + +/** + * @class ApertiumService + */ +function ApertiumService( config ) { + this.config = config; + this.parser = null; +} + +ApertiumService.prototype.translate = function ( segments ) { + var deferred = Q.defer(), + mt = {}, chain, + segmentIds; + + segmentIds = Object.keys( segments ); + chain = segmentIds.reduce( function ( previous, segmentId ) { + return previous.then( function () { + var deferred = Q.defer(), + req; + + req = 'http://localhost:2737/translate?langpair=eng|spa&q=' + segments[ segmentId ].source; + request( req, function ( error, response, body ) { + mt[ segmentId ] = JSON.parse( body ).responseData.translatedText; + deferred.resolve(); + } ); + return deferred.promise; + } ); + }, Q.resolve( 'start' ) ); + + chain.then( function () { + deferred.resolve( mt ); + } ); + + return deferred.promise; +}; + + +module.exports.ApertiumService = ApertiumService; diff --git a/tests/index.js b/tests/index.js index 48c2460..d13ba4b 100644 --- a/tests/index.js +++ b/tests/index.js @@ -3,6 +3,7 @@ tests = [ './tests/segmentation/CXSegmenter.test.js', './tests/mt/Rot13/Rot13.test.js', + './tests/mt/Apertium/Apertium.test.js' ]; qunit.setup( { diff --git a/tests/mt/Apertium/Apertium.test.js b/tests/mt/Apertium/Apertium.test.js new file mode 100644 index 0000000..0c49209 --- /dev/null +++ b/tests/mt/Apertium/Apertium.test.js @@ -0,0 +1,17 @@ +'use strict'; + +QUnit.module( 'Apertium' ); +QUnit.test( 'Apertium tests', function ( assert ) { + var apertium, tests = require( './Apertium.test.json' ); + + apertium = new CX.ApertiumService(); + QUnit.stop(); + apertium.translate( tests.source ).then( function ( result ) { + var segmentId; + + for ( segmentId in tests.source ) { + assert.strictEqual( result[ segmentId ], tests.result[ segmentId ] ); + } + QUnit.start(); + } ); +} ); diff --git a/tests/mt/Apertium/Apertium.test.json b/tests/mt/Apertium/Apertium.test.json new file mode 100644 index 0000000..b32956b --- /dev/null +++ b/tests/mt/Apertium/Apertium.test.json @@ -0,0 +1,22 @@ +{ + "source": { + "1": { + "source": "Debian" + }, + "2": { + "source": "<p>Hello world</p>" + }, + "3": { + "source": "<i>This is in Italics</i> Some other text" + }, + "4": { + "source": "Sentence one. <a href=\"#\">reference</a> Starts with reference" + } + }, + "result": { + "1": "*Debian", + "2": "<p>Hola Mundo</p>", + "3": "<i>Esto es en Cursiva</i> Algunos otro texto", + "4": "Sentenciar uno. <Un *href=\"" + } +} -- To view, visit https://gerrit.wikimedia.org/r/130050 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4f81f9198df2d54ec132a0b1c9a11fe907d6620a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/cxserver Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits