ul-wukong 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +60 -0
- data/.gitmodules +6 -0
- data/.rspec +2 -0
- data/.travis.yml +19 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +17 -0
- data/Guardfile +12 -0
- data/LICENSE.md +95 -0
- data/NOTES-travis.md +31 -0
- data/README-old.md +422 -0
- data/README.md +1308 -0
- data/Rakefile +28 -0
- data/TODO.md +99 -0
- data/bin/cutc +30 -0
- data/bin/cuttab +5 -0
- data/bin/greptrue +6 -0
- data/bin/md5sort +20 -0
- data/bin/setcat +11 -0
- data/bin/tabchar +5 -0
- data/bin/uniq-ord +59 -0
- data/bin/uniqc +3 -0
- data/bin/wu +34 -0
- data/bin/wu-clean-encoding +31 -0
- data/bin/wu-date +13 -0
- data/bin/wu-datetime +13 -0
- data/bin/wu-hist +3 -0
- data/bin/wu-lign +186 -0
- data/bin/wu-local +4 -0
- data/bin/wu-plus +9 -0
- data/bin/wu-source +5 -0
- data/bin/wu-sum +31 -0
- data/diagrams/wu_local.dot +39 -0
- data/diagrams/wu_local.dot.png +0 -0
- data/examples/Gemfile +38 -0
- data/examples/README.md +9 -0
- data/examples/basic/string_reverser.rb +23 -0
- data/examples/basic/tiny_count.rb +8 -0
- data/examples/basic/word_count/accumulator.rb +26 -0
- data/examples/basic/word_count/tokenizer.rb +13 -0
- data/examples/basic/word_count/word_count.rb +6 -0
- data/examples/dataflow/scraper_macro_flow.rb +28 -0
- data/examples/deploy_pack/Gemfile +6 -0
- data/examples/deploy_pack/README.md +6 -0
- data/examples/deploy_pack/a/b/c/.gitkeep +0 -0
- data/examples/deploy_pack/app/processors/string_reverser.rb +5 -0
- data/examples/deploy_pack/config/environment.rb +1 -0
- data/examples/dsl/dataflow/fibonacci_series.rb +101 -0
- data/examples/dsl/dataflow/scraper_macro_flow.rb +28 -0
- data/examples/dsl/dataflow/simple.rb +12 -0
- data/examples/dsl/dataflow/telegram.rb +45 -0
- data/examples/dsl/workflow/cherry_pie.dot +97 -0
- data/examples/dsl/workflow/cherry_pie.md +104 -0
- data/examples/dsl/workflow/cherry_pie.png +0 -0
- data/examples/dsl/workflow/cherry_pie.rb +101 -0
- data/examples/empty/.gitkeep +0 -0
- data/examples/examples_helper.rb +9 -0
- data/examples/geo.rb +4 -0
- data/examples/geo/geo_grids.numbers +0 -0
- data/examples/geo/geolocated.rb +331 -0
- data/examples/geo/quadtile.rb +69 -0
- data/examples/geo/spec/geolocated_spec.rb +247 -0
- data/examples/geo/tile_fetcher.rb +77 -0
- data/examples/graph/implied_geolocation/README.md +63 -0
- data/examples/graph/minimum_spanning_tree/airfares_graphviz.rb +73 -0
- data/examples/improver/tweet_summary.rb +73 -0
- data/examples/loadable.rb +2 -0
- data/examples/munging/airline_flights/airline_flights.rake +83 -0
- data/examples/munging/airline_flights/airplane.rb +0 -0
- data/examples/munging/airline_flights/airport_id_unification.rb +129 -0
- data/examples/munging/airline_flights/airport_ok_chars.rb +4 -0
- data/examples/munging/airline_flights/indexable.rb +75 -0
- data/examples/munging/airline_flights/indexable_spec.rb +90 -0
- data/examples/munging/airline_flights/reconcile_airports.rb +142 -0
- data/examples/munging/airline_flights/tasks.rake +83 -0
- data/examples/munging/airline_flights/topcities.rb +167 -0
- data/examples/munging/geo/geo_json.rb +54 -0
- data/examples/munging/geo/geo_models.rb +69 -0
- data/examples/munging/geo/geonames_models.rb +107 -0
- data/examples/munging/geo/iso_codes.rb +172 -0
- data/examples/munging/geo/reconcile_countries.rb +124 -0
- data/examples/munging/geo/tasks.rake +71 -0
- data/examples/munging/wikipedia/articles/extract_articles-parsed.rb +79 -0
- data/examples/munging/wikipedia/articles/extract_articles-templated.rb +136 -0
- data/examples/munging/wikipedia/articles/textualize_articles.rb +54 -0
- data/examples/munging/wikipedia/articles/verify_structure.rb +43 -0
- data/examples/munging/wikipedia/articles/wp2txt-LICENSE.txt +22 -0
- data/examples/munging/wikipedia/articles/wp2txt_article.rb +259 -0
- data/examples/munging/wikipedia/articles/wp2txt_utils.rb +452 -0
- data/examples/munging/wikipedia/dbpedia/dbpedia_common.rb +5 -0
- data/examples/munging/wikipedia/dbpedia/dbpedia_extract_geocoordinates.rb +78 -0
- data/examples/munging/wikipedia/dbpedia/extract_links-cruft.rb +66 -0
- data/examples/munging/wikipedia/dbpedia/extract_links.rb +260 -0
- data/examples/munging/wikipedia/dbpedia/sameas_extractor.rb +20 -0
- data/examples/rake_helper.rb +97 -0
- data/examples/ruby_project/Gemfile +6 -0
- data/examples/ruby_project/README.md +6 -0
- data/examples/ruby_project/a/b/c/.gitkeep +0 -0
- data/examples/server_logs/geo_ip_mapping/munge_geolite.rb +82 -0
- data/examples/server_logs/logline.rb +95 -0
- data/examples/server_logs/models.rb +66 -0
- data/examples/server_logs/page_counts.pig +48 -0
- data/examples/server_logs/server_logs-01-parse-script.rb +13 -0
- data/examples/server_logs/server_logs-02-histograms-full.rb +33 -0
- data/examples/server_logs/server_logs-02-histograms-mapper.rb +14 -0
- data/examples/server_logs/server_logs-03-breadcrumbs-full.rb +71 -0
- data/examples/server_logs/server_logs-04-page_page_edges-full.rb +40 -0
- data/examples/serverlogs/geo_ip_mapping/munge_geolite.rb +82 -0
- data/examples/serverlogs/models/logline.rb +102 -0
- data/examples/serverlogs/parser/apache_parser_widget.rb +46 -0
- data/examples/serverlogs/visit_paths/common.rb +4 -0
- data/examples/serverlogs/visit_paths/page_counts.pig +48 -0
- data/examples/serverlogs/visit_paths/serverlogs-01-parse-script.rb +11 -0
- data/examples/serverlogs/visit_paths/serverlogs-02-histograms-full.rb +31 -0
- data/examples/serverlogs/visit_paths/serverlogs-02-histograms-mapper.rb +12 -0
- data/examples/serverlogs/visit_paths/serverlogs-03-breadcrumbs-full.rb +67 -0
- data/examples/serverlogs/visit_paths/serverlogs-04-page_page_edges-full.rb +38 -0
- data/examples/splitter.rb +94 -0
- data/examples/string_reverser.rb +7 -0
- data/examples/text/pig_latin/pig_latinizer.rb +35 -0
- data/examples/text/pig_latin/pig_latinizer_widget.rb +16 -0
- data/examples/text/regional_flavor/README.md +14 -0
- data/examples/text/regional_flavor/article_wordbags.pig +39 -0
- data/examples/text/regional_flavor/j01-article_wordbags.rb +4 -0
- data/examples/text/regional_flavor/simple_pig_script.pig +27 -0
- data/examples/twitter.rb +5 -0
- data/lib/hanuman.rb +36 -0
- data/lib/hanuman/graph.rb +97 -0
- data/lib/hanuman/graphvizzer.rb +206 -0
- data/lib/hanuman/graphvizzer/gv_models.rb +161 -0
- data/lib/hanuman/graphvizzer/gv_presenter.rb +97 -0
- data/lib/hanuman/link.rb +35 -0
- data/lib/hanuman/registry.rb +46 -0
- data/lib/hanuman/stage.rb +128 -0
- data/lib/hanuman/tree.rb +67 -0
- data/lib/wu/geo.rb +4 -0
- data/lib/wu/geo/geo_grids.numbers +0 -0
- data/lib/wu/geo/geolocated.rb +331 -0
- data/lib/wu/geo/quadtile.rb +69 -0
- data/lib/wu/graph/union_find.rb +62 -0
- data/lib/wu/model/reconcilable.rb +63 -0
- data/lib/wu/munging.rb +71 -0
- data/lib/wu/social/models/twitter.rb +31 -0
- data/lib/wu/wikipedia/models.rb +20 -0
- data/lib/wukong.rb +54 -0
- data/lib/wukong/dataflow.rb +43 -0
- data/lib/wukong/doc_helpers.rb +14 -0
- data/lib/wukong/doc_helpers/dataflow_handler.rb +29 -0
- data/lib/wukong/doc_helpers/field_handler.rb +91 -0
- data/lib/wukong/doc_helpers/processor_handler.rb +29 -0
- data/lib/wukong/driver.rb +214 -0
- data/lib/wukong/driver/event_machine_driver.rb +15 -0
- data/lib/wukong/driver/wiring.rb +68 -0
- data/lib/wukong/local.rb +42 -0
- data/lib/wukong/local/runner.rb +96 -0
- data/lib/wukong/local/stdio_driver.rb +104 -0
- data/lib/wukong/logger.rb +102 -0
- data/lib/wukong/model/faker.rb +136 -0
- data/lib/wukong/model/flatpack_parser/flat.rb +60 -0
- data/lib/wukong/model/flatpack_parser/flatpack.rb +4 -0
- data/lib/wukong/model/flatpack_parser/lang.rb +46 -0
- data/lib/wukong/model/flatpack_parser/parser.rb +55 -0
- data/lib/wukong/model/flatpack_parser/tokens.rb +130 -0
- data/lib/wukong/plugin.rb +48 -0
- data/lib/wukong/processor.rb +110 -0
- data/lib/wukong/rake_helper.rb +6 -0
- data/lib/wukong/runner.rb +169 -0
- data/lib/wukong/runner/boot_sequence.rb +123 -0
- data/lib/wukong/runner/code_loader.rb +52 -0
- data/lib/wukong/runner/command_runner.rb +44 -0
- data/lib/wukong/runner/deploy_pack_loader.rb +75 -0
- data/lib/wukong/runner/help_message.rb +42 -0
- data/lib/wukong/source.rb +33 -0
- data/lib/wukong/source/source_driver.rb +74 -0
- data/lib/wukong/source/source_runner.rb +38 -0
- data/lib/wukong/spec_helpers.rb +74 -0
- data/lib/wukong/spec_helpers/integration_tests.rb +150 -0
- data/lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb +207 -0
- data/lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb +97 -0
- data/lib/wukong/spec_helpers/shared_examples.rb +22 -0
- data/lib/wukong/spec_helpers/unit_tests.rb +135 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb +132 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb +169 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_runner.rb +60 -0
- data/lib/wukong/version.rb +3 -0
- data/lib/wukong/widget/echo.rb +55 -0
- data/lib/wukong/widget/extract.rb +122 -0
- data/lib/wukong/widget/filters.rb +452 -0
- data/lib/wukong/widget/logger.rb +56 -0
- data/lib/wukong/widget/operators.rb +82 -0
- data/lib/wukong/widget/reducers.rb +10 -0
- data/lib/wukong/widget/reducers/accumulator.rb +73 -0
- data/lib/wukong/widget/reducers/bin.rb +368 -0
- data/lib/wukong/widget/reducers/count.rb +73 -0
- data/lib/wukong/widget/reducers/group.rb +128 -0
- data/lib/wukong/widget/reducers/group_concat.rb +98 -0
- data/lib/wukong/widget/reducers/improver.rb +71 -0
- data/lib/wukong/widget/reducers/join_xml.rb +37 -0
- data/lib/wukong/widget/reducers/moments.rb +72 -0
- data/lib/wukong/widget/reducers/sort.rb +180 -0
- data/lib/wukong/widget/reducers/uniq.rb +91 -0
- data/lib/wukong/widget/serializers.rb +317 -0
- data/lib/wukong/widget/utils.rb +46 -0
- data/lib/wukong/widgets.rb +7 -0
- data/spec/examples/dataflow/fibonacci_series_spec.rb +18 -0
- data/spec/examples/dataflow/parse_apache_logs_spec.rb +8 -0
- data/spec/examples/dataflow/parsing_spec.rb +14 -0
- data/spec/examples/dataflow/simple_spec.rb +34 -0
- data/spec/examples/dataflow/telegram_spec.rb +43 -0
- data/spec/examples/graph/minimum_spanning_tree_spec.rb +34 -0
- data/spec/examples/munging/airline_flights/identifiers_spec.rb +16 -0
- data/spec/examples/munging/airline_flights_spec.rb +202 -0
- data/spec/examples/text/pig_latin_spec.rb +18 -0
- data/spec/examples/workflow/cherry_pie_spec.rb +36 -0
- data/spec/hanuman/graph_spec.rb +119 -0
- data/spec/hanuman/hanuman_spec.rb +10 -0
- data/spec/hanuman/registry_spec.rb +123 -0
- data/spec/hanuman/stage_spec.rb +81 -0
- data/spec/hanuman/tree_spec.rb +119 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/example_test_helpers.rb +95 -0
- data/spec/support/hanuman_test_helpers.rb +92 -0
- data/spec/support/integration_helper.rb +38 -0
- data/spec/support/model_test_helpers.rb +115 -0
- data/spec/support/shared_context_for_graphs.rb +57 -0
- data/spec/support/shared_context_for_reducers.rb +37 -0
- data/spec/support/shared_examples_for_builders.rb +94 -0
- data/spec/support/shared_examples_for_shortcuts.rb +57 -0
- data/spec/wu/model/reconcilable_spec.rb +152 -0
- data/spec/wukong/dataflow_spec.rb +87 -0
- data/spec/wukong/driver_spec.rb +154 -0
- data/spec/wukong/local/runner_spec.rb +29 -0
- data/spec/wukong/local/stdio_driver_spec.rb +73 -0
- data/spec/wukong/local_spec.rb +6 -0
- data/spec/wukong/logger_spec.rb +49 -0
- data/spec/wukong/model/faker_spec.rb +132 -0
- data/spec/wukong/processor_spec.rb +21 -0
- data/spec/wukong/runner_spec.rb +132 -0
- data/spec/wukong/source_spec.rb +6 -0
- data/spec/wukong/widget/extract_spec.rb +101 -0
- data/spec/wukong/widget/filters_spec.rb +79 -0
- data/spec/wukong/widget/logger_spec.rb +23 -0
- data/spec/wukong/widget/operators_spec.rb +25 -0
- data/spec/wukong/widget/reducers/bin_spec.rb +92 -0
- data/spec/wukong/widget/reducers/count_spec.rb +11 -0
- data/spec/wukong/widget/reducers/group_spec.rb +21 -0
- data/spec/wukong/widget/reducers/join_xml_spec.rb +25 -0
- data/spec/wukong/widget/reducers/moments_spec.rb +36 -0
- data/spec/wukong/widget/reducers/sort_spec.rb +26 -0
- data/spec/wukong/widget/reducers/uniq_spec.rb +14 -0
- data/spec/wukong/widget/serializers_spec.rb +114 -0
- data/spec/wukong/widget/sink_spec.rb +19 -0
- data/spec/wukong/widget/source_spec.rb +65 -0
- data/spec/wukong/wu-local_spec.rb +109 -0
- data/spec/wukong/wu-source_spec.rb +32 -0
- data/spec/wukong/wu_spec.rb +14 -0
- data/spec/wukong/wukong_spec.rb +10 -0
- data/wukong.gemspec +35 -0
- metadata +465 -0
@@ -0,0 +1,161 @@
|
|
1
|
+
module Hanuman
|
2
|
+
module Graphvizzer
|
3
|
+
|
4
|
+
COL_1_WIDTH = 47
|
5
|
+
|
6
|
+
class Item
|
7
|
+
include Gorillib::Builder
|
8
|
+
|
9
|
+
field :name, Symbol
|
10
|
+
field :label, String, :default => ->{ name }
|
11
|
+
field :owner, Item
|
12
|
+
|
13
|
+
def indent(adj=0)
|
14
|
+
" " * (depth + adj)
|
15
|
+
end
|
16
|
+
|
17
|
+
def depth
|
18
|
+
owner.depth + 1
|
19
|
+
end
|
20
|
+
|
21
|
+
def quote(str) str.to_s.include?('"') ? str : %Q{"#{str}"} ; end
|
22
|
+
def attrib(attr, val) "#{attr}=#{val}" ; end
|
23
|
+
def brace(str) "#{indent}#{str} {" ; end
|
24
|
+
def close_brace() "#{indent}}" ; end
|
25
|
+
|
26
|
+
def line(str, attrs={}, term=';')
|
27
|
+
if attrs.empty?
|
28
|
+
attr_strs = ''
|
29
|
+
else
|
30
|
+
width = COL_1_WIDTH - indent.length
|
31
|
+
str = "%-#{width}s" % str
|
32
|
+
attr_strs = attrs.map{|attr, val| attrib(attr, val) }
|
33
|
+
attr_strs = "\t[ #{attr_strs.join(", ")} ]"
|
34
|
+
end
|
35
|
+
[indent, str, attr_strs, term].join
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Graph < Item
|
40
|
+
field :items, Array, :default => []
|
41
|
+
field :edges, Array, :default => []
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
str = []
|
45
|
+
str << brace("subgraph #{quote("cluster_#{name}")}") ## subgraph "cluster_crust" {
|
46
|
+
str << line(attrib(" label", quote(label))) ## label="crust";
|
47
|
+
items.each do |item| ##
|
48
|
+
str << item.to_s ## "cherry_pie.crust.small_bowl" [ shape=Mrecord, label="{small\nbowl}" ];
|
49
|
+
end ## "cherry_pie.crust.flour" [ shape=Mrecord, label="{flour}" ];
|
50
|
+
edges.each do |edge| ##
|
51
|
+
str << edge.to_s ## "cherry_pie.crust.small_bowl" -> "cherry_pie.crust.add_to_4";
|
52
|
+
end ## "cherry_pie.crust.flour" -> "cherry_pie.crust.add_to_4";
|
53
|
+
str << close_brace ## }
|
54
|
+
str.join("\n")
|
55
|
+
end
|
56
|
+
|
57
|
+
def graph(name, attrs={})
|
58
|
+
obj = Graph.new(attrs.merge(:name => name, :owner => self))
|
59
|
+
items << obj
|
60
|
+
yield(obj) if block_given?
|
61
|
+
obj
|
62
|
+
end
|
63
|
+
|
64
|
+
def node(name, attrs={})
|
65
|
+
obj = Node.new(attrs.merge(:name => name, :owner => self))
|
66
|
+
items << obj
|
67
|
+
yield(obj) if block_given?
|
68
|
+
obj
|
69
|
+
end
|
70
|
+
|
71
|
+
def edge(from, into, from_slot=nil, into_slot=nil)
|
72
|
+
obj = Edge.new(
|
73
|
+
:name => name, :owner => self,
|
74
|
+
:from => from, :into => into,
|
75
|
+
:from_slot => from_slot, :into_slot => into_slot)
|
76
|
+
edges << obj
|
77
|
+
yield(obj) if block_given?
|
78
|
+
obj
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class Universe < Graph
|
83
|
+
field :orient, Symbol, :doc => 'one of :TB, :BT, :LR, :RL', :default => :TB
|
84
|
+
field :engine, Symbol, :default => :dot
|
85
|
+
|
86
|
+
def to_s
|
87
|
+
str = []
|
88
|
+
str << brace("digraph #{name}") ## digraph Wukong {
|
89
|
+
str << line(" rankdir = #{orient}") ## rankdir = TB;
|
90
|
+
items.each do |item| ## subgraph "cluster_cherry_pie" {
|
91
|
+
str << item.to_s ## # ...
|
92
|
+
end ## }
|
93
|
+
str << close_brace ## }
|
94
|
+
str.join("\n")
|
95
|
+
end
|
96
|
+
|
97
|
+
def depth() 0; end
|
98
|
+
|
99
|
+
def save(path, type=nil)
|
100
|
+
File.open "#{path}.dot", "w" do |f|
|
101
|
+
f.puts self.to_s
|
102
|
+
end
|
103
|
+
system "#{engine} -T#{type} #{path}.dot > #{path}.#{type}" if type
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class Node < Item
|
108
|
+
field :inslots, Array, :default => []
|
109
|
+
field :outslots, Array, :default => []
|
110
|
+
field :shape, Symbol, :default => :Mrecord
|
111
|
+
|
112
|
+
def to_s
|
113
|
+
line(
|
114
|
+
quote(name), ## "cherry_pie.crust.small_bowl" [
|
115
|
+
:shape => shape, ## shape=Mrecord,
|
116
|
+
:label => quote(structured_label), ## label="{{<in>sb}|small\nbowl}"
|
117
|
+
) ## ];
|
118
|
+
end
|
119
|
+
|
120
|
+
def abbreviate(word)
|
121
|
+
word.to_s.
|
122
|
+
gsub(/-\d+$/,''). # remove a trailing index (-0...)
|
123
|
+
split(/[\W_]+/). # split into _ separated segment
|
124
|
+
reject(&:empty?).map{|str| str[0] }.join
|
125
|
+
end
|
126
|
+
|
127
|
+
def inslots_str
|
128
|
+
inslots.map{|slot| "<#{slot}>#{abbreviate(slot)}"}.join("|")
|
129
|
+
end
|
130
|
+
|
131
|
+
def outslots_str
|
132
|
+
outslots.map{|slot| "<_#{slot}>#{abbreviate(slot)}"}.join("|")
|
133
|
+
end
|
134
|
+
|
135
|
+
def label
|
136
|
+
super.to_s.gsub(/_\d+$/, '').gsub(/[_\.]+/, "\\n")
|
137
|
+
end
|
138
|
+
|
139
|
+
def structured_label
|
140
|
+
return label unless shape =~ /record/
|
141
|
+
str = "{"
|
142
|
+
str << "{" << (inslots.empty? ? "<i>" : inslots_str) << "}|"
|
143
|
+
str << label
|
144
|
+
str << "|{" << (outslots.empty? ? "<_o>" : outslots_str) << "}"
|
145
|
+
str << "}"
|
146
|
+
str
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
class Edge < Item
|
151
|
+
field :from, Whatever
|
152
|
+
field :into, Whatever
|
153
|
+
|
154
|
+
def to_s
|
155
|
+
width = COL_1_WIDTH - indent.length
|
156
|
+
"#{indent}%-#{width}s\t-> %-s;" % [ from, into ] ## "cherry_pie.crust.small_bowl" -> "cherry_pie.crust.add_to_4";
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'hanuman/graphvizzer/gv_models'
|
2
|
+
|
3
|
+
module Hanuman
|
4
|
+
|
5
|
+
Stage.class_eval do
|
6
|
+
class_attribute :draw_shape
|
7
|
+
self.draw_shape = :record
|
8
|
+
|
9
|
+
def graphviz_id
|
10
|
+
graph_id
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def gv_into_label() warn [self, self.class.ancestors]; %Q{"#{graphviz_id}":"i"} ; end
|
15
|
+
def gv_from_label() warn [self, self.class.ancestors]; %Q{"#{graphviz_id}":"_o"} ; end
|
16
|
+
|
17
|
+
def to_graphviz(gv)
|
18
|
+
gv.node(self.graphviz_id,
|
19
|
+
:label => name,
|
20
|
+
:shape => draw_shape,
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Product.class_eval do
|
26
|
+
self.draw_shape = :Mrecord
|
27
|
+
end
|
28
|
+
|
29
|
+
module ::Wukong::Universe
|
30
|
+
def to_graphviz
|
31
|
+
gv = Hanuman::Graphvizzer::Universe.new(:name => self.name)
|
32
|
+
@workflows.each_value do |workflow|
|
33
|
+
workflow.to_graphviz(gv)
|
34
|
+
end
|
35
|
+
@dataflows.each_value do |dataflow|
|
36
|
+
dataflow.to_graphviz(gv)
|
37
|
+
end
|
38
|
+
gv
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Graph.class_eval do
|
43
|
+
self.draw_shape = :record
|
44
|
+
|
45
|
+
def to_graphviz(gv)
|
46
|
+
gv.graph(graphviz_id, :label => name) do |gv2|
|
47
|
+
inslots.each_value{|slot| slot.to_graphviz(gv2) if slot.wired? }
|
48
|
+
|
49
|
+
stages.each_value{|stage| stage.to_graphviz(gv2) }
|
50
|
+
|
51
|
+
outslots.each_value{|slot| slot.to_graphviz(gv2) if slot.wired? }
|
52
|
+
#
|
53
|
+
edges.each_value do |edge|
|
54
|
+
gv2.edge(edge[:from].gv_from_label, edge[:into].gv_into_label)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module Hanuman::Slottable
|
61
|
+
def to_graphviz(gv)
|
62
|
+
super.tap{|node| node.receive!(
|
63
|
+
:inslots => inslots.to_a.map{|slot| slot.name },
|
64
|
+
:outslots => outslots.to_a.map{|slot| slot.name },
|
65
|
+
) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
module InputSlotted
|
70
|
+
def gv_into_label() %Q{"#{graphviz_id}":"i"} ; end
|
71
|
+
end
|
72
|
+
module OutputSlotted
|
73
|
+
def gv_from_label() %Q{"#{graphviz_id}":"_o"} ; end
|
74
|
+
end
|
75
|
+
|
76
|
+
Slot.class_eval do
|
77
|
+
def to_graphviz(gv)
|
78
|
+
gv.node(self.graphviz_id, label: name, shape: :Mrecord)
|
79
|
+
end
|
80
|
+
def graphviz_id() (stage.is_a?(Hanuman::Graph)||stage.is_a?(Wukong::Universe)) ? graph_id : stage.graph_id ; end
|
81
|
+
end
|
82
|
+
|
83
|
+
InputSlot.class_eval do
|
84
|
+
def gv_into_label() %Q{"#{graphviz_id}":"#{name}"} ; end
|
85
|
+
def to_graphviz(gv)
|
86
|
+
super.tap{|node| node.receive!(inslots: [name] )}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
OutputSlot.class_eval do
|
91
|
+
def gv_from_label() %Q{"#{graphviz_id}":"_#{name}"} ; end
|
92
|
+
def to_graphviz(gv)
|
93
|
+
super.tap{|node| node.receive!(outslots: [name] )}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/lib/hanuman/link.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Hanuman
|
2
|
+
class LinkFactory
|
3
|
+
|
4
|
+
Registry = {
|
5
|
+
simple: ->(from_stage, *into_stage){ DirectedLink.new(from_stage, *into_stage) }
|
6
|
+
}
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def connect(label, from_stage, *into_stage)
|
11
|
+
Registry[label].call(from_stage, *into_stage)
|
12
|
+
end
|
13
|
+
|
14
|
+
def register(label, factory_method)
|
15
|
+
Registry[label] = factory_method
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class DirectedLink
|
22
|
+
|
23
|
+
attr_accessor :from, :into
|
24
|
+
|
25
|
+
def initialize(from, into)
|
26
|
+
@from = from
|
27
|
+
@into = into
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"#<#{self.class}(#{from.to_s} -> #{into.to_s})>"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Hanuman
|
2
|
+
class Registry
|
3
|
+
|
4
|
+
REGISTRY = {} unless defined? REGISTRY
|
5
|
+
|
6
|
+
def create_or_update(label, builder)
|
7
|
+
create(label, builder) ? true : update(label, builder)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(label, builder)
|
11
|
+
return false if registered?(label)
|
12
|
+
REGISTRY[label] = builder
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(label, new_definition)
|
17
|
+
return false unless registered?(label)
|
18
|
+
REGISTRY[label].merge!(new_definition)
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
def registered?(label)
|
23
|
+
REGISTRY.keys.include? label
|
24
|
+
end
|
25
|
+
|
26
|
+
def retrieve(label)
|
27
|
+
REGISTRY[label].clone rescue nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def decorate_with_registry(graph_instance)
|
31
|
+
REGISTRY.each_pair do |label, definition|
|
32
|
+
graph_instance.define_singleton_method(label) do |*args, &blk|
|
33
|
+
builder = Hanuman::GlobalRegistry.retrieve(label)
|
34
|
+
builder = handle_dsl_arguments_for(builder, *args, &blk)
|
35
|
+
stages[builder.label] = builder
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def show() REGISTRY.dup ; end
|
41
|
+
def clear!() REGISTRY.clear ; end
|
42
|
+
def merge!(contents) REGISTRY.merge!(contents) ; end
|
43
|
+
end
|
44
|
+
|
45
|
+
GlobalRegistry = Registry.new unless defined? GlobalRegistry
|
46
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Hanuman
|
2
|
+
|
3
|
+
module StageInstanceMethods
|
4
|
+
|
5
|
+
attr_accessor :graph
|
6
|
+
|
7
|
+
def linkable_name(direction) ; self.label ; end
|
8
|
+
|
9
|
+
def add_stage_link(type, other_stage)
|
10
|
+
self.links << Hanuman::LinkFactory.connect(type, linkable_name(:in), other_stage.linkable_name(:out))
|
11
|
+
graph.add_link(type, self, other_stage) if graph
|
12
|
+
end
|
13
|
+
|
14
|
+
def root
|
15
|
+
graph ? graph.root(self) : self
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
module StageClassMethods
|
21
|
+
|
22
|
+
def label() self.to_s.demodulize.underscore.to_sym ; end
|
23
|
+
|
24
|
+
def builder
|
25
|
+
return @builder if @builder
|
26
|
+
set_builder(StageBuilder.new(label: label))
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_builder(builder)
|
30
|
+
@builder = builder unless builder.nil?
|
31
|
+
builder.for_class = self
|
32
|
+
@builder
|
33
|
+
end
|
34
|
+
|
35
|
+
def register(new_label = nil)
|
36
|
+
builder.label = new_label || label
|
37
|
+
Hanuman::GlobalRegistry.create_or_update(new_label || label, builder)
|
38
|
+
self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Stage
|
43
|
+
include Gorillib::Model
|
44
|
+
include StageInstanceMethods
|
45
|
+
extend StageClassMethods
|
46
|
+
|
47
|
+
field :label, Symbol, :doc => false
|
48
|
+
field :links, Array, :default => [], doc: false
|
49
|
+
|
50
|
+
def clone
|
51
|
+
cloned_attrs = Hash[ attributes.map{ |key, val| dup_key = key.dup rescue key ; dup_val = val.dup rescue val ; [ dup_key, dup_val ] } ]
|
52
|
+
cloned_links = links.map{ |link| link.dup }
|
53
|
+
self.class.receive(cloned_attrs.merge(links: cloned_links))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class StageBuilder
|
58
|
+
|
59
|
+
include Gorillib::Model
|
60
|
+
include StageInstanceMethods
|
61
|
+
|
62
|
+
field :args, Hash, :default => {}
|
63
|
+
field :for_class, Class
|
64
|
+
field :label, Symbol
|
65
|
+
field :links, Array, :default => []
|
66
|
+
|
67
|
+
def define(*args, &blk)
|
68
|
+
stage = for_class || define_class(label, *args)
|
69
|
+
stage.class_eval(&blk) if block_given?
|
70
|
+
stage.register
|
71
|
+
end
|
72
|
+
|
73
|
+
def build(options = {})
|
74
|
+
for_class.receive self.serialize.merge(options).merge(options[label] || {})
|
75
|
+
end
|
76
|
+
|
77
|
+
def handle_extra_attributes(attrs)
|
78
|
+
args.merge!(attrs)
|
79
|
+
end
|
80
|
+
|
81
|
+
def merge!(other_builder = {})
|
82
|
+
attrs = other_builder.attributes rescue other_builder
|
83
|
+
self.receive!(attrs)
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def namespace(*args) Hanuman::Stage ; end
|
88
|
+
|
89
|
+
def define_class(name, *args)
|
90
|
+
klass = namespace(*args).const_get(name.to_s.camelize, Class.new(namespace(*args))) rescue nil
|
91
|
+
klass ||= namespace(*args).const_set(name.to_s.camelize, Class.new(namespace(*args)))
|
92
|
+
klass.set_builder(self)
|
93
|
+
klass
|
94
|
+
end
|
95
|
+
|
96
|
+
def serialize()
|
97
|
+
attrs = attributes
|
98
|
+
args = attrs.delete(:args)
|
99
|
+
attrs.delete(:links) ; attrs.delete(:for_class)
|
100
|
+
attrs.merge(args)
|
101
|
+
end
|
102
|
+
|
103
|
+
# This is a hacky method to clone a Stage ; probably could be merged into serialize?
|
104
|
+
def clone
|
105
|
+
cloned_attrs = Hash[ serialize.map{ |key, val| dup_key = key.dup rescue key ; dup_val = val.dup rescue val ; [ dup_key, dup_val ] } ]
|
106
|
+
cloned_links = links.map{ |link| link.dup }
|
107
|
+
self.class.receive(cloned_attrs.merge(links: cloned_links).merge(for_class: for_class))
|
108
|
+
end
|
109
|
+
|
110
|
+
def into(stage_or_stages)
|
111
|
+
return stage_or_stages if stage_or_stages.nil?
|
112
|
+
if stage_or_stages.is_a?(Array)
|
113
|
+
stage_or_stages.each do |other_stage_or_stages|
|
114
|
+
while other_stage_or_stages.is_a?(Array)
|
115
|
+
other_stage_or_stages = other_stage_or_stages.first
|
116
|
+
end
|
117
|
+
other_stage = other_stage_or_stages
|
118
|
+
self.into(other_stage)
|
119
|
+
end
|
120
|
+
else
|
121
|
+
self.add_stage_link(:simple, stage_or_stages.root)
|
122
|
+
end
|
123
|
+
stage_or_stages
|
124
|
+
end
|
125
|
+
alias_method :|, :into
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|