Page MenuHomeSoftware Heritage
Paste P739

(An Untitled Masterwork)
ActivePublic

Authored by seirl on Aug 12 2020, 2:42 PM.
package org.softwareheritage.graph.backend;
import it.unimi.dsi.big.webgraph.labelling.ArcLabelledImmutableGraph;
import it.unimi.dsi.big.webgraph.labelling.ArcLabelledNodeIterator;
import it.unimi.dsi.big.webgraph.labelling.BitStreamArcLabelledImmutableGraph;
import it.unimi.dsi.fastutil.io.BinIO;
import it.unimi.dsi.util.PermutedFrontCodedStringList;
import java.io.*;
public class ReadLabelledGraph {
public static void main(String[] args) throws IOException, ClassNotFoundException {
String graphPath = args[0];
ArcLabelledImmutableGraph graph = BitStreamArcLabelledImmutableGraph.loadOffline(graphPath + "-labelled");
NodeIdMap nodeMap = new NodeIdMap(graphPath, graph.numNodes());
PermutedFrontCodedStringList labelMap = (PermutedFrontCodedStringList) BinIO.loadObject(graphPath + "-labels.fcl");
ArcLabelledNodeIterator it = graph.nodeIterator();
while (it.hasNext()) {
long srcNode = it.nextLong();
ArcLabelledNodeIterator.LabelledArcIterator s = it.successors();
long dstNode;
while ((dstNode = s.nextLong()) >= 0) {
int label = (int) s.label().get();
int missing = (1 << s.label().fixedWidth()) - 1;
if (label == missing)
label = -1;
System.out.format(
"%s %s %s\n",
nodeMap.getSwhPID(srcNode),
nodeMap.getSwhPID(dstNode),
((label > -1) ? labelMap.get(label) : "")
);
}
}
}
}