complete method

Returns the most probable ending of the text and the end of word attribute.

Description

CompleteResponse complete(string key, string q, string lang, int limit);

Input parameters

Input parameters can be passed either with an HTTP GET request (see the example) or with an HTTP POST request, where the parameters are passed in the body of the HTTP request.

Request example:

XML interface:

https://predictor.yandex.net/api/v1/predict/complete?key=APIkey&q=hello+wo&lang=en

JSON interface:

https://predictor.yandex.net/api/v1/predict.json/complete?key=APIkey&q=hello+wo&lang=en

JSONP interface (for the myCallback function):

https://predictor.yandex.net/api/v1/predict.json/complete?key=APIkey&q=hello+wo&lang=en&callback=myCallback

Example of input parameters.

Parameter Type Description
Required
key string API key. Get a free API key on this page.
lang string

The language of the text (for example, "en"). To get the list of languages, use the getLangs method.

q string

The text where the user's cursor is pointed.

The suggestion is based on the word that the cursor is pointing at plus the two preceding words, so it is enough to pass a text with three or four words.

Optional
limit int

The maximum number of rows returned (1 by default).

Parameter Type Description
Required
key string API key. Get a free API key on this page.
lang string

The language of the text (for example, "en"). To get the list of languages, use the getLangs method.

q string

The text where the user's cursor is pointed.

The suggestion is based on the word that the cursor is pointing at plus the two preceding words, so it is enough to pass a text with three or four words.

Optional
limit int

The maximum number of rows returned (1 by default).

Returns

In the XML interface, returns the CompleteResponse structure containing the suggested text. For example:

<?xml version="1.0" encoding="utf-8"?>
<CompleteResponse endOfWord="false" pos="-2">
  <text>
    <string>world</string>
    ...
  </text>
</CompleteResponse>

XML scheme elements in the response:

Element Description
CompleteResponse

The root element, which contains the text element.

Attributes:

  • endOfWord – End of word attribute (true/false).

    The method can return the "continuation" of the passed phrase and the endOfWord= true attribute at the same time. For example, for the "He" text it returns "Hello", as well as the end of word attribute.

  • pos – Position in the word for which the ending suggestion is returned. Position is counted from the last character in the query passed in the q element.

    Usually, pos has a negative value. For example, for the q="Alice in Wonderl" it will return pos=-4. If the query contains a complete phrase, the request may return a suggestion for the next word. In this case, the pos value is 0 (for example, if q = "Alice in ") or 1 (for example, if q = "Alice in").

text

Contains string elements with the most likely suggestions for the text.

If the method cannot "continue" the text, the element isn't returned.

Element Description
CompleteResponse

The root element, which contains the text element.

Attributes:

  • endOfWord – End of word attribute (true/false).

    The method can return the "continuation" of the passed phrase and the endOfWord= true attribute at the same time. For example, for the "He" text it returns "Hello", as well as the end of word attribute.

  • pos – Position in the word for which the ending suggestion is returned. Position is counted from the last character in the query passed in the q element.

    Usually, pos has a negative value. For example, for the q="Alice in Wonderl" it will return pos=-4. If the query contains a complete phrase, the request may return a suggestion for the next word. In this case, the pos value is 0 (for example, if q = "Alice in ") or 1 (for example, if q = "Alice in").

text

Contains string elements with the most likely suggestions for the text.

If the method cannot "continue" the text, the element isn't returned.

Error codes
Code Value Description
ERR_OK 200

Operation was completed successfully.

ERR_KEY_INVALID 401

API key is invalid.

ERR_KEY_BLOCKED 402

API key is blocked.

ERR_DAILY_REQ_LIMIT_EXCEEDED 403

The number of requests exceeded the daily limit (requests that use the getLangs method are also counted).

ERR_DAILY_CHAR_LIMIT_EXCEEDED 404

The amount of suggested text exceeded the daily limit (requests that use the getLangs method are also counted).

ERR_TEXT_TOO_LONG 413

Exceeded the maximum text size (1000 characters).

ERR_LANG_NOT_SUPPORTED 501

The language isn't supported.

Error codes
Code Value Description
ERR_OK 200

Operation was completed successfully.

ERR_KEY_INVALID 401

API key is invalid.

ERR_KEY_BLOCKED 402

API key is blocked.

ERR_DAILY_REQ_LIMIT_EXCEEDED 403

The number of requests exceeded the daily limit (requests that use the getLangs method are also counted).

ERR_DAILY_CHAR_LIMIT_EXCEEDED 404

The amount of suggested text exceeded the daily limit (requests that use the getLangs method are also counted).

ERR_TEXT_TOO_LONG 413

Exceeded the maximum text size (1000 characters).

ERR_LANG_NOT_SUPPORTED 501

The language isn't supported.

In the JSON interface, JavaScript objects are returned instead of XML elements. The objects have the same names and semantics as the XML elements:

{"endOfWord":false,"pos":-2,"text":["world"]}

In the JSONP interface, the same JavaScript objects are returned in a callback function (for example, myCallback):

myCallback({"endOfWord":false,"pos":-2,"text":["world"]})