<commit_before>// import libraries
snap = require('snap.js');
viz = require('visualization.js');

// Some basic operations

// creating a new graph
gTest = snap.newUGraph();

//  adding nodes
gTest.addNode(0); gTest.addNode(1); gTest.addNode(2);
gTest.addNode(3); gTest.addNode(4); gTest.addNode(5);

// adding edges
gTest.addEdge(0, 1); gTest.addEdge(2, 1); gTest.addEdge(2, 4);
gTest.addEdge(4, 3); gTest.addEdge(5, 3); gTest.addEdge(4, 5);
gTest.addEdge(3, 1); gTest.addEdge(3, 2);

// iterating graph and returning node ids, degree and degree centrality
var br = 0;
for (var i = gTest.getFirstNode() ; br < gTest.nodeCount() ; i.getNext()) {
    console.log("id: " + i.getId() + ", deg: " + i.getDeg() + ", deg centrality: " + snap.DegreeCentrality(gTest, i.getId()));
    br++;
}

// dump graph
gTest.dump();

// dump graph to file
gTest.dump("gtest.txt");

console.log("end basic operations part");

// Reading graphs from file, detecting communities, computing evolution and plotting

// loading graphs
var g1999 = snap.newUGraph("data\\1999.edg");
var g2000 = snap.newUGraph("data\\2000.edg");
var g2001 = snap.newUGraph("data\\2001.edg");
var g2002 = snap.newUGraph("data\\2002.edg");
var g2003 = snap.newUGraph("data\\2003.edg");
var g2004 = snap.newUGraph("data\\2004.edg");
var g2005 = snap.newUGraph("data\\2005.edg");
var g2006 = snap.newUGraph("data\\2006.edg");

// storing graphs int an array
var graphs = new Array();
graphs.push(g1999); graphs.push(g2000); graphs.push(g2001); graphs.push(g2002); graphs.push(g2003); graphs.push(g2004); graphs.push(g2005); graphs.push(g2006);

// determining communities for the arrey of graphs storing the results (array of sparse vectors)
var communities = new Array();
for (var i = 0; i < graphs.length; i++)
    communities.push(snap.CommunityDetection(graphs[i], "gn"));

// return json string of evolution graph
var json = snap.evolutionJs(communities, 0.5, 0.75);

// plot the evolution graph
viz.drawCommunityEvolution(json, "plot.html", { title: { text: "Community evolution - GirvanNewman, small graphs 8 years, alpha=0.5. beta=0.75" } });


console.log("end loading graphs from files and community evolution plotting");

// Constructing graphs, detecting communities, computing evolution and plotting

g1 = snap.newUGraph();
g1.addNode(0); g1.addNode(1); g1.addNode(2);
g1.addNode(3); g1.addNode(4); g1.addNode(5);
g1.addEdge(0, 1); g1.addEdge(0, 2); g1.addEdge(2, 1);<commit_msg>Adding snap graph functionalities, including community evolution with plotting.<commit_after>// import libraries
snap = require('snap.js');
viz = require('visualization.js');

// Some basic operations

// creating a new graph
gTest = snap.newUGraph();

//  adding nodes
gTest.addNode(0); gTest.addNode(1); gTest.addNode(2);
gTest.addNode(3); gTest.addNode(4); gTest.addNode(5);

// adding edges
gTest.addEdge(0, 1); gTest.addEdge(2, 1); gTest.addEdge(2, 4);
gTest.addEdge(4, 3); gTest.addEdge(5, 3); gTest.addEdge(4, 5);
gTest.addEdge(3, 1); gTest.addEdge(3, 2);

// iterating graph and returning node ids, degree and degree centrality
var br = 0;
for (var i = gTest.getFirstNode() ; br < gTest.nodeCount() ; i.getNext()) {
    console.log("id: " + i.getId() + ", deg: " + i.getDeg() + ", deg centrality: " + snap.DegreeCentrality(gTest, i.getId()));
    br++;
}

// dump graph
gTest.dump();

// dump graph to a file
gTest.dump("gtest.txt");

console.log("end basic operations part");

// Reading graphs from files, detecting communities, computing community evolution and plotting

// loading graphs
var g1999 = snap.newUGraph("data\\1999.edg");
var g2000 = snap.newUGraph("data\\2000.edg");
var g2001 = snap.newUGraph("data\\2001.edg");
var g2002 = snap.newUGraph("data\\2002.edg");
var g2003 = snap.newUGraph("data\\2003.edg");
var g2004 = snap.newUGraph("data\\2004.edg");
var g2005 = snap.newUGraph("data\\2005.edg");
var g2006 = snap.newUGraph("data\\2006.edg");

// storing graphs int an array
var graphs = new Array();
graphs.push(g1999); graphs.push(g2000); graphs.push(g2001); graphs.push(g2002); graphs.push(g2003); graphs.push(g2004); graphs.push(g2005); graphs.push(g2006);

// determining communities for the array of graphs and storing the results in array of sparse vectors
var communities = new Array();
for (var i = 0; i < graphs.length; i++)
    communities.push(snap.CommunityDetection(graphs[i], "gn"));

// return json string of graph evolution
var json = snap.evolutionJs(communities, 0.5, 0.75);

// plot the evolution graph
viz.drawCommunityEvolution(json, "plot.html", { title: { text: "Community evolution - GirvanNewman, small graphs 8 years, alpha=0.5. beta=0.75" } });


console.log("end loading graphs from files and community evolution plotting");

// Constructing graphs, detecting communities, computing evolution and plotting

g1 = snap.newUGraph();
g1.addNode(0); g1.addNode(1); g1.addNode(2);
g1.addNode(3); g1.addNode(4); g1.addNode(5);
g1.addEdge(0, 1); g1.addEdge(0, 2); g1.addEdge(2, 1);
{'fraction_non_alphanumeric': 0.16894609814963799, 'fraction_numerical': 0.06154465004022526, 'mean_word_length': 4.72926267281106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7460605', 'n_tokens_mistral': 1928, 'n_tokens_neox': 1715, 'n_words': 455}