-
Notifications
You must be signed in to change notification settings - Fork 18
/
shakespeare.jx
102 lines (95 loc) · 3.33 KB
/
shakespeare.jx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#This is a sample Makeflow script written in JX which retrieves a sampling of William Shakespeare's plays (raw text modified from
#source at shakespeare.mit.edu), runs an analysis of the amount of dialogue for each character in the sampled plays, and returns
#the character with the most dialogue and the number of times that character spoke.
#
#For each text retrieved (Henry IV Part 1, Henry IV Part 2, Henry VI Part 1, Henry VI Part 2, and Henry VI Part 3) Makeflow will retrieve the text
#file of the play, package the version of Perl at the local site (via Starch, another part of CCTools), and run the script text_analyzer.pl.
#The text_analyzer.pl script reads the play it is given and produces a list of characters in the play and how many times they each speak.
#
#The execution flow for a single play would look like this:
#curl->starch->perl->output.txt
#
#The final task in this makeflow produces top_character.txt which reports the character with the most dialogue out of all plays read.
{
"define" : {
#Here is a list of the plays we will retrieve
"PLAYS": ["henry_iv_part_1",
"henry_iv_part_2",
"henry_vi_part_1",
"henry_vi_part_2",
"henry_vi_part_3"
]
},
"rules": [
#This is the final task in the workflow. Notice that the order we write rules does not matter, Makeflow will figure it out for us.
{
"command": "perl count_characters.pl",
"inputs": [template("characters_{p}.txt") for p in PLAYS,
"count_characters.pl"
],
"outputs": ["top_character.txt"]
},
#JX allows us to condense rules down to patterns using list comprehension.
#In the rule below, we tell Makeflow to get all the plays listed in our context.jx file.
#Look at example in shakespeare.mf to see the expanded version using the Make syntax.
{
"command": template("curl -s -o {p}.txt http://ccl.cse.nd.edu/workflows/shakespeare/{p}.txt"),
"inputs": [],
"outputs": [template("{p}.txt")],
"local_job": true
} for p in PLAYS,
# If a rule has local_job set to true, it executes at the local site.
{
"command": "starch -C starch.config -c \"perl text_analyzer.pl\" perl.sfx",
"inputs": ["/usr/bin/perl",
"text_analyzer.pl"
],
"outputs": ["perl.sfx"],
"local_job": true
},
{
"command": "./perl.sfx henry_iv_part_1.txt",
"inputs": ["henry_iv_part_1.txt",
"perl.sfx",
"text_analyzer.pl"
],
"outputs": ["characters_henry_iv_part_1.txt"]
},
{
"command": "./perl.sfx henry_iv_part_2.txt",
"inputs": ["characters_henry_iv_part_1.txt",
"henry_iv_part_2.txt",
"perl.sfx",
"text_analyzer.pl"
],
"outputs": ["characters_henry_iv_part_2.txt"]
},
{
"command": "./perl.sfx henry_vi_part_1.txt",
"inputs": ["henry_vi_part_1.txt",
"perl.sfx",
"text_analyzer.pl"
],
"outputs": ["characters_henry_vi_part_1.txt"]
},
#Notice this next rule relies on characters_henry_iv_part_1.txt, so it will have to wait for the previous task to finish before it can run.
{
"command": "./perl.sfx henry_vi_part_2.txt",
"inputs": ["characters_henry_vi_part_1.txt",
"henry_vi_part_2.txt",
"perl.sfx",
"text_analyzer.pl"
],
"outputs": ["characters_henry_vi_part_2.txt"]
},
{
"command": "./perl.sfx henry_vi_part_3.txt",
"inputs": ["characters_henry_vi_part_1.txt",
"characters_henry_vi_part_2.txt",
"henry_vi_part_3.txt",
"perl.sfx",
"text_analyzer.pl"
],
"outputs": ["characters_henry_vi_part_3.txt"]
}
]}