summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2016-08-18 10:23:17 +0200
committerPatrick Simianer <p@simianer.de>2016-08-18 10:23:17 +0200
commit54d271fef2d3ba1b1ba87d6a40f4bf53e2e0d4f6 (patch)
tree22d5f2bf4ccfc4bfe077bb72a69866e543aa1d05
parent2b1d7f881c19c4d4b5afae194e02d3300c7675d0 (diff)
non-windowed RR
-rwxr-xr-xrepetition-rate26
1 files changed, 26 insertions, 0 deletions
diff --git a/repetition-rate b/repetition-rate
new file mode 100755
index 0000000..b821782
--- /dev/null
+++ b/repetition-rate
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+
+require 'zipf'
+
+ng = [{},{},{},{}]
+
+while line = STDIN.gets
+ ngrams(line, 4) { |g|
+ if ng[g.size-1].has_key? g
+ ng[g.size-1][g] += 1
+ else
+ ng[g.size-1][g] = 1
+ end
+ }
+end
+
+rr = 1.0
+ng.each_with_index { |h,j|
+ singletons = ng[j].reject { |k,v| v > 1 }.size
+ rr *= (ng[j].size - singletons).to_f/ng[j].size.to_f
+}
+
+rr = rr**0.25
+
+puts rr
+