Class: CrossLanguageSpotter::TverskyReferencesProducer
- Inherits:
-
Object
- Object
- CrossLanguageSpotter::TverskyReferencesProducer
- Defined in:
- lib/crosslanguagespotter/methods/tversky.rb
Instance Attribute Summary collapse
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(parameters) ⇒ TverskyReferencesProducer
constructor
A new instance of TverskyReferencesProducer.
-
#produce_set(project) ⇒ Object
It should produce a set of node ids.
- #tversky_coefficient(context_ni, context_nj) ⇒ Object
Constructor Details
#initialize(parameters) ⇒ TverskyReferencesProducer
Returns a new instance of TverskyReferencesProducer.
11 12 13 14 |
# File 'lib/crosslanguagespotter/methods/tversky.rb', line 11 def initialize(parameters) @threshold = parameters[:threshold] @alpha = parameters[:alpha] end |
Instance Attribute Details
#verbose ⇒ Object
Returns the value of attribute verbose.
9 10 11 |
# File 'lib/crosslanguagespotter/methods/tversky.rb', line 9 def verbose @verbose end |
Instance Method Details
#produce_set(project) ⇒ Object
It should produce a set of node ids
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/crosslanguagespotter/methods/tversky.rb', line 17 def produce_set(project) set = Set.new puts "Tversky method:" if @verbose block = Proc.new do |ni,nj| context_ni = context(ni).values & project.shared_ids context_nj = context(nj).values & project.shared_ids j = tversky_coefficient(context_ni,context_nj) if j>=@threshold id_i = NodeId.from_node(ni) id_j = NodeId.from_node(nj) puts " * '#{id_i.file}':#{id_i.index} -> '#{id_j.file}':#{id_j.index}" if @verbose set << CrossLanguageRelation.new([id_i,id_j]) end end project.iter_over_shared_ids_instances {|ni,nj| block.call(ni,nj) } puts "Tversky method, set produced: #{set.count} elements" if @verbose set end |
#tversky_coefficient(context_ni, context_nj) ⇒ Object
36 37 38 39 40 |
# File 'lib/crosslanguagespotter/methods/tversky.rb', line 36 def tversky_coefficient(context_ni,context_nj) shared = context_ni & context_nj others = (context_ni.count-shared.count)+(context_nj.count-shared.count) shared.count.to_f/(shared.count.to_f+@alpha*others.to_f) end |