Class ArcListASCIIGraph
- java.lang.Object
-
- it.unimi.dsi.big.webgraph.ImmutableGraph
-
- it.unimi.dsi.big.webgraph.ImmutableSequentialGraph
-
- it.unimi.dsi.big.webgraph.ArcListASCIIGraph
-
- All Implemented Interfaces:
it.unimi.dsi.lang.FlyweightPrototype<ImmutableGraph>
- Direct Known Subclasses:
ShiftedByOneArcListASCIIGraph
public class ArcListASCIIGraph extends ImmutableSequentialGraph
AnImmutableGraphthat corresponds to graphs stored in a human-readable ASCII format were each line contains an arc.The file format is very simple: each line contains an arc specified as two nodes separated by whitespace (but we suggest exactly one TAB character). Sources must be in increasing order, but targets can be in any order. The constructor provides an additional parameter, called shift, which will be added to all node indices. The default is 0, but for lists that number nodes starting from 1 it can be set to -1. Actually, the class
ShiftedByOneArcListASCIIGraphcan be used in place of this class for setting the shift to -1 without specifying additional parameters.Contrarily to other classes, the load methods of this class do not always return instances of this class. In particular,
loadOnce(InputStream)will return an instance of this class for read-once access. The instance will not provide offline or random access, but read-once access will be backed by the original input stream and only the successors of a single node will be loaded in core memory at any time.The
load(CharSequence)method, on the other hand, will return a wrapped instance ofArrayListMutableGraphbuilt by copying a wrapped offline instance of this class: thus, it is limited to non-big graphs.Using
ArcListASCIIGraphto convert your dataA simple (albeit rather inefficient) way to import data into WebGraph is using ASCII graphs specified by arc lists. Suppose you create the following file, named
example.arcs:0 1 1 2 2 1
Then, the commandjava it.unimi.dsi.webgraph.BVGraph -g ArcListASCIIGraph example.arcs bvexample
will produce a compressed graph inBVGraphformat with basenamebvexample. Even more convenient, and extremely more efficient, is theloadOnce(InputStream)method, which reads from an input stream an arc-list ASCII graph and exposes it for a single traversal. It can be used, for instance, with the main method ofBVGraphto generate somehow an arc-list ASCII graph and store it in compressed form on the fly. The previous example could be then rewritten asjava it.unimi.dsi.webgraph.BVGraph -1 -g ArcListASCIIGraph dummy bvexample <example.arcs
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class it.unimi.dsi.big.webgraph.ImmutableGraph
ImmutableGraph.LoadMethod
-
-
Field Summary
-
Fields inherited from class it.unimi.dsi.big.webgraph.ImmutableGraph
GRAPHCLASS_PROPERTY_KEY, NUMBER_OF_THREADS_PROPERTY, PROPERTIES_EXTENSION
-
-
Constructor Summary
Constructors Constructor Description ArcListASCIIGraph(java.io.InputStream is, int shift)Creates a read-once arc-list ASCII graph.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ImmutableGraphload(java.lang.CharSequence basename)static ImmutableGraphload(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)static ImmutableGraphloadMapped(java.lang.CharSequence basename)static ImmutableGraphloadMapped(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)static ImmutableGraphloadOffline(java.lang.CharSequence basename)static ImmutableGraphloadOffline(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)static ArcListASCIIGraphloadOnce(java.io.InputStream is)static ArcListASCIIGraphloadOnce(java.io.InputStream is, int shift)static ImmutableGraphloadSequential(java.lang.CharSequence basename)Deprecated.static ImmutableGraphloadSequential(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)Deprecated.static voidmain(java.lang.String[] args)NodeIteratornodeIterator(long from)Returns a node iterator for scanning the graph sequentially, starting from the given node.longnumNodes()Returns the number of nodes of this graph.static voidstore(ImmutableGraph graph, java.lang.CharSequence basename)static voidstore(ImmutableGraph graph, java.lang.CharSequence basename, int shift)Stores an arc-list ASCII graph with a given shift.static voidstore(ImmutableGraph graph, java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused)-
Methods inherited from class it.unimi.dsi.big.webgraph.ImmutableSequentialGraph
copy, outdegree, randomAccess, successorBigArray
-
Methods inherited from class it.unimi.dsi.big.webgraph.ImmutableGraph
basename, equals, hasCopiableIterators, hashCode, intNumNodes, load, nodeIterator, numArcs, outdegrees, splitNodeIterators, store, store, successors, toString, wrap, wrap
-
-
-
-
Constructor Detail
-
ArcListASCIIGraph
public ArcListASCIIGraph(java.io.InputStream is, int shift) throws java.lang.NumberFormatException, java.io.IOExceptionCreates a read-once arc-list ASCII graph. Instances created using this constructor can be only accessed using a single call tonodeIterator(long).- Parameters:
is- an input stream containing an arc-list ASCII graph.- Throws:
java.lang.NumberFormatExceptionjava.io.IOException
-
-
Method Detail
-
numNodes
public long numNodes()
Description copied from class:ImmutableGraphReturns the number of nodes of this graph.Albeit this method is not optional, it is allowed that this method throws an
UnsupportedOperationExceptionif this graph has never been entirely traversed using anode iterator. This apparently bizarre behaviour is necessary to support implementations asArcListASCIIGraph, which do not know the actual number of nodes until a traversal has been completed.- Specified by:
numNodesin classImmutableGraph- Returns:
- the number of nodes.
-
nodeIterator
public NodeIterator nodeIterator(long from)
Description copied from class:ImmutableGraphReturns a node iterator for scanning the graph sequentially, starting from the given node.- Overrides:
nodeIteratorin classImmutableSequentialGraph- Parameters:
from- the node from which the iterator will iterate.- Returns:
- a
NodeIteratorfor accessing nodes and successors sequentially.
-
loadSequential
@Deprecated public static ImmutableGraph loadSequential(java.lang.CharSequence basename) throws java.io.IOException
Deprecated.- Throws:
java.io.IOException
-
loadSequential
@Deprecated public static ImmutableGraph loadSequential(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
Deprecated.- Throws:
java.io.IOException
-
loadOffline
public static ImmutableGraph loadOffline(java.lang.CharSequence basename) throws java.io.IOException
- Throws:
java.io.IOException
-
loadOffline
public static ImmutableGraph loadOffline(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
- Throws:
java.io.IOException
-
loadMapped
public static ImmutableGraph loadMapped(java.lang.CharSequence basename) throws java.io.IOException
- Throws:
java.io.IOException
-
loadMapped
public static ImmutableGraph loadMapped(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
- Throws:
java.io.IOException
-
loadOnce
public static ArcListASCIIGraph loadOnce(java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.IOException
-
loadOnce
public static ArcListASCIIGraph loadOnce(java.io.InputStream is, int shift) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public static ImmutableGraph load(java.lang.CharSequence basename) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public static ImmutableGraph load(java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(ImmutableGraph graph, java.lang.CharSequence basename, it.unimi.dsi.logging.ProgressLogger unused) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(ImmutableGraph graph, java.lang.CharSequence basename) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public static void store(ImmutableGraph graph, java.lang.CharSequence basename, int shift) throws java.io.IOException
Stores an arc-list ASCII graph with a given shift.- Parameters:
graph- a graph to be stored.basename- the name of the output file.shift- a shift that will be added to each node; note that is the opposite of the shift that will have to be used to load the generated file.- Throws:
java.io.IOException
-
main
public static void main(java.lang.String[] args) throws java.lang.IllegalArgumentException, java.lang.SecurityException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.io.IOException, com.martiansoftware.jsap.JSAPException- Throws:
java.lang.IllegalArgumentExceptionjava.lang.SecurityExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.NoSuchMethodExceptionjava.io.IOExceptioncom.martiansoftware.jsap.JSAPException
-
-