Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to build a dictionary for the NetBeans spellchecker

DZone's Guide to

How to build a dictionary for the NetBeans spellchecker

· Big Data Zone
Free Resource

Learn how you can maximize big data in the cloud with Apache Hadoop. Download this eBook now. Brought to you in partnership with Hortonworks.

I'll try to explain how I have developed the French, German and Spanish dictionaries for the NetBeans online spellchecker : we will build a French dictionary for NetBeans 7.3 (it works with 7.2 and 7.1 too).

Summary :

  • #1 expand GNU Aspell dictionaries files.
  • #2 checkout the NetBeans 7.3.0 FCS sources from Mercurial repository.
  • #3 open the English dictionary project and make a copy.
  • #4 modify the copied project.
  • #5 make the NBM file and test it.
  • #6 (optional) sign the NBM file and submit it to the community for validation.

Step 1 : expand GNU Aspell dictionaries files

Download Aspell. You can get the latest Win32 installer version from ftp://ftp.gnu.org(...)Aspell-0-50-3-3-Setup.exe. Run it to install Aspell.
Download the latest French dictionaries file. You can get Win32 installers from ftp://ftp.gnu.org/gnu/aspell/w32/. The latest French dictionnaries file is Aspell-fr-0.50-3-3.exe. Run it to install the French dictionaries into Aspell.

You can now expand the dictionaries files you want to include in the future NetBeans plugin. We'll expand the "fr_FR" and "fr_CH" dictionaries. Go to the "dict" directory of Aspell and run the following commands (if necessary, add the Aspell "bin" directory to your PATH variable, in the Operating System or a batch script) :

aspell --lang=fr_FR --master=fr_FR dump master | sort > aspell_dump_fr_FR.txt
aspell --lang=fr_CH --master=fr_CH dump master | sort > aspell_dump_fr_CH.txt

The first line will expand and sort the "fr_FR" dictionary to the default output. The > switch is used to save the output to a file (aspell_dump_fr_FR.txt), in the current directory. The second line does the same job with the "fr_CH" language.

You'll note that the expanded dictionaries files may not be UTF-8 encoded. If necessary, re-encode them to UTF-8. You can do it with Notepad2 : open a file and go to File, Encoding, and select the UTF-8 encoding. It will encode the opened file.

To finish, pack the two files into a ZIP file (you can do it with every ZIP archiver, like 7-Zip). We will call this archive "aspell-frwl.zip" :

Nota n°1 : What does "expand a dictionary file" means ? Aspell dictionaries files are a set of words and affixes lists. Word lists contains basic forms of common words. Affixes are used to compute the different variations of words. By expanding a dictionary , we ask Aspell to compute a list of all words with all their variations. The result is a huge file. We need to expand dictionaries files because the NetBeans Spellchecker (seems to) use only expanded dictionaries files : it doesn't support affixes lists ;)

Nota n°2 : These are the MS Windows instructions. Linux and MacOS ones should be easy to find.

Step 2 : checkout the NetBeans 7.3.0 FCS sources from Mercurial repository

Refer to the given tutorial : How to build NetBeans from sources, step 1 only.

After that, you need at least two directories : "releases/nbbuild/" and "releases/spellchecker.dictionary_en/". If you want to free some space, you can delete the other directories. You can now start your NetBeans IDE and load the "spellchecker.dictionary_en" project.

Step 3 : open the English dictionary project and make a copy

NetBeans will ask you for a new project name. Choose something like "spellchecker.dictionary_fr" :

Actually, the project name you have chosen is the project's folder name. NetBeans will show you the "SpellChecker English Dictionaries (0)" title for your project. Rename it (you can use the F2 key on the project's name) to "SpellChecker French Dictionaries" :

You now have the two projects, English and French dictionaries plugin projects :

Step 4 : modify the copied project

The French project is correctly named, so we can now modify its content to target French dictionaries.
Switch to the "File" project tab to show more files.

Step 4.1 : empty the "external" directory's content and copy your French dictionaries archive file

This directory contains the English dictionaries files. We will provide our own files.
Delete the files located into the "external" directory and copy the "aspell-frwl.zip" created during step 1.

Step 4.2 : edit the "nbproject/project.properties" file

Replace :

release.external/ispell-enwl-3.1.20.zip=modules/dict/ispell-enwl-3.1.20.zip
jnlp.indirect.files=modules/dict/dictionary_en_US.description,modules/dict/dictionary_en_GB.description,modules/dict/ispell-enwl-3.1.20.zip,modules/dict/dictionary_en.description

by :

release.external/aspell-frwl.zip=modules/dict/aspell-frwl.zip
jnlp.indirect.files=modules/dict/dictionary_fr_FR.description,modules/dict/dictionary_fr_CH.description,modules/dict/aspell-frwl.zip,modules/dict/dictionary_fr.description

We have replaced references to English dictionary and locales by French ones.

Step 4.3 : edit the "nbproject/project.xml" file

Replace :

<code-name-base>org.netbeans.modules.spellchecker.dictionary_en</code-name-base>

by :

<code-name-base>org.netbeans.modules.spellchecker.dictionary_fr</code-name-base>

Step 4.4 : rename the "src/org/netbeans/modules/spellchecker/dictionary_en/" folder

Rename the "dictionary_en" folder to "dictionary_fr".

Step 4.5 : edit the "src/org/netbeans/modules/spellchecker/dictionary_fr/Bundle.properties" file

Replace :

