Differential D4006 Diff 14145 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
package org.softwareheritage.graph.utils; | package org.softwareheritage.graph.utils; | ||||
import it.unimi.dsi.big.webgraph.labelling.ArcLabelledImmutableGraph; | import it.unimi.dsi.big.webgraph.labelling.ArcLabelledImmutableGraph; | ||||
import it.unimi.dsi.big.webgraph.labelling.ArcLabelledNodeIterator; | import it.unimi.dsi.big.webgraph.labelling.ArcLabelledNodeIterator; | ||||
import it.unimi.dsi.big.webgraph.labelling.BitStreamArcLabelledImmutableGraph; | import it.unimi.dsi.big.webgraph.labelling.BitStreamArcLabelledImmutableGraph; | ||||
import it.unimi.dsi.fastutil.io.BinIO; | import it.unimi.dsi.fastutil.io.BinIO; | ||||
import it.unimi.dsi.util.PermutedFrontCodedStringList; | import it.unimi.dsi.util.PermutedFrontCodedStringList; | ||||
import org.softwareheritage.graph.SwhLabel; | |||||
import org.softwareheritage.graph.SwhPerm; | |||||
import org.softwareheritage.graph.maps.NodeIdMap; | import org.softwareheritage.graph.maps.NodeIdMap; | ||||
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"); | // TODO: change the path to be explicit it is only filenames | ||||
PermutedFrontCodedStringList filenameMap = (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(); | SwhLabel[] labels = (SwhLabel[]) s.label().get(); | ||||
if (labels.length > 0) { | if (labels.length > 0) { | ||||
for (int label : labels) { | for (SwhLabel label : labels) { | ||||
SwhPerm.Type permissionType = SwhPerm.Type.fromInt(label.permission); | |||||
System.out.format( | System.out.format( | ||||
"%s %s %s\n", | "%s %s %s %d\n", | ||||
nodeMap.getSWHID(srcNode), | nodeMap.getSWHID(srcNode), | ||||
nodeMap.getSWHID(dstNode), | nodeMap.getSWHID(dstNode), | ||||
labelMap.get(label) | filenameMap.get((int) label.filenameId), | ||||
seirl: Just use label.permission here. | |||||
SwhPerm.Type.toOct(permissionType) | |||||
Done Inline ActionsAccording to Seba, there is now a big version of PermutedFrontCodedStringList. We probably want to use that to be able to use more than 2**32 labels. seirl: According to Seba, there is now a big version of PermutedFrontCodedStringList. We probably want… | |||||
); | ); | ||||
} | } | ||||
} else { | } else { | ||||
System.out.format( | System.out.format( | ||||
"%s %s\n", | "%s %s\n", | ||||
nodeMap.getSWHID(srcNode), | nodeMap.getSWHID(srcNode), | ||||
nodeMap.getSWHID(dstNode) | nodeMap.getSWHID(dstNode) | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
Just use label.permission here.