Module: Clusta::Transforms
- Defined in:
- lib/clusta/transforms.rb,
lib/clusta/transforms/pm3d.rb,
lib/clusta/transforms/import.rb,
lib/clusta/transforms/prune_edges.rb,
lib/clusta/transforms/edges_to_degrees.rb,
lib/clusta/transforms/edges_to_neighborhoods.rb,
lib/clusta/transforms/neighborhoods_to_degree_pairs.rb,
lib/clusta/transforms/degree_pairs_to_assortativities.rb
Defined Under Namespace
Modules: DegreePairsToAssortativities, EdgesToDegrees, EdgesToNeighborhoods, Import, NeighborhoodsToDegreePairs, Pm3d, PruneEdges
Class Method Summary
collapse
Class Method Details
.default_script ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/clusta/transforms.rb', line 29
def self.default_script
Class.new(Wukong::Script).tap do |c|
c.class_eval do
def local_mode_sort_commandline
"sort -n -k2"
end
end
end
end
|
.from_name(name) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/clusta/transforms.rb', line 13
def self.from_name name
begin
const_get(Clusta.classify(name))
rescue NameError => e
raise Error.new("No such transform: '#{name}'")
end
end
|
.has_mapper?(transform) ⇒ Boolean
39
40
41
|
# File 'lib/clusta/transforms.rb', line 39
def self.has_mapper?(transform)
defined?(transform::Mapper)
end
|
.has_reducer?(transform) ⇒ Boolean
43
44
45
|
# File 'lib/clusta/transforms.rb', line 43
def self.has_reducer?(transform)
defined?(transform::Reducer)
end
|
.listing ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/clusta/transforms.rb', line 53
def self.listing
[].tap do |out|
out << "Known transforms:"
out << ''
names.sort.each do |transform_name|
transform = from_name(transform_name)
name_suffix = case
when has_mapper?(transform) && has_reducer?(transform) then ''
when (! has_mapper?(transform)) && has_reducer?(transform) then ' (reduce-only)'
when has_mapper?(transform) && (! has_reducer?(transform)) then ' (map-only)'
when (! has_mapper?(transform)) && (! has_reducer?(transform)) then ' (nothing)'
end
out << " #{transform_name}#{name_suffix}"
if transform.respond_to?(:help)
out << ''
out << " #{transform.help}"
end
out << ''
end
end.join("\n")
end
|
.load_from(path) ⇒ Object
76
77
78
79
|
# File 'lib/clusta/transforms.rb', line 76
def self.load_from path
class_eval(File.read(path), path)
register_transform(Clusta.require_name(path))
end
|
.names ⇒ Object
5
6
7
|
# File 'lib/clusta/transforms.rb', line 5
def self.names
@names ||= []
end
|
9
10
11
|
# File 'lib/clusta/transforms.rb', line 9
def self.register_transform name
names << name
end
|
.script_for(transform) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/clusta/transforms.rb', line 21
def self.script_for transform
mapper = transform::Mapper if defined?(transform::Mapper)
reducer = transform::Reducer if defined?(transform::Reducer)
options = (transform.respond_to?(:options) ? transform.options : {})
script = defined?(transform::Script) ? transform::Script : default_script
script.new(mapper, reducer, options)
end
|