Santhosh has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/381418 )
Change subject: Template adaptation: Implement template param name matching
..
Template adaptation: Implement template param name matching
Algorithm:
1. Get template data for both source and target
2. Get aliases array for each parameter in source template, also
add the param name to that and form aliases+name set
3. For each param in target template data, form a similar set of
aliases and param.
4. Find intersection of above two sets.
5. If the intersection set is not empty, the source param maps to
the param name we located in target template data
Tests for name matching added.
TODO:
1. Use the param mapping to build target template definition.
2. Update tests for MWTemplate.js
Bug: T162114
Change-Id: I4ea9ae0dc902fecba0d300864e40cae6595c61b6
---
D config.yaml
A config.yaml
A lib/adaptation/TemplateParameterMapper.js
M lib/adaptation/TemplateTransclusion.js
A test/adaptation/TemplateParameterMapper.test.js
M test/translationunits/MWTemplate.test.json
6 files changed, 357 insertions(+), 49 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver
refs/changes/18/381418/1
diff --git a/config.yaml b/config.yaml
deleted file mode 12
index c11eec8..000
--- a/config.yaml
+++ /dev/null
@@ -1 +0,0 @@
-config.dev.yaml
\ No newline at end of file
diff --git a/config.yaml b/config.yaml
new file mode 100644
index 000..36280af
--- /dev/null
+++ b/config.yaml
@@ -0,0 +1,93 @@
+# Number of worker processes to spawn.
+# Set to 0 to run everything in a single process without clustering.
+# Use ncpu to run as many workers as there are CPU units
+num_workers: 0
+
+# Log error messages and gracefully restart a worker if v8 reports that it
+# uses more heap (note: not RSS) than this many megabytes.
+worker_heap_limit_mb: 250
+
+# Logger info
+logging:
+ level: trace
+# streams:
+# # Use gelf-stream -> logstash
+#- type: gelf
+#host: logstash1003.eqiad.wmnet
+#port: 12201
+
+# Statsd metrics reporter
+metrics:
+ type: log
+ #host: localhost
+ #port: 8125
+
+services:
+ - name: cxserver
+# a relative path or the name of an npm package, if different from name
+module: ./app.js
+# optionally, a version constraint of the npm package
+# version: ^0.4.0
+# per-service config
+conf:
+ port: 8080
+ # interface: localhost # uncomment to only listen on localhost
+ # More per-service config settings
+ # The location of the spec, defaults to spec.yaml if not specified
+ # spec: ./spec.yaml
+ # allow cross-domain requests to the API (default *)
+ cors: '*'
+ # to disable use:
+ # cors: false
+ # to restrict to a particular domain, use:
+ # cors: restricted.domain.org
+ # URL of the outbound proxy to use (complete with protocol)
+ # proxy: http://my.proxy.org:8080
+ # the list of domains for which not to use the proxy defined above
+ # no_proxy_list:
+ # - domain1.com
+ # - domain2.org
+ user_agent: cxserver
+ # Mediawiki host name. Example {lang}.wikisource.org which get expanded
internally to
+ # es.wikisource.org in a spanish language context.
+ # Do not prefix with http or https://
+ # mw_host: '{lang}.wikipedia.org'
+ mwapi_req:
+body: "{{request.body}}"
+query: "{{ default(request.query, {}) }}"
+headers:
+ host: "{{request.params.domain}}"
+ user-agent: "{{user-agent}}"
+method: post
+uri: "https://{{domain}}/w/api.php";
+ restbase_req:
+method: '{{request.method}}'
+uri: https://{{domain}}/api/rest_v1/{+path}
+query: '{{ default(request.query, {}) }}'
+headers: '{{request.headers}}'
+body: '{{request.body}}'
+ jwt:
+secret: 'secret'
+algorithms:
+ - HS256
+ languages: config/languages.yaml
+ mt:
+Apertium:
+ api: http://apertium.wmflabs.org
+ languages: config/Apertium.yaml
+Yandex:
+ api: https://translate.yandex.net
+ key: null
+ languages: config/Yandex.yaml
+Youdao:
+ api: https://fanyi.youdao.com/paidapi/fanyiapi
+ key: null
+ languages: config/Youdao.yaml
+Matxin:
+ api: http://matxin.elhuyar.eus/API
+ languages: config/Matxin.yaml
+ dictionary:
+Dictd:
+ languages: config/Dictd.yaml
+JsonDict:
+ languages: config/JsonDict.yaml
diff --git a/lib/adaptation/TemplateParameterMapper.js
b/lib/adaptation/TemplateParameterMapper.js
new file mode 100644
index 000..cb9a1f0
--- /dev/null
+++ b/lib/adaptation/TemplateParameterMapper.js
@@ -0,0 +1,59 @@
+class TemplateParameterMapper {
+ constructor( sourceParams, sourceTemplateData, targetTemplateD