Permalink
Browse files

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)
  • Loading branch information...
greebie authored and ruebot committed Mar 29, 2018
1 parent 01366ce commit 993c231de6cf7418dd457e718a9224f916574e5f
Showing with 47,444 additions and 94 deletions.
  1. +47,348 −0 assets/anarchist.graphml
  2. +9 −9 headers/graphpass.h
  3. +5 −5 src/analyze.c
  4. +9 −9 src/filter.c
  5. +8 −6 src/gexf.c
  6. +32 −32 src/graphpass.c
  7. +11 −11 src/io.c
  8. +4 −4 src/reports.c
  9. +12 −12 tests/quickrun_test.c
  10. +6 −6 tests/runner_test_ana.c
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -33,17 +33,17 @@ typedef enum { false, true } bool;
igraph_t g;
igraph_attribute_table_t att;
char* FILENAME; /**< The filename from -f flag. */
char* DIRECTORY; /**< Directory to access FILENAME and put REPORT */
char* METHODS; /**< METHODS to filter */
char* OUTPUT; /**< Folder to output new graphs */
const char* ug_FILENAME; /**< The filename from -f flag. */
const char* ug_DIRECTORY; /**< Directory to access FILENAME */
char* ug_methods; /**< METHODS to filter */
char* ug_OUTPUT; /**< Folder to output new graphs */
char* OUTPATH; /**< Path to output folder (DIRECTORY + OUTPUT) */
igraph_integer_t NODESIZE; /**< Number of Nodes in original graph */
float PERCENT; /**< Filtering percentage 0.0 by default */
bool REPORT; /**< Include a report? */
bool GFORMAT; /**< Graph format - true is "GEXF" false is "GRAPHML" */
bool QUICKRUN; /**< Lightweight visualization run */
bool SAVE; /**< If false, does not save graphs at all (for reports) */
float ug_percent; /**< Filtering percentage 0.0 by default */
bool ug_report; /**< Include a report? */
bool ug_gformat; /**< Graph format - true is "GEXF" false is "GRAPHML" */
bool ug_quickrun; /**< Lightweight visualization run */
bool ug_save; /**< If false, does not save graphs at all (for reports) */
bool CALC_WEIGHTS;
igraph_vector_t WEIGHTED; /**< If greater than 0, conducts weighted analysis */
View
@@ -513,11 +513,11 @@ int create_graph_csv(char* filepath, int start, int perc) {
fprintf(fs, "| perc | Authority | Betweenness | Degree | Eigenvector | Hub | Indegree | OutDegree | PageRank | Random |\n");
for (int i=start; i<perc; i++) {
REPORT = false;
SAVE = false;
PERCENT = i;
METHODS = ALL_METHODS;
OUTPUT = "GRAPH/";
ug_report = false;
ug_save = false;
ug_percent = i;
ug_methods = ALL_METHODS;
ug_OUTPUT = "GRAPH/";
load_graph(filepath);
filter_graph();
fprintf(fs, "|%-5i|", i);
View
@@ -30,9 +30,9 @@
*/
float fix_percentile() {
if (PERCENT == 0.0) {return 0.0;}
if (ug_percent == 0.0) {return 0.0;}
float perc;
perc = (PERCENT > 99.0 || (PERCENT < 1.0 && PERCENT > 0.99)) ? 0.99 : (PERCENT / 100.0);
perc = (ug_percent > 99.0 || (ug_percent < 1.0 && ug_percent > 0.99)) ? 0.99 : (ug_percent / 100.0);
return perc;
}
@@ -203,7 +203,7 @@ int create_filtered_graph(igraph_t *graph, double cutoff, int cutsize, char* att
SETGAN(&g2, "ASSORTATIVITY", assort);
SETGAN(&g2, "DENSITY", dens);
SETGAN(&g2, "RECIPROCITY", recip);
if (SAVE == true) {
if (ug_save == true) {
write_graph(&g2, attr);
}
push(&asshead, assort, attr);
@@ -250,7 +250,7 @@ int shrink (igraph_t *graph, int cutsize, char* attr) {
int runFilters (igraph_t *graph, int cutsize) {
int flag = 0;
while (flag > -1) {
switch (METHODS[flag]) {
switch (ug_methods[flag]) {
case 'a' : shrink(graph, cutsize, "Authority");
break;
case 'b' : shrink(graph, cutsize, "Betweenness");
@@ -283,7 +283,7 @@ int runFilters (igraph_t *graph, int cutsize) {
return 0;
}
/** Filters an igraph using one or more methods based on global "METHODS", and outputs graphs as derivatives of filename.
/** Filters an igraph using one or more methods based on global "ug_methods", and outputs graphs as derivatives of filename.
@return 0 unless an error is discovered
*/
@@ -293,7 +293,7 @@ int filter_graph() {
igraph_vector_init_seq(&idRef, 0, igraph_vcount(&g)-1);
float percentile;
int cutsize;
if (QUICKRUN == true) {
if (ug_quickrun == true) {
printf("\n\nQuickrun requested.\n\n");
printf("Quickrun does no filtering, and provides layout information\n");
printf("based on Degree (nodesize), Walktrap Modularity (color), and\n");
@@ -305,14 +305,14 @@ int filter_graph() {
return(0);
}
/* if (CALC_WEIGHTS == false) {igraph_vector_init(&WEIGHTED, NODESIZE);}*/
percentile = (PERCENT > 0.99) ? fix_percentile() : PERCENT;
percentile = (ug_percent > 0.99) ? fix_percentile() : ug_percent;
cutsize = round((double)NODESIZE * percentile);
printf("Filtering the graphs by %f will reduce the graph size by %d \n", PERCENT, cutsize);
printf("Filtering the graphs by %f will reduce the graph size by %d \n", ug_percent, cutsize);
printf("This will produce a graph with %d nodes.\n", (NODESIZE - cutsize));
SETVANV(&g, "idRef", &idRef);
analysis_all(&g);
runFilters(&g, cutsize);
if (REPORT == true) {
if (ug_report == true) {
write_report(&g);
}
igraph_destroy(&g);
View
@@ -61,7 +61,7 @@ extern int igraph_write_graph_gexf(const igraph_t *graph, FILE *outstream,
int ret;
igraph_integer_t l, vc, ec;
igraph_eit_t it;
igraph_strvector_t gnames, vnames, enames, label;
igraph_strvector_t gnames, vnames, enames, labels;
igraph_vector_t gtypes, vtypes, etypes, size, r, g, b, x, y, weight;
long int i;
igraph_vector_t numv;
@@ -229,7 +229,7 @@ extern int igraph_write_graph_gexf(const igraph_t *graph, FILE *outstream,
if (ret<0) IGRAPH_ERROR("Write failed", IGRAPH_EFILE);
vc=igraph_vcount(graph);
ec=igraph_ecount(graph);
igraph_strvector_init(&label, vc);
igraph_strvector_init(&labels, vc);
igraph_vector_init(&weight, ec);
igraph_vector_init(&r, vc);
igraph_vector_init(&g, vc);
@@ -242,10 +242,10 @@ extern int igraph_write_graph_gexf(const igraph_t *graph, FILE *outstream,
EANV(graph, "weight", &weight);
}
if (igraph_cattribute_has_attr(graph, IGRAPH_ATTRIBUTE_VERTEX, "label") == true) {
VASV(graph, "label", &label);
VASV(graph, "label", &labels);
}
else if (igraph_cattribute_has_attr(graph, IGRAPH_ATTRIBUTE_VERTEX, "name") == true){
VASV(graph, "name", &label);
VASV(graph, "name", &labels);
} else {
printf ("No label information available on this graph.");
}
@@ -264,8 +264,10 @@ extern int igraph_write_graph_gexf(const igraph_t *graph, FILE *outstream,
VANV(graph, "x", &x);
VANV(graph, "y", &y);
for (l=0; l<vc; l++) {
char *name, *name_escaped;
ret=fprintf(outstream, " <node id=\"n%ld\" label=\"%s\">\n", (long)l, STR(label, l) ? STR(label, l) : "x");
char *name, *name_escaped, *label, *label_escaped;
igraph_strvector_get(&labels, l, &label);
IGRAPH_CHECK(igraph_i_xml_escape(label, &label_escaped));
ret=fprintf(outstream, " <node id=\"n%ld\" label=\"%s\">\n", (long)l, label_escaped ? label_escaped : "x");
if (ret<0) IGRAPH_ERROR("Write failed", IGRAPH_EFILE);
ret=fprintf(outstream, " <attvalues>\n");
if (ret<0) IGRAPH_ERROR("Write failed", IGRAPH_EFILE);
View
@@ -34,16 +34,16 @@
#include "igraph.h"
#include "graphpass.h"
char* FILEPATH; /**< The filepath (DIRECTORY + FILENAME) */
char* FILEPATH; /**< The filepath (ug_DIRECTORY + ug_FILENAME) */
/** Whether to save the graph **/
bool SAVE = true;
bool ug_save = true;
/** Graph format true for GEXF; false for GRAPHML **/
bool GFORMAT = false;
bool ug_gformat = false;
/** Produce a report analyzing effect of filtering on graph **/
bool REPORT = false;
bool ug_report = false;
/** Provide a quickrun with simple sizing, positioning and coloring **/
bool QUICKRUN = false;
bool ug_quickrun = false;
int verbose_flag;
@@ -89,32 +89,32 @@ int main (int argc, char *argv[]) {
if (long_options[option_index].flag != 0)
break;
case 'n':
SAVE = !SAVE;
ug_save = !ug_save;
break;
case 'g':
GFORMAT = !GFORMAT;
ug_gformat = !ug_gformat;
break;
case 'd':
DIRECTORY = optarg ? optarg : "assets/";
ug_DIRECTORY = optarg ? optarg : "assets/";
break;
case 'r':
REPORT = !REPORT;
ug_report = !ug_report;
break;
case 'p':
PERCENT = optarg ? atof(optarg) : 0.0;
ug_percent = optarg ? atof(optarg) : 0.0;
break;
case 'm':
METHODS = optarg ? optarg : "d";
ug_methods = optarg ? optarg : "d";
break;
case 'f':
FILENAME = optarg ? optarg : "cpp2.graphml";
ug_FILENAME = optarg ? optarg : "cpp2.graphml";
break;
case 'q':
QUICKRUN = !QUICKRUN;
ug_quickrun = !ug_quickrun;
break;
case 'o':
/*check size of output text */
OUTPUT = optarg ? optarg : "OUT/";
ug_OUTPUT = optarg ? optarg : "OUT/";
break;
case 'w':
CALC_WEIGHTS = !CALC_WEIGHTS;
@@ -143,37 +143,37 @@ int main (int argc, char *argv[]) {
}
/** set default values if not included in flags **/
OUTPUT = OUTPUT ? OUTPUT : "OUT/";
PERCENT = PERCENT ? PERCENT : 0.00;
METHODS = METHODS ? METHODS : "d";
DIRECTORY = DIRECTORY ? DIRECTORY : "assets/";
FILENAME = FILENAME ? FILENAME : "cpp2.graphml";
ug_OUTPUT = ug_OUTPUT ? ug_OUTPUT : "OUT/";
ug_percent = ug_percent ? ug_percent : 0.00;
ug_methods = ug_methods ? ug_methods : "d";
ug_DIRECTORY = ug_DIRECTORY ? ug_DIRECTORY : "assets/";
ug_FILENAME = ug_FILENAME ? ug_FILENAME : "cpp2.graphml";
/** setup directory path DIRECTORY + FILENAME **/
char path[strlen(DIRECTORY)+1];
strncpy(path, DIRECTORY, strlen(DIRECTORY)+1);
/** setup directory path ug_DIRECTORY + ug_FILENAME **/
char path[strlen(ug_DIRECTORY)+1];
strncpy(path, ug_DIRECTORY, strlen(ug_DIRECTORY)+1);
/** start output description **/
printf(">>>>>>> GRAPHPASSING >>>>>>>> \n");
printf("DIRECTORY: %s \nSTRLEN PATH: %li \n", DIRECTORY, strlen(path));
printf("OUTPUT DIRECTORY: %s\nPERCENTAGE: %f\n", OUTPUT, PERCENT);
printf("FILE: %s\nMETHODS STRING: %s\n", FILENAME, METHODS);
printf("QUICKRUN: %i\nREPORT: %i\nSAVE: %i\n", QUICKRUN, REPORT, SAVE);
printf("DIRECTORY: %s \nSTRLEN PATH: %li \n", ug_DIRECTORY, strlen(path));
printf("OUTPUT DIRECTORY: %s\nPERCENTAGE: %f\n", ug_OUTPUT, ug_percent);
printf("FILE: %s\nMETHODS STRING: %s\n", ug_FILENAME, ug_methods);
printf("QUICKRUN: %i\nREPORT: %i\nSAVE: %i\n", ug_quickrun, ug_report, ug_save);
/** try to be nice if user leaves out a '/' **/
if (FILENAME[0] == '/' && DIRECTORY[strlen(DIRECTORY)] == '/' ){
if (ug_FILENAME[0] == '/' && ug_DIRECTORY[strlen(ug_DIRECTORY)] == '/' ){
path[strlen(path)+1] = '\0'; // remove end slash
}
else if (FILENAME[0] != '/' && DIRECTORY[strlen(DIRECTORY)-1] != '/') {
else if (ug_FILENAME[0] != '/' && ug_DIRECTORY[strlen(ug_DIRECTORY)-1] != '/') {
strncat(path, "/", 1); // add a slash.
}
/** set up FILEPATH to access graphml file **/
int sizeOfPath = (strlen(path)+1);
int sizeOfFile = (strlen(FILENAME)+1);
int sizeOfFile = (strlen(ug_FILENAME)+1);
int filepathsize = sizeOfPath + sizeOfFile;
FILEPATH = malloc(filepathsize + 1);
snprintf(FILEPATH, filepathsize, "%s%s", path, FILENAME);
snprintf(FILEPATH, filepathsize, "%s%s", path, ug_FILENAME);
printf("Running graphpass on file: %s\n", FILEPATH);
load_graph(FILEPATH);
@@ -182,8 +182,8 @@ int main (int argc, char *argv[]) {
/** start the filtering based on values and methods **/
filter_graph();
printf("\n\n>>>> SUCCESS!");
if (SAVE) {
printf("- Files output to %s\n", OUTPUT);
if (ug_save) {
printf("- Files output to %s\n", ug_OUTPUT);
}
else {
printf("- NO_SAVE requested, so no output.\n\n\n");
View
@@ -55,7 +55,7 @@ extern int load_graph (char* filename) {
/** \fn int write_graph (igraph_t *graph)
\brief Writes a graph file.
Based on the OUTPUT, FILENAME and METHODS constants
Based on the ug_OUTPUT, FILENAME and methods
writes a network graph to the appropriate location.
If GFORMAT is set to "true" the file will output to GEXF,
otherwise a graphml file will be produced.
@@ -64,32 +64,32 @@ extern int load_graph (char* filename) {
extern int write_graph(igraph_t *graph, char *attr) {
FILE *fp;
char fn[strlen(FILENAME)+1];
char fn[strlen(ug_FILENAME)+1];
struct stat st = {0};
if (stat(OUTPUT, &st) == -1) {
mkdir(OUTPUT, 0700);
if (stat(ug_OUTPUT, &st) == -1) {
mkdir(ug_OUTPUT, 0700);
}
char path[150];
char perc_as_string[3];
int perc = (int)PERCENT;
strncpy(fn, FILENAME, strlen(FILENAME));
int perc = (int)ug_percent;
strncpy(fn, ug_FILENAME, strlen(ug_FILENAME));
strip_ext(fn);
snprintf(perc_as_string, 3, "%d", perc);
strncpy(path, OUTPUT, strlen(OUTPUT)+1);
strncpy(path, ug_OUTPUT, strlen(ug_OUTPUT)+1);
strncat(path, fn, (strlen(fn)+1));
if (QUICKRUN == false) {
if (ug_quickrun == false) {
strncat(path, perc_as_string, 3);
strncat(path, attr, strlen(attr));
}
if (GFORMAT){
if (ug_gformat){
strncat(path, ".gexf", 5);
} else {
strncat(path, ".graphml", 8);
}
if (SAVE == true) {
if (ug_save == true) {
printf("Writing output to: %s\n", path);
fp = fopen(path, "w");
if (GFORMAT) {
if (ug_gformat) {
igraph_write_graph_gexf(graph, fp, 1);
} else {
igraph_write_graph_graphml(graph, fp, 1);
View
@@ -111,15 +111,15 @@ int rankCompare(igraph_t *g1, igraph_t *g2, char* attr, igraph_real_t* result_pv
/** Writes the report **/
int write_report(igraph_t *graph) {
if (QUICKRUN == true) { /*< QUICKRUN does not write a report */
if (ug_quickrun == true) { /*< QUICKRUN does not write a report */
printf("No reports available for quickrun\n");
exit(0);
}
printf("Write report ... \n");
//rankCompare(graph, &g, "Degree");
char dir[150];
struct stat st = {0};
strncpy(dir, OUTPUT, sizeof(OUTPUT)/sizeof(OUTPUT[0]));
strncpy(dir, ug_OUTPUT, sizeof(ug_OUTPUT)/sizeof(ug_OUTPUT[0]));
strncat(dir, "REPORT/", 7);
char filepath[150];
strncpy(filepath, dir, sizeof(dir)/sizeof(dir[0]));
@@ -143,14 +143,14 @@ int write_report(igraph_t *graph) {
t = time(NULL);
fprintf( fs, "REPORT: %s ", ctime(&t));
fprintf( fs, "-------------------- \n\n");
fprintf( fs, "ORIGINAL GRAPH: *%s.gexf*\n\n", FILENAME);
fprintf( fs, "ORIGINAL GRAPH: *%s.gexf*\n\n", ug_FILENAME);
for (int i=0; i<igraph_strvector_size(&gnames); i++) {
fprintf(fs, "%s : %f \n", STR(gnames, i), GAN(&g, STR(gnames, i)));
}
/* print names (use asshead) */
fprintf(fs, "TRAIT COMPARISON BY FILTERING METHOD \n");
fprintf(fs, "------------------------------------ \n");
fprintf(fs, "Percent Filtered: %-2f\n", PERCENT);
fprintf(fs, "Percent Filtered: %-2f\n", ug_percent);
fprintf(fs, "\n| Method | Δ Edges | Δ Assort | Δ Dens. | Δ Recipr | Δ C(Deg.)|\n");
fprintf(fs, "|-----------------|-----------|----------|----------|----------|----------|\n");
while (asshead != NULL) {
Oops, something went wrong.

0 comments on commit 993c231

Please sign in to comment.