Skip to content

Instantly share code, notes, and snippets.

@automatthew
Created August 14, 2009 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save automatthew/168001 to your computer and use it in GitHub Desktop.
Save automatthew/168001 to your computer and use it in GitHub Desktop.
like ngrams, but for phrases
#!/usr/bin/env ruby
require 'enumerator'
max = ARGV[0].to_i || 5
while string = STDIN.gets
bits = string.chomp.split
(2..max).each do |i|
bits.each_cons(i) do |nlog|
puts nlog.join(" ")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment