edu.uci.ics.jung.io
Class PajekNetReader

java.lang.Object
  extended by edu.uci.ics.jung.io.PajekNetReader

public class PajekNetReader
extends Object

Reads a Graph from a Pajek NET formatted source.

If the edge constraints specify that the graph is strictly undirected, and an "*Arcs" section is encountered, or if the edge constraints specify that the graph is strictly directed, and an "*Edges" section is encountered, an IllegalArgumentException is thrown.

If the edge constraints do not permit parallel edges, only the first encountered of a set of parallel edges will be read; subsequent edges in that set will be ignored.

More restrictive edge constraints will cause vertices to be generated that are more time- and space-efficient.

At the moment, only supports the part of the specification that defines:

Here is an example format for a directed graph without edge weights and edges specified in list form:

 *vertices <# of vertices> 
 1 "a" 
 2 "b" 
 3 "c" 
 *arcslist 
 1 2 3 
 2 3  
 
Here is an example format for an undirected graph with edge weights and edges specified in non-list form:
 *vertices <# of vertices> 
 1 "a" 
 2 "b" 
 3 "c" 
 *edges 
 1 2 0.1 
 1 3 0.9 
 2 3 1.0 
 

Author:
Joshua O'Madadhain
See Also:
"'Pajek - Program for Analysis and Visualization of Large Networks', Vladimir Batagelj and Andrej Mrvar, http://vlado.fmf.uni-lj.si/pub/networks/pajek/doc/pajekman.pdf"

Nested Class Summary
protected static class PajekNetReader.ListTagPred
          A Predicate which evaluates to true if the argument ends with the string "list".
protected static class PajekNetReader.TagPred
          A Predicate which evaluates to true if the argument starts with the constructor-specified String.
 
Field Summary
protected  boolean get_locations
           
protected static Predicate l_pred
           
static String LABEL
          The key used to identify the vertex labels (if any) created by this class.
static String LOCATIONS
          The user data key used to retrieve the vertex locations (if any) defined by this class.
protected static Predicate p_pred
           
protected  boolean unique_labels
           
protected  SettableVertexLocationFunction v_locations
           
 
Constructor Summary
PajekNetReader()
          Creates a PajekNetReader whose labels are not required to be unique.
PajekNetReader(boolean unique_labels)
          Creates a PajekNetReader with the specified labeling behavior, which does not read location information (if any).
PajekNetReader(boolean unique_labels, boolean get_locations)
          Creates a PajekNetReader with the specified labeling behavior and location assignment behavior.
PajekNetReader(boolean unique_labels, SettableVertexLocationFunction v_locations)
          Creates a PajekNetReader with the specified labeling behavior and location assignment behavior.
 
Method Summary
protected  Edge createAddEdge(StringTokenizer st, Vertex v1, boolean directed, Graph g, Indexer id, boolean parallel_ok)
           
 Graph load(Reader reader)
          Returns load(reader, new SparseGraph(), null).
 Graph load(Reader reader, Graph g)
          Returns load(reader, g, null).
 Graph load(Reader reader, Graph g, NumberEdgeValue nev)
          Returns load(reader, g, nev, new TypedVertexGenerator(g)).
 Graph load(Reader reader, Graph g, NumberEdgeValue nev, VertexGenerator vg)
          Populates the graph g with the graph represented by the Pajek-format data supplied by reader.
 Graph load(Reader reader, NumberEdgeValue nev)
          Returns load(reader, new SparseGraph(), nev).
 Graph load(String filename)
          Returns load(filename, new SparseGraph(), null).
 Graph load(String filename, Graph g)
          Returns load(filename, g, null).
 Graph load(String filename, Graph g, NumberEdgeValue nev)
          Creates a FileReader from filename, calls load(reader, g, nev), closes the reader, and returns the resultant graph.
 Graph load(String filename, NumberEdgeValue nev)
          Returns load(filename, new SparseGraph(), nev).
 void setGetLocations(boolean get_locations)
          Sets or clears the get_locations boolean.
 void setUniqueLabels(boolean unique_labels)
          Sets or clears the unique_labels boolean.
protected  String skip(BufferedReader br, Predicate p)
          Returns the first line read from br for which p returns true, or null if there is no such line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unique_labels

protected boolean unique_labels

LABEL

public static final String LABEL
The key used to identify the vertex labels (if any) created by this class.

See Also:
Constant Field Values

LOCATIONS

public static final String LOCATIONS
The user data key used to retrieve the vertex locations (if any) defined by this class.

See Also:
Constant Field Values

v_locations

protected SettableVertexLocationFunction v_locations

get_locations

protected boolean get_locations

l_pred

protected static final Predicate l_pred

p_pred

protected static final Predicate p_pred
Constructor Detail

PajekNetReader

public PajekNetReader(boolean unique_labels)
Creates a PajekNetReader with the specified labeling behavior, which does not read location information (if any).

See Also:
PajekNetReader(boolean, boolean)

PajekNetReader

public PajekNetReader(boolean unique_labels,
                      boolean get_locations)
Creates a PajekNetReader with the specified labeling behavior and location assignment behavior.

If unique_labels is true, vertices will be labelled using a StringLabeller with key jung.io.PajekNetReader.LABEL. Otherwise, they will be labeled with a user data String with key PajekNetReader.LABEL. (Vertices that have no apparent label information will not be labelled.)

If get_locations is true, each vertex line in the file will be assumed to contain (x,y) coordinates in the range [0,1]; if any line lacks this data, an IllegalArgumentException will be thrown. (The Pajek format assumes coordinates are (x,y,z) but we ignore the z-coordinate.) Location data will be stored in a SettabelVertexLocationDecorator instance in the graph's user data with keyjung.io.PajekNetReader.LOCATIONS.


PajekNetReader

public PajekNetReader(boolean unique_labels,
                      SettableVertexLocationFunction v_locations)
Creates a PajekNetReader with the specified labeling behavior and location assignment behavior.

If unique_labels is true, vertices will be labelled using a StringLabeller with key jung.io.PajekNetReader.LABEL. Otherwise, they will be labeled with a user data String with key PajekNetReader.LABEL. (Vertices that have no apparent label information will not be labelled.)

If get_locations is true, each vertex line in the file will be assumed to contain (x,y) coordinates in the range [0,1]; if any line lacks this data, an IllegalArgumentException will be thrown. (The Pajek format assumes coordinates are (x,y,z) but we ignore the z-coordinate.) Location data will be stored in v_locations, a reference to which will be stored in the graph's user data with key jung.io.PajekNetReader.LOCATIONS.


PajekNetReader

public PajekNetReader()
Creates a PajekNetReader whose labels are not required to be unique.

Method Detail

load

public Graph load(String filename)
           throws IOException
Returns load(filename, new SparseGraph(), null).

Throws:
IOException

load

public Graph load(String filename,
                  NumberEdgeValue nev)
           throws IOException
Returns load(filename, new SparseGraph(), nev).

Throws:
IOException

load

public Graph load(String filename,
                  Graph g)
           throws IOException
Returns load(filename, g, null).

Throws:
IOException

load

public Graph load(String filename,
                  Graph g,
                  NumberEdgeValue nev)
           throws IOException
Creates a FileReader from filename, calls load(reader, g, nev), closes the reader, and returns the resultant graph.

Throws:
IOException

load

public Graph load(Reader reader,
                  Graph g)
           throws IOException
Returns load(reader, g, null).

Throws:
IOException

load

public Graph load(Reader reader,
                  NumberEdgeValue nev)
           throws IOException
Returns load(reader, new SparseGraph(), nev).

Throws:
IOException

load

public Graph load(Reader reader)
           throws IOException
Returns load(reader, new SparseGraph(), null).

Throws:
IOException

load

public Graph load(Reader reader,
                  Graph g,
                  NumberEdgeValue nev)
           throws IOException
Returns load(reader, g, nev, new TypedVertexGenerator(g)).

Throws:
IOException
See Also:
TypedVertexGenerator

load

public Graph load(Reader reader,
                  Graph g,
                  NumberEdgeValue nev,
                  VertexGenerator vg)
           throws IOException
Populates the graph g with the graph represented by the Pajek-format data supplied by reader. Stores edge weights, if any, according to nev (if non-null). Any existing vertices/edges of g, if any, are unaffected. The edge data are filtered according to g's constraints, if any; thus, if g only accepts directed edges, any undirected edges in the input are ignored. Vertices are created with the generator vg. The user is responsible for supplying a generator whose output is compatible with this graph and its contents; users that don't want to deal with this issue may use a TypedVertexGenerator or call load(reader, g, nev) for a default generator.

Throws:
IOException

createAddEdge

protected Edge createAddEdge(StringTokenizer st,
                             Vertex v1,
                             boolean directed,
                             Graph g,
                             Indexer id,
                             boolean parallel_ok)

skip

protected String skip(BufferedReader br,
                      Predicate p)
               throws IOException
Returns the first line read from br for which p returns true, or null if there is no such line.

Throws:
IOException

setUniqueLabels

public void setUniqueLabels(boolean unique_labels)
Sets or clears the unique_labels boolean.

See Also:
PajekNetReader(boolean, boolean)

setGetLocations

public void setGetLocations(boolean get_locations)
Sets or clears the get_locations boolean.

See Also:
PajekNetReader(boolean, boolean)