Project

improvise

0.0
No commit activity in last 3 years
No release in over 3 years
Improvise generates random words by learning from existing text.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.3
~> 2.0
~> 0.8
~> 0.8

Runtime

~> 2.10
~> 1.8
< 1.0, >= 0.0.9
< 1.0, >= 0.9.3
 Project Readme

Improvise

Improvise generates random words by learning from existing text.

Installation

Add this line to your application's Gemfile:

gem 'improvise'

And then execute:

$ bundle

Or install it yourself as:

$ gem install improvise

Usage

Require the 'improvise' gem:

require 'improvise'

Learn

Create a new dictionary with depth 3:

dict = Improvise::ForwardDictionary.new(3)

Or create a reversed dictionary with depth 3:

dict = Improvise::ReverseDictionary.new(3)

Learn from a list of existing words:

dict.learn!([
    'ruby', 
    'sapphire', 
    'pearl', 
    'diamond', 
    'amethyst', 
    'topaz', 
    'emerald'
])

Generate

Generate a 6-letter word:

dict.generate_word(6)

Generate a 7-letter word, starting with 'top':

dict.generate_word(7, 'top')

Store

Write a dictionary in Ruby's Marshal format to a file called 'dict.bin':

dict_file = File.open('dict.bin', 'w')
Improvise::IO::DictionaryWriter.write(dict_file, dict)

Write a dictionary in Ruby's Marshal format, gzipped, to a file called 'dict.bin.gz':

dict_file = File.open('dict.bin.gz', 'w')
Improvise::IO::DictionaryWriter.write(dict_file, dict, gzip: true)

Write a dictionary in json format, gzipped, to a file called 'dict.json.gz':

dict_file = File.open('dict.json.gz', 'w')
Improvise::IO::DictionaryWriter.write(dict_file, dict, format: :json, gzip: true)

Note: writing a dictionary closes the passed IO object.

Load

Restore a dictionary from a file called 'dict.bin' in Ruby's Marshal format:

dict_file = File.open('dict.bin', 'r')
dict = Improvise::IO::DictionaryReader.read(dict_file)

Restore a dictionary from a file called 'dict.bin.gz' in Ruby's Marshal format, gzipped:

dict_file = File.open('dict.bin.gz', 'r')
dict = Improvise::IO::DictionaryReader.read(dict_file, gzip: true)

Restore a dictionary from a file called 'dict.json.gz' in json format, gzipped:

dict_file = File.open('dict.json.gz', 'r')
dict = Improvise::IO::DictionaryReader.read(dict_file, format: :json, gzip: true)

Note: reading a dictionary closes the passed IO object.

Command-line tool

A command-line interface to the library has been provided under the name 'improvise'. Run improvise --help to get a list of available commands.

Contributing

  1. Fork
  2. Branch (git checkout -b my-new-feature)
  3. Commit (git commit -am 'Added some feature')
  4. Push (git push origin my-new-feature)
  5. Pull request