Apertium has moved from SourceForge to GitHub.
If you have any questions, please come and talk to us on #apertium on irc.freenode.net or contact the GitHub migration team.

User:Shardulc

From Apertium
(Difference between revisions)
Jump to: navigation, search
(Minor changes to translate/ documentation)
(Copy to http://wiki.apertium.org/wiki/Apertium-apy#Usage, leave a backup)
Line 1: Line 1:
== Usage ==
 
APY supports three types of requests: GET, POST, and JSONP. Using GET/POST are possible only if APY is running on the same server as the client due to cross-site scripting restrictions; however, JSONP requests are permitted in any context and will be useful. Using curl, APY can easily be tested:
 
<code>
 
<pre>curl -G --data "lang=kaz-tat&modes=morph&q=алдым" http://localhost:2737/perWord</pre>
 
</code> It can also be tested through your browser or through HTTP calls. Unfortunately, curl does '''not''' decode JSON output by default and to make testing easier, a APY Sandbox is provided in the SVN with [[Apertium-html-tools]].
 
   
{| class="wikitable" border="1"
+
'''/translate'''
|-
+
Translate text
! URL
 
! Function
 
! Parameters
 
! Output
 
|-
 
| '''/listPairs'''
 
| List available language pairs
 
|
 
*'''include_deprecated_codes''': give this parameter to include old ISO-639-1 codes in output
 
| To be consistent with ScaleMT, the returned JS Object contains a <code>responseData</code> key with an Array of language pair objects with keys <code>sourceLanguage</code> and <code>targetLanguage</code>.
 
<pre>
 
$ curl 'http://localhost:2737/listPairs'
 
   
{"responseStatus": 200, "responseData": [
 
{"sourceLanguage": "kaz", "targetLanguage": "tat"},
 
{"sourceLanguage": "tat", "targetLanguage": "kaz"},
 
{"sourceLanguage": "mk", "targetLanguage": "en"}
 
], "responseDetails": null}
 
</pre>
 
|-
 
| '''/list'''
 
| List available mode information
 
|
 
*'''q''': type of information to list
 
** pairs (alias for /listPairs)
 
** analyzers/analysers
 
** generators
 
** taggers/disambiguators
 
| The returned JS Object contains a mapping from language pairs to mode names (used internally by Apertium).
 
<pre>
 
$ curl 'http://localhost:2737/list?q=analyzers'
 
{"mk-en": "mk-en-morph", "en-es": "en-es-anmor", "kaz-tat": "kaz-tat-morph",
 
"tat-kaz": "tat-kaz-morph", "fin": "fin-morph", "es-en": "es-en-anmor", "kaz": "kaz-morph"}
 
</pre>
 
<pre>
 
$ curl 'http://localhost:2737/list?q=generators'
 
{"en-es": "en-es-generador", "fin": "fin-gener", "es-en": "es-en-generador"}
 
</pre>
 
<pre>
 
$ curl 'http://localhost:2737/list?q=taggers'
 
{"es-en": "es-en-tagger", "en-es": "en-es-tagger", "mk-en": "mk-en-tagger",
 
"tat-kaz": "tat-kaz-tagger", "kaz-tat": "kaz-tat-tagger", "kaz": "kaz-tagger"}
 
</pre>
 
|-
 
| '''/translate'''
 
| Translate text
 
|
 
 
*'''langpair''': language pair to use for translation
 
*'''langpair''': language pair to use for translation
 
*'''q''': text to translate
 
*'''q''': text to translate
Line 73: Line 34:
 
{"responseData": {"translatedText": "Qu\u00e9 hace este trabajo?"}, "responseDetails": null, "responseStatus": 200}
 
{"responseData": {"translatedText": "Qu\u00e9 hace este trabajo?"}, "responseDetails": null, "responseStatus": 200}
 
</pre>
 
</pre>
|-
 
| '''/translateDoc'''
 
| Translate a document (.odt, .txt, .rtf, .html, .docx, .pptx, .xlsx, .tex)
 
|
 
*'''langpair''': language pair to use for translation
 
*'''file''': document to translate
 
*'''markUnknown=no''' (optional): include this to remove "*" in front of unknown words
 
| Returns the translated document.
 
<pre>
 
$ curl --form 'file=@/path/to/kaz.odt' 'http://localhost:2737/translateDoc?langpair=kaz|tat' > tat.odt
 
</pre>
 
|-
 
| '''/analyze''' or '''/analyse'''
 
| Morphologically analyze text
 
|
 
*'''lang''': language to use for analysis
 
*'''q''': text to analyze
 
| The returned JS Array contains JS Arrays in the format <code>[analysis, input-text]</code>.
 
<pre style="white-space: pre-wrap;
 
white-space: -moz-pre-wrap;
 
white-space: -pre-wrap;
 
white-space: -o-pre-wrap;
 
word-wrap: break-word;">
 
$ curl -G --data "lang=kaz&q=Сен+бардың+ба?" http://localhost:2737/analyze
 
[["Сен/сен<v><tv><imp><p2><sg>/сен<prn><pers><p2><sg><nom>","Сен "], ["бардың ба/бар<adj><subst><gen>+ма<qst>/бар<v><iv><ifi><p2><sg>+ма<qst>","бардың ба"], ["?/?<sent>","?"]]
 
</pre>
 
|-
 
| '''/generate'''
 
| Generate surface forms from text
 
|
 
*'''lang''': language to use for generation
 
*'''q''': text to generate
 
| The returned JS Array contains JS Arrays in the format <code>[generated, input-text]</code>.
 
<pre>
 
$ curl -G --data "lang=kaz&q=^сен<v><tv><imp><p2><sg>$" http://localhost:2737/generate
 
[["сен","^сен<v><tv><imp><p2><sg>$ "]]
 
</pre>
 
|-
 
| '''/perWord'''
 
| Perform morphological tasks per word
 
|
 
*'''lang''': language to use for tasks
 
*'''modes''': morphological tasks to perform on text (15 combinations possible - delimit using '+')
 
** tagger/disambig
 
** biltrans
 
** translate
 
** morph
 
*'''q''': text to perform tasks on
 
| The returned JS Array contains JS Objects each containing the key <code>input</code> and up to 4 other keys corresponding to the requested modes (<code>tagger</code>, <code>morph</code>, <code>biltrans</code> and <code>translate</code>).
 
<pre style="white-space: pre-wrap;
 
white-space: -moz-pre-wrap;
 
white-space: -pre-wrap;
 
white-space: -o-pre-wrap;
 
word-wrap: break-word;">
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=morph&q=let+there+be+light'
 
[{"input": "let", "morph": ["let<vblex><inf>", "let<vblex><pres>", "let<vblex><past>", "let<vblex><pp>"]}, {"input": "there", "morph": ["there<adv>"]}, {"input": "be", "morph": ["be<vbser><inf>"]}, {"input": "light", "morph": ["light<n><sg>", "light<adj><sint>", "light<vblex><inf>", "light<vblex><pres>"]}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=tagger&q=let+there+be+light'
 
[{"input": "let", "tagger": "let<vblex><pp>"}, {"input": "there", "tagger": "there<adv>"}, {"input": "be", "tagger": "be<vbser><inf>"}, {"input": "light", "tagger": "light<adj><sint>"}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=morph+tagger&q=let+there+be+light'
 
[{"input": "let", "morph": ["let<vblex><inf>", "let<vblex><pres>", "let<vblex><past>", "let<vblex><pp>"], "tagger": "let<vblex><pp>"}, {"input": "there", "morph": ["there<adv>"], "tagger": "there<adv>"}, {"input": "be", "morph": ["be<vbser><inf>"], "tagger": "be<vbser><inf>"}, {"input": "light", "morph": ["light<n><sg>", "light<adj><sint>", "light<vblex><inf>", "light<vblex><pres>"], "tagger": "light<adj><sint>"}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=translate&q=let+there+be+light'
 
[{"input": "let", "translate": ["dejar<vblex><pp>"]}, {"input": "there", "translate": ["all\u00ed<adv>"]}, {"input": "be", "translate": ["ser<vbser><inf>"]}, {"input": "light", "translate": ["ligero<adj>"]}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=biltrans&q=let+there+be+light'
 
[{"input": "let", "biltrans": ["dejar<vblex><inf>", "dejar<vblex><pres>", "dejar<vblex><past>", "dejar<vblex><pp>"]}, {"input": "there", "biltrans": ["all\u00ed<adv>"]}, {"input": "be", "biltrans": ["ser<vbser><inf>"]}, {"input": "light", "biltrans": ["luz<n><f><sg>", "ligero<adj>", "encender<vblex><inf>", "encender<vblex><pres>"]}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=translate+biltrans&q=let+there+be+light'
 
[{"input": "let", "translate": ["dejar<vblex><pp>"], "biltrans": ["dejar<vblex><inf>", "dejar<vblex><pres>", "dejar<vblex><past>", "dejar<vblex><pp>"]}, {"input": "there", "translate": ["all\u00ed<adv>"], "biltrans": ["all\u00ed<adv>"]}, {"input": "be", "translate": ["ser<vbser><inf>"], "biltrans": ["ser<vbser><inf>"]}, {"input": "light", "translate": ["ligero<adj>"], "biltrans": ["luz<n><f><sg>", "ligero<adj>", "encender<vblex><inf>", "encender<vblex><pres>"]}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=morph+biltrans&q=let+there+be+light'
 
[{"input": "let", "morph": ["let<vblex><inf>", "let<vblex><pres>", "let<vblex><past>", "let<vblex><pp>"], "biltrans": ["dejar<vblex><inf>", "dejar<vblex><pres>", "dejar<vblex><past>", "dejar<vblex><pp>"]}, {"input": "there", "morph": ["there<adv>"], "biltrans": ["all\u00ed<adv>"]}, {"input": "be", "morph": ["be<vbser><inf>"], "biltrans": ["ser<vbser><inf>"]}, {"input": "light", "morph": ["light<n><sg>", "light<adj><sint>", "light<vblex><inf>", "light<vblex><pres>"], "biltrans": ["luz<n><f><sg>", "ligero<adj>", "encender<vblex><inf>", "encender<vblex><pres>"]}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=tagger+biltrans&q=let+there+be+light'
 
[{"input": "let", "biltrans": ["dejar<vblex><inf>", "dejar<vblex><pres>", "dejar<vblex><past>", "dejar<vblex><pp>"], "tagger": "let<vblex><pp>"}, {"input": "there", "biltrans": ["all\u00ed<adv>"], "tagger": "there<adv>"}, {"input": "be", "biltrans": ["ser<vbser><inf>"], "tagger": "be<vbser><inf>"}, {"input": "light", "biltrans": ["luz<n><f><sg>", "ligero<adj>", "encender<vblex><inf>", "encender<vblex><pres>"], "tagger": "light<adj><sint>"}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=tagger+translate&q=let+there+be+light'
 
[{"input": "let", "translate": ["dejar<vblex><pp>"], "tagger": "let<vblex><pp>"}, {"input": "there", "translate": ["all\u00ed<adv>"], "tagger": "there<adv>"}, {"input": "be", "translate": ["ser<vbser><inf>"], "tagger": "be<vbser><inf>"}, {"input": "light", "translate": ["ligero<adj>"], "tagger": "light<adj><sint>"}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=morph+translate&q=let+there+be+light'
 
[{"translate": ["dejar<vblex><pp>"], "input": "let", "morph": ["let<vblex><inf>", "let<vblex><pres>", "let<vblex><past>", "let<vblex><pp>"]}, {"translate": ["all\u00ed<adv>"], "input": "there", "morph": ["there<adv>"]}, {"translate": ["ser<vbser><inf>"], "input": "be", "morph": ["be<vbser><inf>"]}, {"translate": ["ligero<adj>"], "input": "light", "morph": ["light<n><sg>", "light<adj><sint>", "light<vblex><inf>", "light<vblex><pres>"]}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=translate+biltrans+tagger&q=let+there+be+light'
 
[{"input": "let", "translate": ["dejar<vblex><pp>"], "biltrans": ["dejar<vblex><inf>", "dejar<vblex><pres>", "dejar<vblex><past>", "dejar<vblex><pp>"], "tagger": "let<vblex><pp>"}, {"input": "there", "translate": ["all\u00ed<adv>"], "biltrans": ["all\u00ed<adv>"], "tagger": "there<adv>"}, {"input": "be", "translate": ["ser<vbser><inf>"], "biltrans": ["ser<vbser><inf>"], "tagger": "be<vbser><inf>"}, {"input": "light", "translate": ["ligero<adj>"], "biltrans": ["luz<n><f><sg>", "ligero<adj>", "encender<vblex><inf>", "encender<vblex><pres>"], "tagger": "light<adj><sint>"}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=morph+biltrans+tagger&q=let+there+be+light'
 
[{"input": "let", "morph": ["let<vblex><inf>", "let<vblex><pres>", "let<vblex><past>", "let<vblex><pp>"], "biltrans": ["dejar<vblex><inf>", "dejar<vblex><pres>", "dejar<vblex><past>", "dejar<vblex><pp>"], "tagger": "let<vblex><pp>"}, {"input": "there", "morph": ["there<adv>"], "biltrans": ["all\u00ed<adv>"], "tagger": "there<adv>"}, {"input": "be", "morph": ["be<vbser><inf>"], "biltrans": ["ser<vbser><inf>"], "tagger": "be<vbser><inf>"}, {"input": "light", "morph": ["light<n><sg>", "light<adj><sint>", "light<vblex><inf>", "light<vblex><pres>"], "biltrans": ["luz<n><f><sg>", "ligero<adj>", "encender<vblex><inf>", "encender<vblex><pres>"], "tagger": "light<adj><sint>"}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=morph+translate+tagger&q=let+there+be+light'
 
[{"translate": ["dejar<vblex><pp>"], "input": "let", "morph": ["let<vblex><inf>", "let<vblex><pres>", "let<vblex><past>", "let<vblex><pp>"], "tagger": "let<vblex><pp>"}, {"translate": ["all\u00ed<adv>"], "input": "there", "morph": ["there<adv>"], "tagger": "there<adv>"}, {"translate": ["ser<vbser><inf>"], "input": "be", "morph": ["be<vbser><inf>"], "tagger": "be<vbser><inf>"}, {"translate": ["ligero<adj>"], "input": "light", "morph": ["light<n><sg>", "light<adj><sint>", "light<vblex><inf>", "light<vblex><pres>"], "tagger": "light<adj><sint>"}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=morph+translate+biltrans&q=let+there+be+light'
 
[{"translate": ["dejar<vblex><pp>"], "input": "let", "morph": ["let<vblex><inf>", "let<vblex><pres>", "let<vblex><past>", "let<vblex><pp>"], "biltrans": ["dejar<vblex><inf>", "dejar<vblex><pres>", "dejar<vblex><past>", "dejar<vblex><pp>"]}, {"translate": ["all\u00ed<adv>"], "input": "there", "morph": ["there<adv>"], "biltrans": ["all\u00ed<adv>"]}, {"translate": ["ser<vbser><inf>"], "input": "be", "morph": ["be<vbser><inf>"], "biltrans": ["ser<vbser><inf>"]}, {"translate": ["ligero<adj>"], "input": "light", "morph": ["light<n><sg>", "light<adj><sint>", "light<vblex><inf>", "light<vblex><pres>"], "biltrans": ["luz<n><f><sg>", "ligero<adj>", "encender<vblex><inf>", "encender<vblex><pres>"]}]
 
 
curl 'http://localhost:2737/perWord?lang=en-es&modes=morph+translate+biltrans+tagger&q=let+there+be+light'
 
[{"translate": ["dejar<vblex><pp>"], "input": "let", "morph": ["let<vblex><inf>", "let<vblex><pres>", "let<vblex><past>", "let<vblex><pp>"], "biltrans": ["dejar<vblex><inf>", "dejar<vblex><pres>", "dejar<vblex><past>", "dejar<vblex><pp>"], "tagger": "let<vblex><pp>"}, {"translate": ["all\u00ed<adv>"], "input": "there", "morph": ["there<adv>"], "biltrans": ["all\u00ed<adv>"], "tagger": "there<adv>"}, {"translate": ["ser<vbser><inf>"], "input": "be", "morph": ["be<vbser><inf>"], "biltrans": ["ser<vbser><inf>"], "tagger": "be<vbser><inf>"}, {"translate": ["ligero<adj>"], "input": "light", "morph": ["light<n><sg>", "light<adj><sint>", "light<vblex><inf>", "light<vblex><pres>"], "biltrans": ["luz<n><f><sg>", "ligero<adj>", "encender<vblex><inf>", "encender<vblex><pres>"], "tagger": "light<adj><sint>"}]
 
 
</pre>
 
|-
 
| '''/listLanguageNames'''
 
| Get localized language names
 
|
 
*'''locale''': language to get localized language names in
 
*'''languages''': list of '+' delimited language codes to retrieve localized names for (optional - if not specified, all available codes will be returned)
 
| The returned JS Object contains a mapping of requested language codes to localized language names
 
<pre>
 
$ curl 'http://localhost:2737/listLanguageNames?locale=fr&languages=ca+en+mk+tat+kk'
 
{"ca": "catalan", "en": "anglais", "kk": "kazakh", "mk": "macédonien", "tat": "tatar"}
 
</pre>
 
|-
 
| '''/calcCoverage'''
 
| Get coverage of a language on a text
 
|
 
*'''lang''': language to analyze with
 
*'''q''': text to analyze for coverage
 
| The returned JS Array contains a single floating point value ≤ 1 that indicates the coverage.
 
<pre style="white-space: pre-wrap;
 
white-space: -moz-pre-wrap;
 
white-space: -pre-wrap;
 
white-space: -o-pre-wrap;
 
word-wrap: break-word;">
 
$ curl 'http://localhost:2737/getCoverage?lang=en-es&q=Whereas disregard and contempt for which have outraged the conscience of mankind'
 
[0.9230769230769231]
 
</pre>
 
|-
 
| '''/identifyLang'''
 
| Return a list of languages with probabilities of the text being in that language. Uses CLD2 if that's installed, otherwise will try any analyser modes.
 
|
 
*'''q''': text which you would like to compute probabilities for
 
| The returned JS Object contains a mapping from language codes to probabilities.
 
<pre>
 
$ curl 'http://localhost:2737/identifyLang?q=This+is+a+piece+of+text.'
 
{"ca": 0.19384234, "en": 0.98792465234, "kk": 0.293442432, "zh": 0.002931001}
 
</pre>
 
|-
 
| '''/stats'''
 
| Return some statistics about pair usage, uptime, portion of time spent actively translating
 
|
 
*'''requests=N''' (optional): limit period-based stats to last N requests
 
| Note that period-based stats are limited to 3600 seconds by default (see -T argument to servlet.py)
 
<pre>
 
$ curl -Ss localhost:2737/stats|jq .responseData
 
{
 
"holdingPipes": 0,
 
"periodStats": {
 
"totTimeSpent": 10.760803,
 
"ageFirstRequest": 19.609394,
 
"totChars": 2718,
 
"requests": 8,
 
"charsPerSec": 252.58
 
},
 
"runningPipes": {
 
"eng-spa": 1
 
},
 
"useCount": {
 
"eng-spa": 8
 
},
 
"uptime": 26
 
}
 
</pre>
 
|-
 
|}
 

Revision as of 19:24, 28 December 2016

/translate Translate text

  • langpair: language pair to use for translation
  • q: text to translate
  • markUnknown=no (optional): include this to remove "*" in front of unknown words
  • deformat: deformatter to be used: one of html (default), txt, rtf
  • reformat: deformatter to be used: one of html, html-noent (default), txt, rtf
  • format: if deformatter and reformatter are the same, they can be specified here

For more about formatting, please see Format Handling. | To be consistent with ScaleMT, the returned JS Object contains a responseData key with an JS Object that has key translatedText that contains the translated text.

$ curl 'http://localhost:2737/translate?langpair=kaz|tat&q=Сен+бардың+ба?'
{"responseStatus": 200, "responseData": {"translatedText": "Син барныңмы?"}, "responseDetails": null}
$ echo Сен бардың ба? > myfile
$ curl --data-urlencode 'q@myfile' 'http://localhost:2737/translate?langpair=kaz|tat'
{"responseStatus": 200, "responseData": {"translatedText": "Син барныңмы?"}, "responseDetails": null}

The following two queries contain nonstandard whitespace characters and are equivalent:

$ curl 'http://localhost:2737/translate?langpair=eng|spa&q=This    works well&deformat=txt&reformat=txt'
{"responseStatus": 200, "responseData": {"translatedText": "Esto    trabaja\u2001bien"}, "responseDetails": null}
$ curl 'http://localhost:2737/translate?langpair=eng|spa&q=This    works well&format=txt'
{"responseStatus": 200, "responseData": {"translatedText": "Esto    trabaja\u2001bien"}, "responseDetails": null}

The following two queries illustrate the difference between the html and html-noent reformatter:

$ curl 'http://localhost:2737/translate?langpair=eng|spa&q=How does this work?&reformat=html'
{"responseData": {"translatedText": "Qu&eacute; hace este trabajo?"}, "responseDetails": null, "responseStatus": 200}
$ curl 'http://localhost:2737/translate?langpair=eng|spa&q=How does this work?&reformat=html-noent'
{"responseData": {"translatedText": "Qu\u00e9 hace este trabajo?"}, "responseDetails": null, "responseStatus": 200}
Personal tools