0

Does anyone know if QGIS is going to have an in-built spell check as standard in future versions? It is one complaint I get from staff is lack of a spell check.

If not has anyone successfully found a way that the Python libraries can be tapped into and added into QGIS?

2
  • 4
    Where is the text you want to spell check? In attribute table?
    – Bera
    Commented Jul 4, 2020 at 19:09
  • attribute table and layout manager
    – mh_perth
    Commented Jul 5, 2020 at 12:57

2 Answers 2

4

I had a go using python and library named pyspellchecker.

Install process (on my system): Find executable:

import sys
sys.executable

Then pip:

enter image description here

This will print out the misspelled words for a field in the attribute table and select the feature:

from spellchecker import SpellChecker
import re

layer = iface.activeLayer()
field_to_check = 'words'

#Remove all but letters and whitespaces
regex = re.compile(r"\s*[^A-Za-z]+\s*") #https://stackoverflow.com/questions/40105027/reg-ex-remove-non-alpha-characters-keeping-spaces

for f in layer.getFeatures():
    spell = SpellChecker()
    text = f[field_to_check]
    text = regex.sub(' ', text)
    wordlist = text.split()
    #print(wordlist)
    misspelled = spell.unknown(wordlist)
    if len(misspelled)>0:
        layer.select(f.id())
        print('Misspelled words in feature {}: {}'.format(f.id(), misspelled))

enter image description here

1
  • 2
    Very neat and compact solution
    – Matt
    Commented Nov 16, 2022 at 7:51
0

If you are using Postgresql then there is a built-in functionality for spell-checking. It uses text search data type to create a token table extracted from your document or user input lexemes.

You only need to introduce a dictionary (it has some pre-defined ones) and implement the required SQL to find if the text need to be corrected and again use some SQL to correct it.

You may also use a third party library like hunspell on github.

Sorry, I don’t really know if qgis will implement spell-checking in future.

Not the answer you're looking for? Browse other questions tagged or ask your own question.