Hunspell package : spell checking for French language
Asked Answered
P

1

5

As I will be working on a french text with the mission to analyse it, I am unable to add a french dictionary to the hunspell package. I tried the links suggested by the package as follows :

To manually install dictionaries, copy the corresponding .aff and .dic file to ~/Library/Spelling or a custom directory specified in DICPATH. Alternatively you can pass the entire path to the .dic file as the dict parameter. Some popular sources of dictionaries are SCOWL, OpenOffice, debian, github/titoBouzout or github/wooorm.

However, nothing works out. I would like some suggestions into how to add a french dictionary to this package.

Thanks.

Picturesque answered 10/8, 2022 at 12:19 Comment(0)
T
7

This solution should work on any system (windows, linux, macOS):

First, run this code to download a lot of wonderful dictionaries:

git clone https://github.com/titoBouzout/Dictionaries.git

Take note of where you just downloaded the new files (since you'll use that location in the next step).

Inside R, run this line to load in the French dictionary you just downloaded:

library(hunspell) 
french <- dictionary("~/Dictionaries/French.dic")

Now that you have the French dictionary loaded, you can immediately use it to check spelling of French words:

words_to_check <- c( 
  "poule", 
  "coq", 
  "canard", 
  "cochon", 
  "âne", 
  "sldkfjsldkjf" # <- incorrect spelling should return false
  )

hunspell_check(words_to_check, dict = french)

# [1]  TRUE  TRUE  TRUE  TRUE  TRUE  FALSE

Note: this works for any language, not just French.

Titty answered 10/8, 2022 at 12:46 Comment(1)
It worked out and the problem is solved. thank you so much.Picturesque

© 2022 - 2024 — McMap. All rights reserved.