-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The example
function in YandexTranslate
without translation
#101
Comments
Don't mix different things - dictionary (словарь) и example (примеры). That documentation talks about a dictionary. But okay, that's not the problem, we use custom reverse engineered API endpoints, the endpoint in the documentation requires API keys for authorisation. |
Can you get the same behavior as you need (source language to source language) in Yandex Translate web application or Android application? If not, we can't help you. |
I'm sorry that I got something mixed up. But in the
Unfortunately, I couldn't reproduce it. I will try to find a solution to my problem outside of your library. Maybe you can give me some advice? |
The closest thing to the functionality mentioned in documentation is the
I make some changes to the translatepy to get working Yandex dictionary function and I get this response for specific words:
Is this something you were looking for? |
I think the definition of the translate/translatepy/translators/base.py Lines 959 to 975 in 6bd2237
translate/translatepy/models.py Lines 634 to 733 in 6bd2237
This makes me think that I just checked on the As for the current stable version, those functions are hit are miss and are here because some translators such as Yandex are DeepL supported some kind of “example” feature, but which seemed to have different behaviors following the website used. Note For example, the use of a It might also be worth diving a bit more in the current web implementations of the |
As a result, I wrote my own simple function to get a list of sample sentences using your exceptions. I'll use it for now. import requests
from translatepy.translators.yandex import YandexTranslateException
from translatepy.translators import BaseTranslator
def get_examples(text: str, source_language: str, destination_language: str) -> list:
link = (f"https://dictionary.yandex.net/dicservice.json/queryCorpus?ui=en&"
f"src={text}&lang={source_language}-{destination_language}&flags=7&srv=android&v=2&maxlen=200")
BaseTranslator._validate_language_pair(None, source_language, destination_language)
request = requests.get(link)
if request.status_code >= 400:
raise YandexTranslateException(request.status_code, request.json()["message"])
result = []
for example in request.json()["result"]["examples"]:
result.append({
"src": example["src"].replace("<", "").replace(">", ""),
"dst": example["dst"].replace("<", "").replace(">", "")
})
return result |
To get examples of sentences with a word in English, I use the
YandexTranslate
class functionexample
. This function has the parametersdestination_language
andsource_language
and when they are equal, the errorParameterValueError: Parameter source_language cannot be equal to the destination_language parameter
appears. Although in the documentationYandex API says that you can use a language pair with the same languages.
To get around this error, I have to translate the word I need, and then specify the translation back to the source language in the
example
function. This leads to incorrect results.The Yandex API allows (if you believe the documentation) not to translate the word to search for suggestions, but the library returns an error.
Is it possible to search for example Yandex sentences through your library without translating the word?
The code I'm using now:
The code that I would like to use, but which returns an error:
The text was updated successfully, but these errors were encountered: