public class PajekNetReader
extends java.lang.Object
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 3Here 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
Modifier and Type | Class and Description |
---|---|
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. |
Modifier and Type | Field and Description |
---|---|
protected boolean |
get_locations |
protected static org.apache.commons.collections.Predicate |
l_pred |
static java.lang.String |
LABEL
The key used to identify the vertex labels (if any) created by this class.
|
static java.lang.String |
LOCATIONS
The user data key used to retrieve the vertex locations (if any) defined by this class.
|
protected static org.apache.commons.collections.Predicate |
p_pred |
protected boolean |
unique_labels |
protected SettableVertexLocationFunction |
v_locations |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
protected Edge |
createAddEdge(java.util.StringTokenizer st,
Vertex v1,
boolean directed,
Graph g,
Indexer id,
boolean parallel_ok) |
Graph |
load(java.io.Reader reader)
Returns
load(reader, new SparseGraph(), null) . |
Graph |
load(java.io.Reader reader,
Graph g)
Returns
load(reader, g, null) . |
Graph |
load(java.io.Reader reader,
Graph g,
NumberEdgeValue nev)
Returns
load(reader, g, nev, new TypedVertexGenerator(g)) . |
Graph |
load(java.io.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(java.io.Reader reader,
NumberEdgeValue nev)
Returns
load(reader, new SparseGraph(), nev) . |
Graph |
load(java.lang.String filename)
Returns
load(filename, new SparseGraph(), null) . |
Graph |
load(java.lang.String filename,
Graph g)
Returns
load(filename, g, null) . |
Graph |
load(java.lang.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(java.lang.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 java.lang.String |
skip(java.io.BufferedReader br,
org.apache.commons.collections.Predicate p)
Returns the first line read from
br for which p
returns true , or null if there is no
such line. |
protected boolean unique_labels
public static final java.lang.String LABEL
public static final java.lang.String LOCATIONS
protected SettableVertexLocationFunction v_locations
protected boolean get_locations
protected static final org.apache.commons.collections.Predicate l_pred
protected static final org.apache.commons.collections.Predicate p_pred
public PajekNetReader(boolean unique_labels)
PajekNetReader(boolean, boolean)
public PajekNetReader(boolean unique_labels, boolean get_locations)
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
.
public PajekNetReader(boolean unique_labels, SettableVertexLocationFunction v_locations)
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
.
public PajekNetReader()
public Graph load(java.lang.String filename) throws java.io.IOException
load(filename, new SparseGraph(), null)
.java.io.IOException
public Graph load(java.lang.String filename, NumberEdgeValue nev) throws java.io.IOException
load(filename, new SparseGraph(), nev)
.java.io.IOException
public Graph load(java.lang.String filename, Graph g) throws java.io.IOException
load(filename, g, null)
.java.io.IOException
public Graph load(java.lang.String filename, Graph g, NumberEdgeValue nev) throws java.io.IOException
FileReader
from filename
, calls
load(reader, g, nev)
, closes the reader, and returns
the resultant graph.java.io.IOException
public Graph load(java.io.Reader reader, Graph g) throws java.io.IOException
load(reader, g, null)
.java.io.IOException
public Graph load(java.io.Reader reader, NumberEdgeValue nev) throws java.io.IOException
load(reader, new SparseGraph(), nev)
.java.io.IOException
public Graph load(java.io.Reader reader) throws java.io.IOException
load(reader, new SparseGraph(), null)
.java.io.IOException
public Graph load(java.io.Reader reader, Graph g, NumberEdgeValue nev) throws java.io.IOException
load(reader, g, nev, new TypedVertexGenerator(g))
.java.io.IOException
TypedVertexGenerator
public Graph load(java.io.Reader reader, Graph g, NumberEdgeValue nev, VertexGenerator vg) throws java.io.IOException
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.java.io.IOException
protected Edge createAddEdge(java.util.StringTokenizer st, Vertex v1, boolean directed, Graph g, Indexer id, boolean parallel_ok)
protected java.lang.String skip(java.io.BufferedReader br, org.apache.commons.collections.Predicate p) throws java.io.IOException
br
for which p
returns true
, or null
if there is no
such line.java.io.IOException
public void setUniqueLabels(boolean unique_labels)
unique_labels
boolean.PajekNetReader(boolean, boolean)
public void setGetLocations(boolean get_locations)
get_locations
boolean.PajekNetReader(boolean, boolean)