Class: CrossLanguageSpotter::ContextReferencesProducer

Inherits:
Object
  • Object
show all
Defined in:
lib/crosslanguagespotter/methods/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ ContextReferencesProducer

Returns a new instance of ContextReferencesProducer.



78
79
80
81
82
# File 'lib/crosslanguagespotter/methods/context.rb', line 78

def initialize(parameters)
    @threshold = parameters[:threshold]
    @verbose = parameters[:verbose]
    @alpha = parameters[:alpha]
end

Instance Attribute Details

#verboseObject

Returns the value of attribute verbose.



76
77
78
# File 'lib/crosslanguagespotter/methods/context.rb', line 76

def verbose
  @verbose
end

Instance Method Details

#points_map(project) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/crosslanguagespotter/methods/context.rb', line 84

def points_map(project)
    # fill points map
    points_map = PointsMap.new(@alpha)
    block1 = Proc.new do |ni,nj|
        context_ni = context(ni)
        context_nj = context(nj)
        shared_ctx = context_nj.intersection(context_ni).to_a
        shared_ctx.each do |shared_ctx_entry|
            v = shared_ctx_entry[:value]
            context_ni.declarators_per_value(v).each do |di|
                context_nj.declarators_per_value(v).each do |dj|
                    points_map.register_child_contribute(Pair.new(di,dj))
                end
            end
        end
        points_map.register_context_contribute(Pair.new(ni,nj),shared_ctx.count)
    end     
    project.iter_over_shared_ids_instances {|ni,nj| block1.call(ni,nj) }
    points_map
end

#produce_set(project) ⇒ Object

It should produce a set of node ids



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/crosslanguagespotter/methods/context.rb', line 106

def produce_set(project)
    set = Set.new
    puts "Context method:" if @verbose
            
    points_map = points_map(project)
    
    # look into points map
    points_map.each(@threshold).each do |pair,value|
        f = pair.first
        s = pair.second
        id_i = NodeId.from_node(f)
        id_j = NodeId.from_node(s)
        set << CrossLanguageRelation.new([id_i,id_j])
    end

    puts "Context method, set produced: #{set.count} elements" if @verbose
    set
end