Coder Social home page Coder Social logo

fonetica's Introduction

fonetica

Fonetica implements the BuscaBR algorithm to match misspelled or ambiguous names at Brazil.

The Story

One day I had to perform a phonetic search on a people database using the Soundex alghoritm but didn't work for names at Brazil like "Wagner Batista" and "Vagner Baptista".

Then Google suggested me to read the BuscaBR algorithm.

Usage

require 'fonetica'

'wagner batista'.foneticalize #=> "VM BT"
'vagner baptista'.foneticalize #=> "VM BT"

Using with ActiveRecord

You can use the fonetica to search on ActiveRecord like this:

class Person < ActiveRecord::Base
  before_save :foneticalize

  def self.search(name)
    where(arel_table[:fonetica].matches("#{name.foneticalize}%"))
  end

  protected

  def foneticalize
    self.fonetica = name.foneticalize
  end
end

If you want to match any part, you should change scope to:

def self.search
  where(arel_table[:fonetica].matches("%#{name.foneticalize}%"))
end

Remember to add a index on fonetica column:

class AddFoneticaToPeople < ActiveRecord::Migration
  def change
    add_column :people, :fonetica, :string
    add_index :people, :fonetica
  end
end

How to contribute

Please ensure that you provide appropriate test coverage and ensure the documentation is up-to-date. Bonus points if you perform your changes in a clean topic branch rather than master, and if you create a pull request for your changes to be discussed and reviewed.

Please also keep your commits atomic so that they are more likely to apply cleanly. That means that each commit should contain the smallest possible logical change. Don't commit two features at once, don't update the gemspec at the same time you add a feature, don't fix a whole bunch of whitespace in a file at the same time you change a few lines, etc, etc.

Development environment

$ git clone https://github.com/sobrinho/fonetica
$ cd fonetica
$ bundle install
$ rake test

License

Fonetica is hosted on Github: https://github.com/sobrinho/fonetica, where your contributions, forkings, comments and feedback are greatly welcomed.

Copyright (c) 2010-2014 Gabriel Sobrinho, released under the MIT license.

fonetica's People

Contributors

sobrinho avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.