Skip to content

Commit 993c231

Browse files
greebieruebot
authored andcommitted
Add anarchist.graphml for testing large outputs with unescaped values. (#16)
Fix xml_escapes for labelling (issue #15) Give namespace for user generated variables and distinguish between constant and non-constant variables. (issue #13)
1 parent 01366ce commit 993c231

File tree

10 files changed

+47444
-94
lines changed

10 files changed

+47444
-94
lines changed

assets/anarchist.graphml

Lines changed: 47348 additions & 0 deletions
Large diffs are not rendered by default.

headers/graphpass.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ typedef enum { false, true } bool;
3333

3434
igraph_t g;
3535
igraph_attribute_table_t att;
36-
char* FILENAME; /**< The filename from -f flag. */
37-
char* DIRECTORY; /**< Directory to access FILENAME and put REPORT */
38-
char* METHODS; /**< METHODS to filter */
39-
char* OUTPUT; /**< Folder to output new graphs */
36+
const char* ug_FILENAME; /**< The filename from -f flag. */
37+
const char* ug_DIRECTORY; /**< Directory to access FILENAME */
38+
char* ug_methods; /**< METHODS to filter */
39+
char* ug_OUTPUT; /**< Folder to output new graphs */
4040
char* OUTPATH; /**< Path to output folder (DIRECTORY + OUTPUT) */
4141
igraph_integer_t NODESIZE; /**< Number of Nodes in original graph */
42-
float PERCENT; /**< Filtering percentage 0.0 by default */
43-
bool REPORT; /**< Include a report? */
44-
bool GFORMAT; /**< Graph format - true is "GEXF" false is "GRAPHML" */
45-
bool QUICKRUN; /**< Lightweight visualization run */
46-
bool SAVE; /**< If false, does not save graphs at all (for reports) */
42+
float ug_percent; /**< Filtering percentage 0.0 by default */
43+
bool ug_report; /**< Include a report? */
44+
bool ug_gformat; /**< Graph format - true is "GEXF" false is "GRAPHML" */
45+
bool ug_quickrun; /**< Lightweight visualization run */
46+
bool ug_save; /**< If false, does not save graphs at all (for reports) */
4747
bool CALC_WEIGHTS;
4848
igraph_vector_t WEIGHTED; /**< If greater than 0, conducts weighted analysis */
4949

src/analyze.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,11 @@ int create_graph_csv(char* filepath, int start, int perc) {
513513
fprintf(fs, "| perc | Authority | Betweenness | Degree | Eigenvector | Hub | Indegree | OutDegree | PageRank | Random |\n");
514514

515515
for (int i=start; i<perc; i++) {
516-
REPORT = false;
517-
SAVE = false;
518-
PERCENT = i;
519-
METHODS = ALL_METHODS;
520-
OUTPUT = "GRAPH/";
516+
ug_report = false;
517+
ug_save = false;
518+
ug_percent = i;
519+
ug_methods = ALL_METHODS;
520+
ug_OUTPUT = "GRAPH/";
521521
load_graph(filepath);
522522
filter_graph();
523523
fprintf(fs, "|%-5i|", i);

src/filter.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
*/
3131

3232
float fix_percentile() {
33-
if (PERCENT == 0.0) {return 0.0;}
33+
if (ug_percent == 0.0) {return 0.0;}
3434
float perc;
35-
perc = (PERCENT > 99.0 || (PERCENT < 1.0 && PERCENT > 0.99)) ? 0.99 : (PERCENT / 100.0);
35+
perc = (ug_percent > 99.0 || (ug_percent < 1.0 && ug_percent > 0.99)) ? 0.99 : (ug_percent / 100.0);
3636
return perc;
3737
}
3838

@@ -203,7 +203,7 @@ int create_filtered_graph(igraph_t *graph, double cutoff, int cutsize, char* att
203203
SETGAN(&g2, "ASSORTATIVITY", assort);
204204
SETGAN(&g2, "DENSITY", dens);
205205
SETGAN(&g2, "RECIPROCITY", recip);
206-
if (SAVE == true) {
206+
if (ug_save == true) {
207207
write_graph(&g2, attr);
208208
}
209209
push(&asshead, assort, attr);
@@ -250,7 +250,7 @@ int shrink (igraph_t *graph, int cutsize, char* attr) {
250250
int runFilters (igraph_t *graph, int cutsize) {
251251
int flag = 0;
252252
while (flag > -1) {
253-
switch (METHODS[flag]) {
253+
switch (ug_methods[flag]) {
254254
case 'a' : shrink(graph, cutsize, "Authority");
255255
break;
256256
case 'b' : shrink(graph, cutsize, "Betweenness");
@@ -283,7 +283,7 @@ int runFilters (igraph_t *graph, int cutsize) {
283283
return 0;
284284
}
285285

286-
/** Filters an igraph using one or more methods based on global "METHODS", and outputs graphs as derivatives of filename.
286+
/** Filters an igraph using one or more methods based on global "ug_methods", and outputs graphs as derivatives of filename.
287287
288288
@return 0 unless an error is discovered
289289
*/
@@ -293,7 +293,7 @@ int filter_graph() {
293293
igraph_vector_init_seq(&idRef, 0, igraph_vcount(&g)-1);
294294
float percentile;
295295
int cutsize;
296-
if (QUICKRUN == true) {
296+
if (ug_quickrun == true) {
297297
printf("\n\nQuickrun requested.\n\n");
298298
printf("Quickrun does no filtering, and provides layout information\n");
299299
printf("based on Degree (nodesize), Walktrap Modularity (color), and\n");
@@ -305,14 +305,14 @@ int filter_graph() {
305305
return(0);
306306
}
307307
/* if (CALC_WEIGHTS == false) {igraph_vector_init(&WEIGHTED, NODESIZE);}*/
308-
percentile = (PERCENT > 0.99) ? fix_percentile() : PERCENT;
308+
percentile = (ug_percent > 0.99) ? fix_percentile() : ug_percent;
309309
cutsize = round((double)NODESIZE * percentile);
310-
printf("Filtering the graphs by %f will reduce the graph size by %d \n", PERCENT, cutsize);
310+
printf("Filtering the graphs by %f will reduce the graph size by %d \n", ug_percent, cutsize);
311311
printf("This will produce a graph with %d nodes.\n", (NODESIZE - cutsize));
312312
SETVANV(&g, "idRef", &idRef);
313313
analysis_all(&g);
314314
runFilters(&g, cutsize);
315-
if (REPORT == true) {
315+
if (ug_report == true) {
316316
write_report(&g);
317317
}
318318
igraph_destroy(&g);

src/gexf.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern int igraph_write_graph_gexf(const igraph_t *graph, FILE *outstream,
6161
int ret;
6262
igraph_integer_t l, vc, ec;
6363
igraph_eit_t it;
64-
igraph_strvector_t gnames, vnames, enames, label;
64+
igraph_strvector_t gnames, vnames, enames, labels;
6565
igraph_vector_t gtypes, vtypes, etypes, size, r, g, b, x, y, weight;
6666
long int i;
6767
igraph_vector_t numv;
@@ -229,7 +229,7 @@ extern int igraph_write_graph_gexf(const igraph_t *graph, FILE *outstream,
229229
if (ret<0) IGRAPH_ERROR("Write failed", IGRAPH_EFILE);
230230
vc=igraph_vcount(graph);
231231
ec=igraph_ecount(graph);
232-
igraph_strvector_init(&label, vc);
232+
igraph_strvector_init(&labels, vc);
233233
igraph_vector_init(&weight, ec);
234234
igraph_vector_init(&r, vc);
235235
igraph_vector_init(&g, vc);
@@ -242,10 +242,10 @@ extern int igraph_write_graph_gexf(const igraph_t *graph, FILE *outstream,
242242
EANV(graph, "weight", &weight);
243243
}
244244
if (igraph_cattribute_has_attr(graph, IGRAPH_ATTRIBUTE_VERTEX, "label") == true) {
245-
VASV(graph, "label", &label);
245+
VASV(graph, "label", &labels);
246246
}
247247
else if (igraph_cattribute_has_attr(graph, IGRAPH_ATTRIBUTE_VERTEX, "name") == true){
248-
VASV(graph, "name", &label);
248+
VASV(graph, "name", &labels);
249249
} else {
250250
printf ("No label information available on this graph.");
251251
}
@@ -264,8 +264,10 @@ extern int igraph_write_graph_gexf(const igraph_t *graph, FILE *outstream,
264264
VANV(graph, "x", &x);
265265
VANV(graph, "y", &y);
266266
for (l=0; l<vc; l++) {
267-
char *name, *name_escaped;
268-
ret=fprintf(outstream, " <node id=\"n%ld\" label=\"%s\">\n", (long)l, STR(label, l) ? STR(label, l) : "x");
267+
char *name, *name_escaped, *label, *label_escaped;
268+
igraph_strvector_get(&labels, l, &label);
269+
IGRAPH_CHECK(igraph_i_xml_escape(label, &label_escaped));
270+
ret=fprintf(outstream, " <node id=\"n%ld\" label=\"%s\">\n", (long)l, label_escaped ? label_escaped : "x");
269271
if (ret<0) IGRAPH_ERROR("Write failed", IGRAPH_EFILE);
270272
ret=fprintf(outstream, " <attvalues>\n");
271273
if (ret<0) IGRAPH_ERROR("Write failed", IGRAPH_EFILE);

src/graphpass.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@
3434
#include "igraph.h"
3535
#include "graphpass.h"
3636

37-
char* FILEPATH; /**< The filepath (DIRECTORY + FILENAME) */
37+
char* FILEPATH; /**< The filepath (ug_DIRECTORY + ug_FILENAME) */
3838

3939
/** Whether to save the graph **/
40-
bool SAVE = true;
40+
bool ug_save = true;
4141
/** Graph format true for GEXF; false for GRAPHML **/
42-
bool GFORMAT = false;
42+
bool ug_gformat = false;
4343
/** Produce a report analyzing effect of filtering on graph **/
44-
bool REPORT = false;
44+
bool ug_report = false;
4545
/** Provide a quickrun with simple sizing, positioning and coloring **/
46-
bool QUICKRUN = false;
46+
bool ug_quickrun = false;
4747

4848
int verbose_flag;
4949

@@ -89,32 +89,32 @@ int main (int argc, char *argv[]) {
8989
if (long_options[option_index].flag != 0)
9090
break;
9191
case 'n':
92-
SAVE = !SAVE;
92+
ug_save = !ug_save;
9393
break;
9494
case 'g':
95-
GFORMAT = !GFORMAT;
95+
ug_gformat = !ug_gformat;
9696
break;
9797
case 'd':
98-
DIRECTORY = optarg ? optarg : "assets/";
98+
ug_DIRECTORY = optarg ? optarg : "assets/";
9999
break;
100100
case 'r':
101-
REPORT = !REPORT;
101+
ug_report = !ug_report;
102102
break;
103103
case 'p':
104-
PERCENT = optarg ? atof(optarg) : 0.0;
104+
ug_percent = optarg ? atof(optarg) : 0.0;
105105
break;
106106
case 'm':
107-
METHODS = optarg ? optarg : "d";
107+
ug_methods = optarg ? optarg : "d";
108108
break;
109109
case 'f':
110-
FILENAME = optarg ? optarg : "cpp2.graphml";
110+
ug_FILENAME = optarg ? optarg : "cpp2.graphml";
111111
break;
112112
case 'q':
113-
QUICKRUN = !QUICKRUN;
113+
ug_quickrun = !ug_quickrun;
114114
break;
115115
case 'o':
116116
/*check size of output text */
117-
OUTPUT = optarg ? optarg : "OUT/";
117+
ug_OUTPUT = optarg ? optarg : "OUT/";
118118
break;
119119
case 'w':
120120
CALC_WEIGHTS = !CALC_WEIGHTS;
@@ -143,37 +143,37 @@ int main (int argc, char *argv[]) {
143143
}
144144

145145
/** set default values if not included in flags **/
146-
OUTPUT = OUTPUT ? OUTPUT : "OUT/";
147-
PERCENT = PERCENT ? PERCENT : 0.00;
148-
METHODS = METHODS ? METHODS : "d";
149-
DIRECTORY = DIRECTORY ? DIRECTORY : "assets/";
150-
FILENAME = FILENAME ? FILENAME : "cpp2.graphml";
146+
ug_OUTPUT = ug_OUTPUT ? ug_OUTPUT : "OUT/";
147+
ug_percent = ug_percent ? ug_percent : 0.00;
148+
ug_methods = ug_methods ? ug_methods : "d";
149+
ug_DIRECTORY = ug_DIRECTORY ? ug_DIRECTORY : "assets/";
150+
ug_FILENAME = ug_FILENAME ? ug_FILENAME : "cpp2.graphml";
151151

152-
/** setup directory path DIRECTORY + FILENAME **/
153-
char path[strlen(DIRECTORY)+1];
154-
strncpy(path, DIRECTORY, strlen(DIRECTORY)+1);
152+
/** setup directory path ug_DIRECTORY + ug_FILENAME **/
153+
char path[strlen(ug_DIRECTORY)+1];
154+
strncpy(path, ug_DIRECTORY, strlen(ug_DIRECTORY)+1);
155155

156156
/** start output description **/
157157
printf(">>>>>>> GRAPHPASSING >>>>>>>> \n");
158-
printf("DIRECTORY: %s \nSTRLEN PATH: %li \n", DIRECTORY, strlen(path));
159-
printf("OUTPUT DIRECTORY: %s\nPERCENTAGE: %f\n", OUTPUT, PERCENT);
160-
printf("FILE: %s\nMETHODS STRING: %s\n", FILENAME, METHODS);
161-
printf("QUICKRUN: %i\nREPORT: %i\nSAVE: %i\n", QUICKRUN, REPORT, SAVE);
158+
printf("DIRECTORY: %s \nSTRLEN PATH: %li \n", ug_DIRECTORY, strlen(path));
159+
printf("OUTPUT DIRECTORY: %s\nPERCENTAGE: %f\n", ug_OUTPUT, ug_percent);
160+
printf("FILE: %s\nMETHODS STRING: %s\n", ug_FILENAME, ug_methods);
161+
printf("QUICKRUN: %i\nREPORT: %i\nSAVE: %i\n", ug_quickrun, ug_report, ug_save);
162162

163163
/** try to be nice if user leaves out a '/' **/
164-
if (FILENAME[0] == '/' && DIRECTORY[strlen(DIRECTORY)] == '/' ){
164+
if (ug_FILENAME[0] == '/' && ug_DIRECTORY[strlen(ug_DIRECTORY)] == '/' ){
165165
path[strlen(path)+1] = '\0'; // remove end slash
166166
}
167-
else if (FILENAME[0] != '/' && DIRECTORY[strlen(DIRECTORY)-1] != '/') {
167+
else if (ug_FILENAME[0] != '/' && ug_DIRECTORY[strlen(ug_DIRECTORY)-1] != '/') {
168168
strncat(path, "/", 1); // add a slash.
169169
}
170170

171171
/** set up FILEPATH to access graphml file **/
172172
int sizeOfPath = (strlen(path)+1);
173-
int sizeOfFile = (strlen(FILENAME)+1);
173+
int sizeOfFile = (strlen(ug_FILENAME)+1);
174174
int filepathsize = sizeOfPath + sizeOfFile;
175175
FILEPATH = malloc(filepathsize + 1);
176-
snprintf(FILEPATH, filepathsize, "%s%s", path, FILENAME);
176+
snprintf(FILEPATH, filepathsize, "%s%s", path, ug_FILENAME);
177177
printf("Running graphpass on file: %s\n", FILEPATH);
178178

179179
load_graph(FILEPATH);
@@ -182,8 +182,8 @@ int main (int argc, char *argv[]) {
182182
/** start the filtering based on values and methods **/
183183
filter_graph();
184184
printf("\n\n>>>> SUCCESS!");
185-
if (SAVE) {
186-
printf("- Files output to %s\n", OUTPUT);
185+
if (ug_save) {
186+
printf("- Files output to %s\n", ug_OUTPUT);
187187
}
188188
else {
189189
printf("- NO_SAVE requested, so no output.\n\n\n");

src/io.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extern int load_graph (char* filename) {
5555
/** \fn int write_graph (igraph_t *graph)
5656
\brief Writes a graph file.
5757
58-
Based on the OUTPUT, FILENAME and METHODS constants
58+
Based on the ug_OUTPUT, FILENAME and methods
5959
writes a network graph to the appropriate location.
6060
If GFORMAT is set to "true" the file will output to GEXF,
6161
otherwise a graphml file will be produced.
@@ -64,32 +64,32 @@ extern int load_graph (char* filename) {
6464

6565
extern int write_graph(igraph_t *graph, char *attr) {
6666
FILE *fp;
67-
char fn[strlen(FILENAME)+1];
67+
char fn[strlen(ug_FILENAME)+1];
6868
struct stat st = {0};
69-
if (stat(OUTPUT, &st) == -1) {
70-
mkdir(OUTPUT, 0700);
69+
if (stat(ug_OUTPUT, &st) == -1) {
70+
mkdir(ug_OUTPUT, 0700);
7171
}
7272
char path[150];
7373
char perc_as_string[3];
74-
int perc = (int)PERCENT;
75-
strncpy(fn, FILENAME, strlen(FILENAME));
74+
int perc = (int)ug_percent;
75+
strncpy(fn, ug_FILENAME, strlen(ug_FILENAME));
7676
strip_ext(fn);
7777
snprintf(perc_as_string, 3, "%d", perc);
78-
strncpy(path, OUTPUT, strlen(OUTPUT)+1);
78+
strncpy(path, ug_OUTPUT, strlen(ug_OUTPUT)+1);
7979
strncat(path, fn, (strlen(fn)+1));
80-
if (QUICKRUN == false) {
80+
if (ug_quickrun == false) {
8181
strncat(path, perc_as_string, 3);
8282
strncat(path, attr, strlen(attr));
8383
}
84-
if (GFORMAT){
84+
if (ug_gformat){
8585
strncat(path, ".gexf", 5);
8686
} else {
8787
strncat(path, ".graphml", 8);
8888
}
89-
if (SAVE == true) {
89+
if (ug_save == true) {
9090
printf("Writing output to: %s\n", path);
9191
fp = fopen(path, "w");
92-
if (GFORMAT) {
92+
if (ug_gformat) {
9393
igraph_write_graph_gexf(graph, fp, 1);
9494
} else {
9595
igraph_write_graph_graphml(graph, fp, 1);

src/reports.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ int rankCompare(igraph_t *g1, igraph_t *g2, char* attr, igraph_real_t* result_pv
111111

112112
/** Writes the report **/
113113
int write_report(igraph_t *graph) {
114-
if (QUICKRUN == true) { /*< QUICKRUN does not write a report */
114+
if (ug_quickrun == true) { /*< QUICKRUN does not write a report */
115115
printf("No reports available for quickrun\n");
116116
exit(0);
117117
}
118118
printf("Write report ... \n");
119119
//rankCompare(graph, &g, "Degree");
120120
char dir[150];
121121
struct stat st = {0};
122-
strncpy(dir, OUTPUT, sizeof(OUTPUT)/sizeof(OUTPUT[0]));
122+
strncpy(dir, ug_OUTPUT, sizeof(ug_OUTPUT)/sizeof(ug_OUTPUT[0]));
123123
strncat(dir, "REPORT/", 7);
124124
char filepath[150];
125125
strncpy(filepath, dir, sizeof(dir)/sizeof(dir[0]));
@@ -143,14 +143,14 @@ int write_report(igraph_t *graph) {
143143
t = time(NULL);
144144
fprintf( fs, "REPORT: %s ", ctime(&t));
145145
fprintf( fs, "-------------------- \n\n");
146-
fprintf( fs, "ORIGINAL GRAPH: *%s.gexf*\n\n", FILENAME);
146+
fprintf( fs, "ORIGINAL GRAPH: *%s.gexf*\n\n", ug_FILENAME);
147147
for (int i=0; i<igraph_strvector_size(&gnames); i++) {
148148
fprintf(fs, "%s : %f \n", STR(gnames, i), GAN(&g, STR(gnames, i)));
149149
}
150150
/* print names (use asshead) */
151151
fprintf(fs, "TRAIT COMPARISON BY FILTERING METHOD \n");
152152
fprintf(fs, "------------------------------------ \n");
153-
fprintf(fs, "Percent Filtered: %-2f\n", PERCENT);
153+
fprintf(fs, "Percent Filtered: %-2f\n", ug_percent);
154154
fprintf(fs, "\n| Method | Δ Edges | Δ Assort | Δ Dens. | Δ Recipr | Δ C(Deg.)|\n");
155155
fprintf(fs, "|-----------------|-----------|----------|----------|----------|----------|\n");
156156
while (asshead != NULL) {

0 commit comments

Comments
 (0)