Created
February 7, 2017 17:19
-
-
Save jboynyc/d7cb5be34f05cc10e96579aa4b6cb3c5 to your computer and use it in GitHub Desktop.
Run SNAP RolX role extraction on an IGraph network graph.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
from collections import defaultdict | |
from tempfile import NamedTemporaryFile | |
import igraph as ig | |
ROLX_BIN = 'Snap-3.0/examples/rolx/testrolx' | |
def extract_roles(input_graph, min_roles=2, max_roles=3): | |
results = defaultdict(list) | |
with NamedTemporaryFile() as input_file, NamedTemporaryFile() as output_file: | |
input_graph.write_edgelist(input_file.name) | |
subprocess.check_call([ROLX_BIN, | |
'-i:{}'.format(input_file.name), | |
'-o:{}'.format(output_file.name), | |
'-l:{}'.format(min_roles), | |
'-u:{}'.format(max_roles)]) | |
output = output_file.readlines() | |
for node, role in (i.split() for i in output[2:]): | |
results[int(role)].append(int(node)) | |
return ig.VertexCover(input_graph, results.values()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://eliassi.org/papers/henderson-kdd2011.pdf