<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>ruby on rails spell checking on random thoughts</title><link>https://awesomeprogrammer.com/categories/ruby-on-rails-spell-checking/</link><description>Recent content in ruby on rails spell checking on random thoughts</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Mon, 26 Nov 2012 00:00:00 +0000</lastBuildDate><atom:link href="https://awesomeprogrammer.com/categories/ruby-on-rails-spell-checking/index.xml" rel="self" type="application/rss+xml"/><item><title>Hook up aspell dictionary into your rails app</title><link>https://awesomeprogrammer.com/blog/2012/11/26/hook-up-aspell-dictionary-into-your-rails-app/</link><pubDate>Mon, 26 Nov 2012 00:00:00 +0000</pubDate><guid>https://awesomeprogrammer.com/blog/2012/11/26/hook-up-aspell-dictionary-into-your-rails-app/</guid><description><![CDATA[<p>How to check spelling in your rails app in three quick steps.</p>
<h4 id="1-install-aspell-doh">1. Install aspell (d&rsquo;oh)</h4>
<p>with desired dictionary/ies.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo apt-get install aspell aspell-en aspell-pl
</span></span></code></pre></div><h4 id="2-install-ffi-aspell1">2. Install <a href="https://rubygems.org/gems/ffi-aspell">ffi-aspell</a></h4>
<p>(I can&rsquo;t recommend <a href="https://rubygems.org/gems/raspell">respell</a> as it&rsquo;s quite dated and you probably will encounter some annoying utf-8 encoding problems)</p>
<h4 id="3-wake-up">3. Wake up</h4>
<p>your inner grammar-nazi!</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>  speller <span style="color:#f92672">=</span> <span style="color:#66d9ef">FFI</span><span style="color:#f92672">::</span><span style="color:#66d9ef">Aspell</span><span style="color:#f92672">::</span><span style="color:#66d9ef">Speller</span><span style="color:#f92672">.</span>new(<span style="color:#e6db74">&#39;en&#39;</span>, <span style="color:#e6db74">encoding</span>: <span style="color:#e6db74">&#39;utf-8&#39;</span>)
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># you may be also interested in those two options for starter:</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># speller.set(&#39;ignore-case&#39;, &#39;true&#39;)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># speller.suggestion_mode = &#39;normal&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;I have no ideaz wut&#39;s goign on&#34;</span><span style="color:#f92672">.</span>gsub(<span style="color:#e6db74">/[\w\&#39;]+/</span>) <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>word<span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span>    puts <span style="color:#e6db74">&#34;&#39;</span><span style="color:#e6db74">#{</span>word<span style="color:#e6db74">}</span><span style="color:#e6db74">&#39; seems incorrect, did you mean: &#39;</span><span style="color:#e6db74">#{</span>speller<span style="color:#f92672">.</span>suggestions(word)<span style="color:#f92672">.</span>first<span style="color:#e6db74">}</span><span style="color:#e6db74">&#39;?&#34;</span> <span style="color:#66d9ef">unless</span> speller<span style="color:#f92672">.</span>correct?(word)
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">end</span>
</span></span></code></pre></div><pre tabindex="0"><code>ideaz&#39; seems incorrect, did you mean: &#39;ideas&#39;?
&#39;wut&#39;s&#39; seems incorrect, did you mean: &#39;Wit&#39;s&#39;?
&#39;goign&#39; seems incorrect, did you mean: &#39;going&#39;?
</code></pre><p>It&rsquo;s a nice feature that you can use eg. for suggesting/validating user&rsquo;s search queries.</p>]]></description><content:encoded><![CDATA[<p>How to check spelling in your rails app in three quick steps.</p>
<h4 id="1-install-aspell-doh">1. Install aspell (d&rsquo;oh)</h4>
<p>with desired dictionary/ies.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo apt-get install aspell aspell-en aspell-pl
</span></span></code></pre></div><h4 id="2-install-ffi-aspell1">2. Install <a href="https://rubygems.org/gems/ffi-aspell">ffi-aspell</a></h4>
<p>(I can&rsquo;t recommend <a href="https://rubygems.org/gems/raspell">respell</a> as it&rsquo;s quite dated and you probably will encounter some annoying utf-8 encoding problems)</p>
<h4 id="3-wake-up">3. Wake up</h4>
<p>your inner grammar-nazi!</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span>  speller <span style="color:#f92672">=</span> <span style="color:#66d9ef">FFI</span><span style="color:#f92672">::</span><span style="color:#66d9ef">Aspell</span><span style="color:#f92672">::</span><span style="color:#66d9ef">Speller</span><span style="color:#f92672">.</span>new(<span style="color:#e6db74">&#39;en&#39;</span>, <span style="color:#e6db74">encoding</span>: <span style="color:#e6db74">&#39;utf-8&#39;</span>)
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># you may be also interested in those two options for starter:</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># speller.set(&#39;ignore-case&#39;, &#39;true&#39;)</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e"># speller.suggestion_mode = &#39;normal&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#e6db74">&#34;I have no ideaz wut&#39;s goign on&#34;</span><span style="color:#f92672">.</span>gsub(<span style="color:#e6db74">/[\w\&#39;]+/</span>) <span style="color:#66d9ef">do</span> <span style="color:#f92672">|</span>word<span style="color:#f92672">|</span>
</span></span><span style="display:flex;"><span>    puts <span style="color:#e6db74">&#34;&#39;</span><span style="color:#e6db74">#{</span>word<span style="color:#e6db74">}</span><span style="color:#e6db74">&#39; seems incorrect, did you mean: &#39;</span><span style="color:#e6db74">#{</span>speller<span style="color:#f92672">.</span>suggestions(word)<span style="color:#f92672">.</span>first<span style="color:#e6db74">}</span><span style="color:#e6db74">&#39;?&#34;</span> <span style="color:#66d9ef">unless</span> speller<span style="color:#f92672">.</span>correct?(word)
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">end</span>
</span></span></code></pre></div><pre tabindex="0"><code>ideaz&#39; seems incorrect, did you mean: &#39;ideas&#39;?
&#39;wut&#39;s&#39; seems incorrect, did you mean: &#39;Wit&#39;s&#39;?
&#39;goign&#39; seems incorrect, did you mean: &#39;going&#39;?
</code></pre><p>It&rsquo;s a nice feature that you can use eg. for suggesting/validating user&rsquo;s search queries.</p>]]></content:encoded></item></channel></rss>