Skip to content

Commit a9bc004

Browse files
Graph exploration: add support for vertex name <> ID mapping
by LiterallySignedStringMap (graph.lmap) Change access of static method reverseDomainName (private -> public)
1 parent 1b54784 commit a9bc004

File tree

1 file changed

+14
-3
lines changed
  • src/main/java/org/commoncrawl/webgraph/explore

1 file changed

+14
-3
lines changed

src/main/java/org/commoncrawl/webgraph/explore/Graph.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import it.unimi.dsi.util.FrontCodedStringList;
3232
import it.unimi.dsi.util.ImmutableExternalPrefixMap;
3333
import it.unimi.dsi.util.Interval;
34+
import it.unimi.dsi.util.LiterallySignedStringMap;
3435
import it.unimi.dsi.util.ShiftAddXorSignedStringMap;
3536
import it.unimi.dsi.webgraph.ImmutableGraph;
3637
import it.unimi.dsi.webgraph.LazyIntIterator;
@@ -56,6 +57,7 @@ public class Graph {
5657
protected FrontCodedStringList vertexMapFcl;
5758
protected ShiftAddXorSignedStringMap vertexMapSmph;
5859
protected GOV4Function<String> vertexMapMph;
60+
protected LiterallySignedStringMap vertexMapLmap;
5961

6062
private static int LAZY_INT_ITERATOR_EMPTY_VALUE = LazyIntIterators.EMPTY_ITERATOR.nextInt();
6163

@@ -84,6 +86,9 @@ public Graph(String name) throws Exception {
8486
} else {
8587
LOG.error("No vertex mapping found, cannot translate from vertex names to IDs.");
8688
}
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");
8792
} else {
8893
LOG.error("No vertex mapping found, cannot translate from vertex names to IDs.");
8994
}
@@ -97,8 +102,12 @@ public Graph(String name) throws Exception {
97102
public String vertexIdToLabel(long id) {
98103
if (vertexMap != null) {
99104
return vertexMap.list().get((int) id).toString();
100-
} else {
105+
} else if (vertexMapFcl != null) {
101106
return vertexMapFcl.get((int) id).toString();
107+
} else if (vertexMapLmap != null) {
108+
return vertexMapLmap.list().get((int) id).toString();
109+
} else {
110+
throw new RuntimeException("No vertex map loaded.");
102111
}
103112
}
104113

@@ -109,6 +118,8 @@ public long vertexLabelToId(String label) {
109118
return vertexMapSmph.getLong(label);
110119
} else if (vertexMapMph != null) {
111120
return vertexMapMph.getLong(label);
121+
} else if (vertexMapLmap != null) {
122+
return vertexMapLmap.getLong(label);
112123
} else {
113124
throw new RuntimeException("No vertex map loaded.");
114125
}
@@ -221,7 +232,7 @@ public Stream<Entry<String, Long>> topLevelDomainCounts(IntStream vertexIds) {
221232
List<Entry<String, Long>> res = new LinkedList<>();
222233
PrimitiveIterator.OfInt iter = vertexIds.iterator();
223234
if (iter.hasNext()) {
224-
int curr = iter.nextInt();;
235+
int curr = iter.nextInt();
225236
do {
226237
final MutableString currLabel = vertexMap.list().get(curr);
227238
final int pos = currLabel.indexOf('.');
@@ -397,7 +408,7 @@ public static String getRegisteredDomainReversed(String reversedHostName, boolea
397408
* "https://en.wikipedia.org/wiki/Reverse_domain_name_notation">reverse
398409
* domain name notation</a> (un)applied
399410
*/
400-
private static String reverseDomainName(String reversedDomainName) {
411+
public static String reverseDomainName(String reversedDomainName) {
401412
return HostToDomainGraph.reverseHost(reversedDomainName);
402413
}
403414
}

0 commit comments

Comments
 (0)