Difference between revisions of "User:Shardulc"

From Apertium
Jump to navigation Jump to search
(Copy to http://wiki.apertium.org/wiki/Apertium-apy#Usage, leave a backup)
(Add /translateChain documentation)
Line 1: Line 1:
  +
'''/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'''

Revision as of 00:20, 5 January 2017

/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&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}