Created
June 16, 2014 12:11
-
-
Save lgylym/a2bb6a9af46b85cb4d6d to your computer and use it in GitHub Desktop.
from webgraph datasets create simple graph files (csv)
This file contains 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 it.unimi.dsi.webgraph.*; | |
import java.io.File; | |
import java.io.FileWriter; | |
/** | |
* Created by yluo on 6/13/2014. | |
* webgraph: http://webgraph.di.unimi.it/ | |
* | |
* output format: node [children] | |
* | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
String input = "D:\\webbase-2001"; | |
String output = "D:\\webbase_ge200.txt"; | |
File towrite = new File(output); | |
int degreeThreshold = 200; | |
try { | |
FileWriter fw = new FileWriter(towrite); | |
ImmutableGraph graph = ImmutableGraph.loadSequential(input); | |
NodeIterator ni = graph.nodeIterator(); | |
while(ni.hasNext()) { | |
//get the node | |
int node = ni.nextInt(); | |
int outdegree = ni.outdegree(); | |
if(outdegree >= degreeThreshold) { | |
//output the node and the neighbors, per line | |
fw.write(Integer.toString(node) + " "); | |
LazyIntIterator li = ni.successors(); | |
while( outdegree-- != 0 ) { | |
fw.write(Integer.toString(li.nextInt()) + " "); | |
} | |
fw.write("\n"); | |
} | |
} | |
fw.close(); | |
}catch(Exception e) { | |
System.err.println(e); | |
} | |
System.out.println("hello world!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment