From 54d271fef2d3ba1b1ba87d6a40f4bf53e2e0d4f6 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Thu, 18 Aug 2016 10:23:17 +0200 Subject: non-windowed RR --- repetition-rate | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 repetition-rate 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 + -- cgit v1.2.3