Differential D4028 Diff 14692 java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java
Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java
Show All 9 Lines | |||||
import java.io.IOException; | import java.io.IOException; | ||||
public class ReadLabelledGraph { | public class ReadLabelledGraph { | ||||
public static void main(String[] args) throws IOException, ClassNotFoundException { | public static void main(String[] args) throws IOException, ClassNotFoundException { | ||||
String graphPath = args[0]; | String graphPath = args[0]; | ||||
ArcLabelledImmutableGraph graph = BitStreamArcLabelledImmutableGraph.loadOffline(graphPath + "-labelled"); | ArcLabelledImmutableGraph graph = BitStreamArcLabelledImmutableGraph.loadOffline(graphPath + "-labelled"); | ||||
NodeIdMap nodeMap = new NodeIdMap(graphPath, graph.numNodes()); | NodeIdMap nodeMap = new NodeIdMap(graphPath, graph.numNodes()); | ||||
PermutedFrontCodedStringList labelMap = (PermutedFrontCodedStringList) BinIO.loadObject(graphPath + "-labels.fcl"); | PermutedFrontCodedStringList labelMap = (PermutedFrontCodedStringList) BinIO | ||||
.loadObject(graphPath + "-labels.fcl"); | |||||
ArcLabelledNodeIterator it = graph.nodeIterator(); | ArcLabelledNodeIterator it = graph.nodeIterator(); | ||||
while (it.hasNext()) { | while (it.hasNext()) { | ||||
long srcNode = it.nextLong(); | long srcNode = it.nextLong(); | ||||
ArcLabelledNodeIterator.LabelledArcIterator s = it.successors(); | ArcLabelledNodeIterator.LabelledArcIterator s = it.successors(); | ||||
long dstNode; | long dstNode; | ||||
while ((dstNode = s.nextLong()) >= 0) { | while ((dstNode = s.nextLong()) >= 0) { | ||||
int[] labels = (int[]) s.label().get(); | int[] labels = (int[]) s.label().get(); | ||||
if (labels.length > 0) { | if (labels.length > 0) { | ||||
for (int label : labels) { | for (int label : labels) { | ||||
System.out.format( | System.out.format("%s %s %s\n", nodeMap.getSWHID(srcNode), nodeMap.getSWHID(dstNode), | ||||
"%s %s %s\n", | labelMap.get(label)); | ||||
nodeMap.getSWHID(srcNode), | |||||
nodeMap.getSWHID(dstNode), | |||||
labelMap.get(label) | |||||
); | |||||
} | } | ||||
} else { | } else { | ||||
System.out.format( | System.out.format("%s %s\n", nodeMap.getSWHID(srcNode), nodeMap.getSWHID(dstNode)); | ||||
"%s %s\n", | |||||
nodeMap.getSWHID(srcNode), | |||||
nodeMap.getSWHID(dstNode) | |||||
); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||