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
Revision as of 01:20, 5 January 2017 by Shardulc (Talk | contribs)

Jump to: navigation, search

/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}
Personal tools