dejunk 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78bada0220a075c407f09e81eeb3602b669f9c64a6b0107bf26764c2721c1f0c
4
- data.tar.gz: 189aa6798ca085cee985df90a28c7efa42c57c0574ef6652382992e0ef0ff41c
3
+ metadata.gz: 06c7eece281db7bb6218b0f3a56da9541a5830f8b7d0e739daf08b6d9f6b004d
4
+ data.tar.gz: b2dc0dd0f457164085eb19e418f75db4bca6d7cb0a315fa1e5bc0f9fad2ac3aa
5
5
  SHA512:
6
- metadata.gz: 719a2c5bcc2f9a9c201f8856fbd5a219fe7b1b497c1c585d3c49c6104d4b37099fef3aef7635dc2fd5b054c1ae25fbd91c98b9bf569e1293fb9ee2c68049a10e
7
- data.tar.gz: 0a0a75d55d940cd8e757a458385ab603541150a1a94e42532c9628a26b46be1b198220d781fddcb9d4d3da59ced552d7a8b056c7934c7192437420288298110a
6
+ metadata.gz: 367bf74302776bf03dbef89b2f5aad58c5f446511b30ae2cfc765372b86a9600ef9e2faf7d4b639629938ebfc59dd9c7d2a1720564dcfd94aeedd05235b023cb
7
+ data.tar.gz: a47f13d1b05d25641329ac4ed963288096e84a30186a16789facef75ecb5709137987d65b7cf727b935c71a16f01481b39b50e46bae8154cdd5ea28843ac1b3c
@@ -0,0 +1,15 @@
1
+ name: build
2
+
3
+ on:
4
+ push:
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v7
11
+ - uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: .tool-versions
14
+ bundler-cache: true
15
+ - run: bundle exec rspec
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 4.0.5
@@ -1,3 +1,3 @@
1
1
  module Dejunk
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
data/lib/dejunk.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "active_support/core_ext/object/blank"
2
2
  require "active_support/core_ext/string"
3
- require "bigdecimal"
4
3
  require "yaml"
5
4
 
6
5
  require "dejunk/version"
@@ -133,17 +132,16 @@ module Dejunk
133
132
 
134
133
  return 0 unless bigrams.present?
135
134
 
136
- prob_bigrams_given_mashing = bigrams.
137
- map { |bigram| BigDecimal(mashing_probability(bigram).to_s) }.
138
- inject(&:*)
135
+ # Work in log space because the raw products of per-bigram probabilities
136
+ # underflow Float.
137
+ log_prob_given_mashing = bigrams.sum { |bigram| Math.log(mashing_probability(bigram)) }
138
+ log_prob_given_corpus = bigrams.sum { |bigram| Math.log(corpus_probability(bigram)) }
139
139
 
140
- prob_bigrams_given_corpus = bigrams.
141
- map { |bigram| BigDecimal(corpus_probability(bigram).to_s) }.
142
- inject(&:*)
140
+ # Equivalent to mashing / (mashing + corpus), with the priors applied.
141
+ log_odds_ratio = log_prob_given_corpus + Math.log(1 - apriori_probability_of_mashing) -
142
+ log_prob_given_mashing - Math.log(apriori_probability_of_mashing)
143
143
 
144
- numerator = prob_bigrams_given_mashing * apriori_probability_of_mashing
145
-
146
- numerator / (numerator + prob_bigrams_given_corpus * (1 - apriori_probability_of_mashing))
144
+ 1.0 / (1.0 + Math.exp(log_odds_ratio))
147
145
  end
148
146
 
149
147
  def normalize_for_comparison(string)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dejunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Judd
@@ -57,9 +57,10 @@ executables: []
57
57
  extensions: []
58
58
  extra_rdoc_files: []
59
59
  files:
60
- - ".circleci/config.yml"
60
+ - ".github/workflows/build.yml"
61
61
  - ".gitignore"
62
62
  - ".rspec"
63
+ - ".tool-versions"
63
64
  - ".travis.yml"
64
65
  - Gemfile
65
66
  - LICENSE
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  - !ruby/object:Gem::Version
89
90
  version: '0'
90
91
  requirements: []
91
- rubygems_version: 3.6.9
92
+ rubygems_version: 4.0.10
92
93
  specification_version: 4
93
94
  summary: Detect keyboard mashing and other junk in your data.
94
95
  test_files: []
data/.circleci/config.yml DELETED
@@ -1,15 +0,0 @@
1
- version: 2.1
2
-
3
- jobs:
4
- build:
5
- docker:
6
- - image: cimg/ruby:3.4.8
7
- steps:
8
- - checkout
9
- - run: bundle install
10
- - run: bundle exec rspec
11
-
12
- workflows:
13
- build_and_test:
14
- jobs:
15
- - build