Permalink
Browse files

implement util.rb

  • Loading branch information...
1 parent b609eaa commit 7b4bab75d29d6c425d09e1b79bf15c52f3ab95b0 @xdite committed Oct 3, 2011
Showing with 16 additions and 0 deletions.
  1. +16 −0 util.rb
View
16 util.rb
@@ -0,0 +1,16 @@
+class XRange
+ def initialize(n) @n=n end
+ def each() 0.upto(@n-1){|i|yield i} end
+end
+
+def xrange(n) XRange.new(n) end
+
+def ngram(n, terms)
+
+ array = []
+ for i in xrange(terms.length - n + 1)
+ array << terms[i..i+n-1]
+ end
+
+ return array
+end

0 comments on commit 7b4bab7

Please sign in to comment.