diff --git a/java/src/main/java/org/softwareheritage/graph/utils/DumpProperties.java b/java/src/main/java/org/softwareheritage/graph/utils/DumpProperties.java index a50f983..cfb47a4 100644 --- a/java/src/main/java/org/softwareheritage/graph/utils/DumpProperties.java +++ b/java/src/main/java/org/softwareheritage/graph/utils/DumpProperties.java @@ -1,74 +1,79 @@ package org.softwareheritage.graph.utils; import it.unimi.dsi.big.webgraph.NodeIterator; import org.softwareheritage.graph.SwhUnidirectionalGraph; import org.softwareheritage.graph.labels.DirEntry; import java.io.IOException; public class DumpProperties { public static void main(String[] args) throws IOException { String graphPath = args[0]; - SwhUnidirectionalGraph graph = SwhUnidirectionalGraph.loadLabelled(graphPath); + SwhUnidirectionalGraph graph; + if (args.length > 1 && (args[1].equals("--mapped") || args[1].equals("-m"))) { + graph = SwhUnidirectionalGraph.loadLabelledMapped(graphPath); + } else { + graph = SwhUnidirectionalGraph.loadLabelled(graphPath); + } graph.loadContentLength(); graph.loadContentIsSkipped(); graph.loadPersonIds(); graph.loadAuthorTimestamps(); graph.loadCommitterTimestamps(); graph.loadMessages(); graph.loadTagNames(); graph.loadLabelNames(); NodeIterator it = graph.nodeIterator(); while (it.hasNext()) { long node = it.nextLong(); System.out.format("%s: %s\n", node, graph.getSWHID(node)); var s = graph.labelledSuccessors(node); long succ; System.out.println(" successors:"); while ((succ = s.nextLong()) >= 0) { DirEntry[] labels = (DirEntry[]) s.label().get(); if (labels.length > 0) { for (DirEntry label : labels) { System.out.format(" %s %s [perms: %s]\n", graph.getSWHID(succ), new String(graph.getLabelName(label.filenameId)), label.permission); } } else { System.out.format(" %s\n", graph.getSWHID(succ)); } } switch (graph.getNodeType(node)) { case CNT: System.out.format(" length: %s\n", graph.getContentLength(node)); System.out.format(" is_skipped: %s\n", graph.isContentSkipped(node)); break; case REV: System.out.format(" author: %s\n", graph.getAuthorId(node)); System.out.format(" committer: %s\n", graph.getCommitterId(node)); System.out.format(" date: %s (offset: %s)\n", graph.getAuthorTimestamp(node), graph.getAuthorTimestampOffset(node)); System.out.format(" committer_date: %s (offset: %s)\n", graph.getCommitterTimestamp(node), graph.getCommitterTimestampOffset(node)); byte[] msg = graph.getMessage(node); if (msg != null) { System.out.format(" message: %s\n", (new String(msg)).replace("\n", "\\n")); } break; case REL: System.out.format(" author: %s\n", graph.getAuthorId(node)); System.out.format(" date: %s (offset: %s)\n", graph.getAuthorTimestamp(node), graph.getAuthorTimestamp(node)); System.out.format(" message: %s\n", (new String(graph.getMessage(node))).replace("\n", "\\n")); System.out.format(" tag name: %s\n", new String(graph.getTagName(node))); break; case ORI: System.out.format(" url: %s\n", graph.getUrl(node)); } System.out.println(); } } } diff --git a/java/src/main/java/org/softwareheritage/graph/utils/ReadGraph.java b/java/src/main/java/org/softwareheritage/graph/utils/ReadGraph.java index 998cbce..c760032 100644 --- a/java/src/main/java/org/softwareheritage/graph/utils/ReadGraph.java +++ b/java/src/main/java/org/softwareheritage/graph/utils/ReadGraph.java @@ -1,25 +1,40 @@ package org.softwareheritage.graph.utils; import it.unimi.dsi.big.webgraph.NodeIterator; +import it.unimi.dsi.logging.ProgressLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.softwareheritage.graph.SwhUnidirectionalGraph; import java.io.IOException; +import java.util.concurrent.TimeUnit; public class ReadGraph { + final static Logger logger = LoggerFactory.getLogger(ReadLabelledGraph.class); + public static void main(String[] args) throws IOException { String graphPath = args[0]; - SwhUnidirectionalGraph graph = SwhUnidirectionalGraph.load(graphPath); + SwhUnidirectionalGraph graph; + ProgressLogger pl = new ProgressLogger(logger, 10, TimeUnit.SECONDS); + if (args.length > 1 && (args[1].equals("--mapped") || args[1].equals("-m"))) { + graph = SwhUnidirectionalGraph.loadMapped(graphPath, pl); + } else { + graph = SwhUnidirectionalGraph.load(graphPath, pl); + } + pl.expectedUpdates = graph.numArcs(); + pl.start("Reading graph..."); NodeIterator it = graph.nodeIterator(); while (it.hasNext()) { long srcNode = it.nextLong(); var s = it.successors(); long dstNode; while ((dstNode = s.nextLong()) >= 0) { System.out.format("%s %s\n", graph.getSWHID(srcNode), graph.getSWHID(dstNode)); + pl.lightUpdate(); } } } } diff --git a/java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java b/java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java index a1fcfe4..3c64bbd 100644 --- a/java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java +++ b/java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java @@ -1,35 +1,48 @@ package org.softwareheritage.graph.utils; import it.unimi.dsi.big.webgraph.labelling.ArcLabelledNodeIterator; +import it.unimi.dsi.logging.ProgressLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.softwareheritage.graph.SwhUnidirectionalGraph; import org.softwareheritage.graph.labels.DirEntry; import java.io.IOException; +import java.util.concurrent.TimeUnit; public class ReadLabelledGraph { + final static Logger logger = LoggerFactory.getLogger(ReadLabelledGraph.class); + public static void main(String[] args) throws IOException, ClassNotFoundException { String graphPath = args[0]; - SwhUnidirectionalGraph graph = SwhUnidirectionalGraph.loadLabelled(graphPath); + ProgressLogger pl = new ProgressLogger(logger, 10, TimeUnit.SECONDS); + SwhUnidirectionalGraph graph; + if (args.length > 1 && (args[1].equals("--mapped") || args[1].equals("-m"))) { + graph = SwhUnidirectionalGraph.loadLabelledMapped(graphPath, pl); + } else { + graph = SwhUnidirectionalGraph.loadLabelled(graphPath, pl); + } + graph.properties.loadLabelNames(); ArcLabelledNodeIterator it = graph.labelledNodeIterator(); while (it.hasNext()) { long srcNode = it.nextLong(); ArcLabelledNodeIterator.LabelledArcIterator s = it.successors(); long dstNode; while ((dstNode = s.nextLong()) >= 0) { DirEntry[] labels = (DirEntry[]) s.label().get(); if (labels.length > 0) { for (DirEntry label : labels) { System.out.format("%s %s %s %d\n", graph.getSWHID(srcNode), graph.getSWHID(dstNode), new String(graph.properties.getLabelName(label.filenameId)), label.permission); } } else { System.out.format("%s %s\n", graph.getSWHID(srcNode), graph.getSWHID(dstNode)); } } } } }