Giter Site home page Giter Site logo

dadario / stemmify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raypereda/stemmify

1.0 1.0 0.0 301 KB

Ruby module that converts a word to its approximate root form with the Porter stemmer. For example, observing and observation reduce to observ.

Home Page: http://tartarus.org/martin/PorterStemmer/

stemmify's Introduction

Stemmify

Description

This is a Rails gem for reducing words to their roots. For example, all the following words to are stemmed to “observ”, which is not a real word in this case: observance observances observancy observant observants observation observe observed observer observers observing observingly

The algorithm used here is based on the Porter stemmer. You can read more about Martin Porter’s stemmer at

tartarus.org/~martin/PorterStemmer/

Martin Porter explains:

The Porter stemming algorithm (or ‘Porter stemmer’) is a process for removing the commoner morphological and inflexional endings from words in English. Its main use is as part of a term normalisation process that is usually done when setting up Information Retrieval systems.

Install

$ sudo gem install stemmify

or

$ gem install stemmify

Note that while the source code is hosted on github, the actual gem is hosted on RubyGem.org.

Usage

Let’s say you are building some sort of search tool. You want searches for “observations” and “observer” to all bring up the same items. When you are building you index, you can map all the words to their roots using the stem method.

Here’s an example usage:

require 'stemmify'
print("observations".stem) # ==> "observ"

You can use stemmify as a command line tool:

$ stem input_file.txt
$ printf "I\nwalked\nin\nthe\nforest\n.\n" | stem

Both the file based input and the input taken from the stdin should be tokenized, i.e. provide one token per line, tokens should be delimeted e.g. by a new line feed.

For tokenization consider using a tokenizer, for instance the tokenizer gem.

Test Suite

This test is based on the sample input and output text from Martin Porter website. It includes 23532 test words and their expected stem results. To run the test, just type

rake test

Thanks

Dave Thomas from pragprog.com made speed improvements to this code before it was packaged as a gem.

License

Copyright © 2011 Ray Pereda

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

stemmify's People

Contributors

raypereda avatar arbox avatar

Stargazers

Adriano Dadario avatar

Watchers

James Cloos 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.