OpenIDE-Module-Display-Category=Base IDE
OpenIDE-Module-Long-Description=\
    Provides Ispell's (ver. 3.1.20) word list for use in the online spellchecker.
OpenIDE-Module-Name=Spellchecker English Dictionaries
OpenIDE-Module-Short-Description=English Dictionaries for Spellchecker

by something like :

OpenIDE-Module-Display-Category=Base IDE
OpenIDE-Module-Long-Description=\
    Provides Aspell's French word list for use in the online spellchecker.
OpenIDE-Module-Name=Spellchecker French Dictionaries
OpenIDE-Module-Short-Description=French Dictionaries for Spellchecker

This file describes your plugin. Do not hesitate to change the description fields.

Step 4.6 : edit the "build.xml" file

Replace :

<project name="spellchecker.dictionary_en" default="netbeans" basedir=".">

by :

<project name="spellchecker.dictionary_fr" default="netbeans" basedir=".">

Step 4.7 : edit the "manifest.mf" file

Replace :

Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.spellchecker.dictionary_en
XOpenIDE-Module-Layer: org/netbeans/modules/spellchecker/dictionary_en/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/spellchecker/dictionary_en/Bundle.properties
OpenIDE-Module-Specification-Version: 1.8.1

by :

Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.spellchecker.dictionary_fr
XOpenIDE-Module-Layer: org/netbeans/modules/spellchecker/dictionary_fr/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/spellchecker/dictionary_fr/Bundle.properties
OpenIDE-Module-Specification-Version: 1.0

Please note we have changed the plugin version, from 1.8.1 to 1.0.

Step 4.8 : rename and edit the "release/module/dict/dictionary_en.description" file

Rename the "dictionary_en.description" file to "dictionary_fr.description".

After that, replace :

jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.0
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.1
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.2
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.3
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/american.0
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/american.1
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/american.2

by :

jar:nbinst:///modules/dict/aspell-frwl.zip!/aspell_dump_fr_FR.txt
jar:nbinst:///modules/dict/aspell-frwl.zip!/aspell_dump_fr_CH.txt

Some explanations : our plugin will contain dictionaries for the "fr", "fr_FR" and "fr_CH" locales. We have a ".description" file for each of them. In these files, we locate the word list(s) to use. So, the "fr" locale is the combination of the "fr_FR" and "fr_CH" word lists. The "fr_FR" locale uses the "fr_FR" word list, and the "fr_CH" locale uses the "fr_CH" word list. Here, we have edited the description file of the "fr" locale. Let's do it for the other ones :)

Nota : The "aspell-frwl.zip!" syntax means that we enter into a ZIP file.

Step 4.9 : rename and edit the "release/module/dict/dictionary_en_GB.description" file

Rename the "dictionary_en_GB.description" file to "dictionary_fr_FR.description".

After that, replace :

jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.0
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.1
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.2
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.3
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/british.0
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/british.1
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/british.2

by :

jar:nbinst:///modules/dict/aspell-frwl.zip!/aspell_dump_fr_FR.txt

Step 4.10 : rename and edit the "release/module/dict/dictionary_en_US.description" file

Rename the "dictionary_en_US.description" file to "dictionary_fr_CH.description".

After that, replace :

jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.0
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.1
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.2
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/english.3
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/american.0
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/american.1
jar:nbinst:///modules/dict/ispell-enwl-3.1.20.zip!/american.2

by :

jar:nbinst:///modules/dict/aspell-frwl.zip!/aspell_dump_fr_CH.txt

Step 5 : make the NBM file and test it

You can now launch the Build action to compile the project, and the Create NBM action to package your plugin into a NBM file ("build/org-netbeans-modules-spellchecker-dictionary_fr.nbm"). To test it :

  • go to the Plugins Manager ("Tools" / "Plugins"), the "Downloaded" tab, the "Add Plugins..." button, load your NBM file and confirm : your plugin is now installed !
  • you can now change the spellchecker default locale, open a text file and type a letter (only !), wait a few seconds to let Netbeans generate a cache file for the selected locale (if you don't wait, the cache creation will fail and the spellchecker won't work), and try to use the spellchecker correction.
    This is explained in my French Dictionary Plugin page.

Nota : If you don't wait the cache creation, the spellchecker won't work for the selected locale. You can go to your ".netbeans/7.x.y/var/cache/dict/" directory and delete the corresponding ".trie1" (or ".trie2") file. Restart NetBeans to let it to recreate a cache file.

Step 6 : (optional) sign the NBM file and submit it to the community for validation

You can now publish your plugin on the NetBeans Plugins Portal (don't forget create an account). To make it available in the NetBeans Plugins Manager (Tools / Plugins), you have to submit it to validation.
Firstly, you have to sign your plugin (generate a certificate file and sign your plugin) : you'll find a tutorial at http://wiki.netbeans.org/DevFaqSignNbm. Example : keytool -genkey -storepass PASSWORD -alias ALIAS -keystore FOO.cert -validity 3651 (it will create the "FOO.cert" certificate file with a 3651 days validity, the "ALIAS" alias an the "PASSWORD" password. The tool will ask you additional information).

Then, you can now upload your plugin to the NetBeans Plugins Portal and ask for a validation.
Once validated, your plugin will be available in the NetBeans Plugins Manager.

Hortonworks DataFlow is an integrated platform that makes data ingestion fast, easy, and secure. Download the white paper now.  Brought to you in partnership with Hortonworks

Topics:

Published at DZone with permission of Jonathan Lermitage. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}