Skip to content

fixes for known word matching in corpus dictionary #303

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ TextBlobs can be translated between languages.

>>> en_blob = TextBlob(u'Simple is better than complex.')
>>> en_blob.translate(to='es')
TextBlob("Lo simple es mejor que lo complejo.")
TextBlob("Simple es mejor que complejo.")

If no source language is specified, TextBlob will attempt to detect the language. You can specify the source language explicitly, like so.
Raises `TranslatorError <textblob.exceptions.TranslatorError>` if the TextBlob cannot be translated into the requested language or `NotTranslated <textblob.exceptions.NotTranslated>` if the translated result is the same as the input string.
Expand Down
10 changes: 5 additions & 5 deletions tests/test_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def test_detect_non_ascii(self):
def test_translate_spaces(self):
es_text = "Hola, me llamo Adrián! Cómo estás? Yo bien"
to_en = self.translator.translate(es_text, from_lang="es", to_lang="en")
assert_equal(to_en, "Hi, my name is Adrián! How are you? I am good")
assert_equal(to_en, "Hello, my name is Adrian! How are you? I am good")

def test_translate_missing_from_language_auto_detects(self):
text = "Ich hole das Bier"
translated = self.translator.translate(text, to_lang="en")
assert_equal(translated, "I'll get the beer")
assert_equal(translated, "I get the beer")

def test_translate_text(self):
text = "This is a sentence."
Expand All @@ -99,11 +99,11 @@ def test_translate_text(self):
def test_translate_non_ascii(self):
text = "ذات سيادة كاملة"
translated = self.translator.translate(text, from_lang='ar', to_lang='en')
assert_equal(translated, "Fully sovereign")
assert_equal(translated, "Full sovereign")

text2 = "美丽比丑陋更好"
text2 = "美丽胜于丑陋"
translated = self.translator.translate(text2, from_lang="zh-CN", to_lang='en')
assert_equal(translated, "Beautiful is better than ugly")
assert_equal(translated, "Beauty is better than ugly")

@mock.patch('textblob.translate.Translator._validate_translation', mock.MagicMock())
def test_translate_unicode_escape(self):
Expand Down
2 changes: 1 addition & 1 deletion textblob/_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ def _edit2(self, w):
def _known(self, words=[]):
""" Returns the given list of words filtered by known words.
"""
return set(w for w in words if w in self)
return set(w for w in words if w.lower() in self)

def suggest(self, w):
""" Return a list of (word, confidence) spelling corrections for the given word,
Expand Down