MCPcopy Create free account
hub / github.com/commoncrawl/cc-webgraph / Graph

Class Graph

src/main/java/org/commoncrawl/webgraph/explore/Graph.java:44–532  ·  view source on GitHub ↗

Holds webgraph-related data structures and access methods for graph exploration.

Source from the content-addressed store, hash-verified

42 * exploration.
43 */
44public class Graph {
45
46 private static Logger LOG = LoggerFactory.getLogger(Graph.class);
47
48 /** The base name of the graph */
49 public String name;
50 /** The graph */
51 public ImmutableGraph graph;
52 /** The transpose of the graph */
53 public ImmutableGraph graphT;
54
55 /* Maps to translate between vertex label an ID */
56 protected ImmutableExternalPrefixMap vertexMap;
57 protected FrontCodedStringList vertexMapFcl;
58 protected ShiftAddXorSignedStringMap vertexMapSmph;
59 protected GOV4Function<String> vertexMapMph;
60 protected LiterallySignedStringMap vertexMapLmap;
61
62 private static int LAZY_INT_ITERATOR_EMPTY_VALUE = LazyIntIterators.EMPTY_ITERATOR.nextInt();
63
64 public Graph(String name) throws Exception {
65 this.name = name;
66 try {
67 LOG.info("Loading graph {}.graph", name);
68 graph = ImmutableGraph.loadMapped(name);
69 LOG.info("Loading transpose of the graph {}-t.graph", name);
70 graphT = ImmutableGraph.loadMapped(name + "-t");
71 if (Files.exists(Paths.get(name + ".iepm"))) {
72 LOG.info("Loading vertex map {}.iepm (ImmutableExternalPrefixMap)", name);
73 vertexMap = (ImmutableExternalPrefixMap) BinIO.loadObject(name + ".iepm");
74 } else if (Files.exists(Paths.get(name + ".fcl"))) {
75 LOG.info("Loading vertex map {}.fcl (FrontCodedStringList, maps vertex IDs to labels)", name);
76 vertexMapFcl = (FrontCodedStringList) BinIO.loadObject(name + ".fcl");
77 if (Files.exists(Paths.get(name + ".smph"))) {
78 LOG.info("Loading vertex map {}.smph (string map perfect hash, maps vertex labels to IDs)", name);
79 vertexMapSmph = (ShiftAddXorSignedStringMap) BinIO.loadObject(name + ".smph");
80 } else if (Files.exists(Paths.get(name + ".mph"))) {
81 LOG.info("Loading vertex map {}.mph (minimal perfect hash, maps vertex labels to IDs)", name);
82 vertexMapMph = (GOV4Function<String>) BinIO.loadObject(name + ".mph");
83 LOG.warn(
84 "Using a minimal perfect hash as vertex map does not allow to verify that a vertex label exists. "
85 + "Non-existant labels are mapped to quasi-random IDs.");
86 } else {
87 LOG.error("No vertex mapping found, cannot translate from vertex names to IDs.");
88 }
89 } else if (Files.exists(Paths.get(name + ".lmap"))) {
90 LOG.info("Loading vertex map {}.lmap (LiterallySignedStringMap)", name);
91 vertexMapLmap = (LiterallySignedStringMap) BinIO.loadObject(name + ".lmap");
92 } else {
93 LOG.error("No vertex mapping found, cannot translate from vertex names to IDs.");
94 }
95 } catch (IOException | ClassNotFoundException e) {
96 LOG.error("Failed to load graph {}:", name, e);
97 throw e;
98 }
99 LOG.info("Loaded graph {}.graph", name);
100 }
101

Callers

nothing calls this directly

Calls 1

nextIntMethod · 0.80

Tested by

no test coverage detected