Pyenchant: Как напечатать результаты в формате "err.word, string" - PullRequest
0 голосов
/ 26 апреля 2018

Я пытаюсь запустить проверку орфографии в списке строк. С кодом ниже я получаю только слова ошибки как (err.word). Однако я хотел бы напечатать строку вместе со словом ошибки, как

"This is a msspelled string" : msspelled

Я пытался

print("{} ".format(err.word), "{} ".format(chkr.get_text()))

но это не генерирует то, что я хочу. Есть предложения?

from enchant.checker import SpellChecker
import pypyodbc as db
import pandas as pd

pd.set_option('max_rows', 10000) # overriding default number of rows
pd.set_option('display.max_colwidth', -1)

cnx = db.connect("DNS")
qry = ("""SQL""")
A = pd.read_sql(qry,cnx).to_string()

chkr = SpellChecker("en_US")
chkr.set_text(A)

for err in chkr:
       print("{} ".format(err.word))

1 Ответ

0 голосов
/ 03 мая 2018

Это то, что вы пытаетесь сделать?

from enchant.checker import SpellChecker
A = "This iis a msspelled string"
chkr = SpellChecker("en_US")
chkr.set_text(A)

# Put all misspelled words in a list
misspelled_words = [err.word for err in chkr]

# Format and print this the sentence with the list of words.
print("{} : {}".format(A, ', '.join(misspelled_words)))
...