Difference between revisions of "User:Shardulc"
Jump to navigation
Jump to search
(Add /translateChain documentation) |
(Add /list chained translation documentation) |
||
Line 1: | Line 1: | ||
'''/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). |
|||
<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> |
|||
<pre> |
|||
$ 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"}]} |
|||
</pre> |
|||
<pre> |
|||
$ curl 'http://localhost:2737/list?q=chains&src=fra' |
|||
{"responseDetails": null, "responseStatus": 200, "responseData": ["eng", "eng_US", "spa"]} |
|||
</pre> |
|||
'''/translateChain''' |
'''/translateChain''' |
||
Translate text in a chain of translations |
Translate text in a chain of translations |
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}