Difference between revisions of "User:Shardulc"
Jump to navigation
Jump to search
(Link to format handling page) |
(Add /list chained translation documentation) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
'''/list''' or '''/listPairs''' List available mode information |
|||
== 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" |
|||
|- |
|||
! 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 |
*'''q''': type of information to list |
||
** pairs ( |
** pairs (default for /listPairs) |
||
** analyzers/analysers |
** analyzers/analysers |
||
** generators |
** generators |
||
** taggers/disambiguators |
** taggers/disambiguators |
||
** chains (chained translations: see '''/translateChain'''). This requires the additional argument '''src''' for the source language of possible translation chains. |
|||
| The returned JS Object contains a mapping from language pairs to mode names (used internally by Apertium). |
|||
The returned JS Object contains a mapping from language pairs to mode names (used internally by Apertium). |
|||
<pre> |
<pre> |
||
$ curl 'http://localhost:2737/list?q=analyzers' |
$ curl 'http://localhost:2737/list?q=analyzers' |
||
Line 50: | Line 21: | ||
"tat-kaz": "tat-kaz-tagger", "kaz-tat": "kaz-tat-tagger", "kaz": "kaz-tagger"} |
"tat-kaz": "tat-kaz-tagger", "kaz-tat": "kaz-tat-tagger", "kaz": "kaz-tagger"} |
||
</pre> |
</pre> |
||
<pre> |
|||
|- |
|||
$ curl 'http://localhost:2737/list?q=pairs' |
|||
| '''/translate''' |
|||
{"responseDetails": null, "responseStatus": 200, "responseData": [{"sourceLanguage": "spa", "targetLanguage": "eng"}, {"sourceLanguage": "spa", "targetLanguage": |
|||
| Translate text |
|||
"fra"}, {"sourceLanguage": "fra", "targetLanguage": "spa"}, {"sourceLanguage": "eng", "targetLanguage": "spa"}]} |
|||
| |
|||
</pre> |
|||
<pre> |
|||
$ curl 'http://localhost:2737/list?q=chains&src=fra' |
|||
{"responseDetails": null, "responseStatus": 200, "responseData": ["eng", "eng_US", "spa"]} |
|||
</pre> |
|||
'''/translateChain''' |
|||
Translate text in a chain of translations |
|||
*'''langpairs''': language pairs in the chain. If only two languages are given, like '''eng|spa''', APy calculates the shortest path between them (which is the pair itself if it exists, of course). If more languages are given, like '''eng|spa|fra''', APy follows that path if possible and returns a 400 if not. |
|||
*'''q''' (optional): text to translate. If not provided, APy responds with the path that would be taken for '''langpairs'''; otherwise APy translates the text. |
|||
*Other parameters are like '''/translate''' |
|||
If the installed pairs are |
|||
<pre> |
|||
$ curl 'http://localhost:2737/listPairs' |
|||
{"responseData": [{"targetLanguage": "fra", "sourceLanguage": "spa"}, {"targetLanguage": "eng", "sourceLanguage": "spa"}, |
|||
{"targetLanguage": "spa", "sourceLanguage": "eng"}, {"targetLanguage": "spa", "sourceLanguage": "fra"}], |
|||
"responseStatus": 200, "responseDetails": null} |
|||
</pre> |
|||
then |
|||
<pre> |
|||
$ curl 'http://localhost:2737/translateChain?langpairs=eng|fra&q=There+is+an+elephant+in+the+room' |
|||
{"responseData": {"translationChain": ["eng", "spa", "fra"], "translatedText": " Il y a un \u00e9l\u00e9phant dans la chambre"}, |
|||
"responseStatus": 200, "responseDetails": null} |
|||
$ curl 'http://localhost:2737/translateChain?langpairs=eng|spa&q=There+is+an+elephant+in+the+room' |
|||
{"responseData": {"translationChain": ["eng", "spa"], "translatedText": " Hay un elefante en la habitaci\u00f3n"}, |
|||
"responseStatus": 200, "responseDetails": null} |
|||
$ curl 'http://localhost:2737/translate?langpair=eng|spa&q=There+is+an+elephant+in+the+room' |
|||
{"responseData": {"translatedText": " Hay un elefante en la habitaci\u00f3n"}, "responseStatus": 200, "responseDetails": null} |
|||
$ curl 'http://localhost:2737/translate?langpair=spa|fra&q=Hay+un+elefante+en+la+habitación' |
|||
{"responseData": {"translatedText": "Il y a un \u00e9l\u00e9phant dans la chambre"}, "responseStatus": 200, "responseDetails": null} |
|||
</pre> |
|||
Without a '''q''' parameter: |
|||
<pre> |
|||
$ curl 'http://localhost:2737/translateChain?langpairs=spa|fra' |
|||
{"responseData": {"translationChain": ["spa", "fra"]}, "responseStatus": 200, "responseDetails": null} |
|||
$ curl 'http://localhost:2737/translateChain?langpairs=fra|eng' |
|||
{"responseData": {"translationChain": ["fra", "spa", "eng"]}, "responseStatus": 200, "responseDetails": null} |
|||
</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 59: | Line 79: | ||
*'''deformat''': deformatter to be used: one of html (default), txt, rtf |
*'''deformat''': deformatter to be used: one of html (default), txt, rtf |
||
*'''reformat''': deformatter to be used: one of html, html-noent (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 |
*'''format''': if deformatter and reformatter are the same, they can be specified here |
||
For more about formatting, please see [http://wiki.apertium.org/wiki/Format_handling |
For more about formatting, please see [http://wiki.apertium.org/wiki/Format_handling Format Handling]. |
||
| To be consistent with ScaleMT, the returned JS Object contains a <code>responseData</code> key with an JS Object that has key <code>translatedText</code> that contains the translated text. |
| To be consistent with ScaleMT, the returned JS Object contains a <code>responseData</code> key with an JS Object that has key <code>translatedText</code> that contains the translated text. |
||
<pre> |
<pre> |
||
Line 68: | Line 88: | ||
$ curl --data-urlencode 'q@myfile' 'http://localhost:2737/translate?langpair=kaz|tat' |
$ curl --data-urlencode 'q@myfile' 'http://localhost:2737/translate?langpair=kaz|tat' |
||
{"responseStatus": 200, "responseData": {"translatedText": "Син барныңмы?"}, "responseDetails": null} |
{"responseStatus": 200, "responseData": {"translatedText": "Син барныңмы?"}, "responseDetails": null} |
||
</pre> |
|||
The following two queries contain nonstandard whitespace characters and are equivalent: |
|||
<pre> |
|||
$ curl 'http://localhost:2737/translate?langpair=eng|spa&q=This works well&deformat=txt&reformat=txt' |
$ 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} |
{"responseStatus": 200, "responseData": {"translatedText": "Esto trabaja\u2001bien"}, "responseDetails": null} |
||
Line 74: | Line 97: | ||
{"responseStatus": 200, "responseData": {"translatedText": "Esto trabaja\u2001bien"}, "responseDetails": null} |
{"responseStatus": 200, "responseData": {"translatedText": "Esto trabaja\u2001bien"}, "responseDetails": null} |
||
</pre> |
</pre> |
||
(The last two queries are equivalent.) |
|||
|- |
|||
| '''/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>"]}] |
|||
The following two queries illustrate the difference between the <code>html</code> and <code>html-noent</code> reformatter: |
|||
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> |
<pre> |
||
$ curl |
$ 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' |
|||
"holdingPipes": 0, |
|||
{"responseData": {"translatedText": "Qu\u00e9 hace este trabajo?"}, "responseDetails": null, "responseStatus": 200} |
|||
"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> |
</pre> |
||
|- |
|||
|} |
Latest revision as of 03:21, 6 January 2017
/list or /listPairs List available mode information
- q: type of information to list
- pairs (default for /listPairs)
- analyzers/analysers
- generators
- taggers/disambiguators
- chains (chained translations: see /translateChain). This requires the additional argument src for the source language of possible translation chains.
The returned JS Object contains a mapping from language pairs to mode names (used internally by Apertium).
$ 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"}
$ curl 'http://localhost:2737/list?q=generators' {"en-es": "en-es-generador", "fin": "fin-gener", "es-en": "es-en-generador"}
$ 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"}
$ curl 'http://localhost:2737/list?q=pairs' {"responseDetails": null, "responseStatus": 200, "responseData": [{"sourceLanguage": "spa", "targetLanguage": "eng"}, {"sourceLanguage": "spa", "targetLanguage": "fra"}, {"sourceLanguage": "fra", "targetLanguage": "spa"}, {"sourceLanguage": "eng", "targetLanguage": "spa"}]}
$ curl 'http://localhost:2737/list?q=chains&src=fra' {"responseDetails": null, "responseStatus": 200, "responseData": ["eng", "eng_US", "spa"]}
/translateChain
Translate text in a chain of translations
- langpairs: language pairs in the chain. If only two languages are given, like eng|spa, APy calculates the shortest path between them (which is the pair itself if it exists, of course). If more languages are given, like eng|spa|fra, APy follows that path if possible and returns a 400 if not.
- q (optional): text to translate. If not provided, APy responds with the path that would be taken for langpairs; otherwise APy translates the text.
- Other parameters are like /translate
If the installed pairs are
$ curl 'http://localhost:2737/listPairs' {"responseData": [{"targetLanguage": "fra", "sourceLanguage": "spa"}, {"targetLanguage": "eng", "sourceLanguage": "spa"}, {"targetLanguage": "spa", "sourceLanguage": "eng"}, {"targetLanguage": "spa", "sourceLanguage": "fra"}], "responseStatus": 200, "responseDetails": null}
then
$ curl 'http://localhost:2737/translateChain?langpairs=eng|fra&q=There+is+an+elephant+in+the+room' {"responseData": {"translationChain": ["eng", "spa", "fra"], "translatedText": " Il y a un \u00e9l\u00e9phant dans la chambre"}, "responseStatus": 200, "responseDetails": null} $ curl 'http://localhost:2737/translateChain?langpairs=eng|spa&q=There+is+an+elephant+in+the+room' {"responseData": {"translationChain": ["eng", "spa"], "translatedText": " Hay un elefante en la habitaci\u00f3n"}, "responseStatus": 200, "responseDetails": null} $ curl 'http://localhost:2737/translate?langpair=eng|spa&q=There+is+an+elephant+in+the+room' {"responseData": {"translatedText": " Hay un elefante en la habitaci\u00f3n"}, "responseStatus": 200, "responseDetails": null} $ curl 'http://localhost:2737/translate?langpair=spa|fra&q=Hay+un+elefante+en+la+habitación' {"responseData": {"translatedText": "Il y a un \u00e9l\u00e9phant dans la chambre"}, "responseStatus": 200, "responseDetails": null}
Without a q parameter:
$ curl 'http://localhost:2737/translateChain?langpairs=spa|fra' {"responseData": {"translationChain": ["spa", "fra"]}, "responseStatus": 200, "responseDetails": null} $ curl 'http://localhost:2737/translateChain?langpairs=fra|eng' {"responseData": {"translationChain": ["fra", "spa", "eng"]}, "responseStatus": 200, "responseDetails": null}
/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é 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}