{"id":6,"date":"2020-04-28T22:34:00","date_gmt":"2020-04-28T22:34:00","guid":{"rendered":""},"modified":"2021-02-22T01:14:18","modified_gmt":"2021-02-22T01:14:18","slug":"using-personal-custom-dictionary-with","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2020\/04\/using-personal-custom-dictionary-with.html","title":{"rendered":"Using Personal Custom Dictionary with Aspell and Pspell"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>Lately I was building a spell checker with PHP and I wanted to use my own dictionary with only specific words. Pspell in PHP sounded like the easiest way, however, by default, Pspell uses Aspell&#8217;s dictionary.<br \/>\nIn this post, I&#8217;m going to show you how to disable the default Aspell dictionary and use a custom made dictionary instead.<\/p>\n<p><a name=\"more\"><\/a><\/p>\n<h2 style=\"text-align: left;\">Requirements:<\/h2>\n<ul style=\"text-align: left;\">\n<li>Root access to your Linux server.<\/li>\n<li>Aspell already installed (This should be super easy on CentOS and Ubuntu)<\/li>\n<li>Aspell language dictionary installed<\/li>\n<li>PHP Pspell extension enabled<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2 style=\"text-align: left;\">In Your Server&#8217;s Terminal<\/h2>\n<p>Let&#8217;s find where the default data directory is:<\/p>\n<pre>aspell config<\/pre>\n<p>Look for data-dir entry for the path, it&#8217;s usually \/usr\/lib64\/aspell-0.60 on CentOS 7, and navigate to it<\/p>\n<pre>cd \/usr\/lib64\/aspell-0.60<\/pre>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2020\/04\/default-2Baspell-2Bdir.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2020\/04\/default-2Baspell-2Bdir-300x33.jpg\" width=\"400\" height=\"43\" border=\"0\" data-original-height=\"73\" data-original-width=\"673\" \/><\/a><\/div>\n<p>Create a new default wordlist, with at least 1 word<\/p>\n<pre>vim wordlist<\/pre>\n<p>Add 1 word, press &#8220;i&#8221; to write, and &#8220;wq&#8221; to exit back to command line<\/p>\n<p>I&#8217;ll create a new master dictionary called en_techdev (English language)<\/p>\n<pre>aspell --lang=en create master .\/en_techdev.rws &lt; wordlist<\/pre>\n<pre>vim en_techdev.multi<\/pre>\n<p>And add the following<br \/>\n<i>add en_techdev.rws<\/i><\/p>\n<p>Run<\/p>\n<pre>aspell -d en_techdev.rws -l en\u00a0 config<\/pre>\n<p>You will see the new master dictionary is our en_techdev.rws<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2020\/04\/aspell-2Bcustom-2Bmaster-2Bdefault.jpg\"><img decoding=\"async\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2020\/04\/aspell-2Bcustom-2Bmaster-2Bdefault.jpg\" border=\"0\" data-original-height=\"109\" data-original-width=\"525\" \/><\/a><\/div>\n<p>You can use dump dicts to view your new dictionary<\/p>\n<pre>aspell dump dicts<\/pre>\n<h2 style=\"text-align: left;\">PHP<\/h2>\n<p>In PHP, just use it as follows<\/p>\n<pre>&lt;?php<\/pre>\n<p>$pspell_link = pspell_new(&#8220;en_techdev&#8221;);<\/p>\n<p>You can add a new list to the dictionary<\/p>\n<pre>$pspell_config = pspell_config_create(\"en_TECHDEV\");<\/pre>\n<p>pspell_config_personal($pspell_config, &#8220;\/path\/toYourWebsiteDir\/pspell\/en_techdev.pws&#8221;);<\/p>\n<p>$pspell_link = pspell_new_config($pspell_config);<\/p>\n<p>pspell_add_to_personal($pspell_link, &#8220;newWord&#8221;);<\/p>\n<p>pspell_add_to_personal($pspell_link, &#8220;newWord2&#8221;);<\/p>\n<p>pspell_save_wordlist($pspell_link);<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Lately I was building a spell checker with PHP and I wanted to use my own dictionary with only specific words. Pspell in PHP sounded like the easiest way, however, by default, Pspell uses Aspell&#8217;s dictionary. In this post, I&#8217;m going to show you how to disable the default Aspell dictionary and use a custom [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,22],"tags":[134,136,135],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-linux","category-php","tag-aspell","tag-dictionary","tag-psepll"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=6"}],"version-history":[{"count":3,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":154,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions\/154"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}