Skip to content
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib stop pulling in words once we have ran out of words to pull
spec
.document
.gitignore Initial commit to n_gram.
LICENSE Initial commit to n_gram.
README.rdoc initial commit
Rakefile
VERSION Version bump to 0.0.1
n_gram.gemspec Regenerated gemspec for version 0.0.1

README.rdoc

NGram

A simple NGram generator - en.wikipedia.org/wiki/N-gram.

Install

gem sources -a http://gemcutter.org
sudo gem install n_gram

How To Use

A single N-Gram

require 'rubygems'
require 'n_gram'

data = ['here is some text', 'here is more text']

n_gram = NGram.new(data, :n => 2)

# To see the N-Gram of the collection
ngram.ngrams_of_all_data
  #=> {2 => {'here is' => 2 etc...}}

# To see the N-Grams of individual inputs
# If we want the N-Gram of data[0]
ngram.ngrams_of_inputs[0]
  #=> {2 => {'here is' => 1 etc...}}

Multiple N-Grams

require 'rubygems'
require 'n_gram'

data = ['here is some text', 'here is more text']

n_gram = NGram.new(data, :n => [2,3])

# To see the N-Gram of the collection
ngram.ngrams_of_all_data
  #=> {2 => {'here is' => 2 etc...}, 3 => {'here is some' => 1 etc...}}

# To see the N-Grams of individual inputs
# If we want the N-Gram of data[0]
ngram.ngrams_of_inputs[0]
  #=> {2 => {'here is' => 1 etc...}, 3 => {'here is some' => 1 etc...}}

Copyright

Copyright © 2009 Red Davis. See LICENSE for details.

Something went wrong with that request. Please try again.