lightmodels 0.1.2-java → 0.2.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +8 -0
- data/Rakefile +9 -0
- data/lib/lightmodels/info_extraction.rb +133 -0
- data/lib/lightmodels/jsonser_nav.rb +12 -12
- data/lib/lightmodels/model_building.rb +66 -1
- data/lib/lightmodels/monkey_patching.rb +30 -0
- data/lib/lightmodels/parsing.rb +186 -0
- data/lib/lightmodels/query_serialized.rb +81 -0
- data/lib/lightmodels/rgen_ext.rb +153 -0
- data/lib/lightmodels/serialization.rb +11 -28
- data/lib/lightmodels/version.rb +3 -0
- data/lightmodels.gemspec +29 -0
- data/test/data/node_setCompleted.json +443 -0
- data/test/test_helper.rb +8 -0
- data/test/test_info_extraction.rb +90 -0
- data/test/test_queryserialized.rb +40 -0
- data/test/test_serialization.rb +64 -0
- metadata +122 -32
- checksums.yaml +0 -7
- data/lib/lightmodels/model.rb +0 -11
- data/lib/lightmodels/query.rb +0 -36
- data/lib/lightmodels/stats.rb +0 -69
data/lib/lightmodels/stats.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'emf_jruby'
|
2
|
-
|
3
|
-
module LightModels
|
4
|
-
|
5
|
-
class CountingMap
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@map = {}
|
9
|
-
@sum_values = 0
|
10
|
-
end
|
11
|
-
|
12
|
-
def inc(key)
|
13
|
-
@map[key] = 0 unless @map[key]
|
14
|
-
@map[key] = @map[key]+1
|
15
|
-
@sum_values += 1
|
16
|
-
end
|
17
|
-
|
18
|
-
def value(key)
|
19
|
-
@map[key] = 0 unless @map[key]
|
20
|
-
@map[key]
|
21
|
-
end
|
22
|
-
|
23
|
-
# number of times the value appeared divived by total frequency
|
24
|
-
def p(key)
|
25
|
-
@map[key].to_f/total_frequency.to_f
|
26
|
-
end
|
27
|
-
|
28
|
-
def each(&block)
|
29
|
-
@map.each(&block)
|
30
|
-
end
|
31
|
-
|
32
|
-
def total_frequency
|
33
|
-
@sum_values
|
34
|
-
end
|
35
|
-
|
36
|
-
def n_values
|
37
|
-
@map.count
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.entropy(counting_map)
|
43
|
-
s = 0.0
|
44
|
-
counting_map.each do |k,v|
|
45
|
-
p = counting_map.p(k)
|
46
|
-
s += p*Math.log(p)
|
47
|
-
end
|
48
|
-
-s
|
49
|
-
end
|
50
|
-
|
51
|
-
def idf(n,n_docs)
|
52
|
-
Math.log(n_docs.to_f/n.to_f)
|
53
|
-
end
|
54
|
-
|
55
|
-
def combine_self(arr,&op)
|
56
|
-
for i in 0..(arr.count-2)
|
57
|
-
for j in (i+1)..(arr.count-1)
|
58
|
-
op.call(arr[i],arr[j])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def combine(arr1,arr2,&op)
|
64
|
-
arr1.each do |el1|
|
65
|
-
arr2.each {|el2| op.call(el1,el2)}
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|