Class PajekNetReader<G extends edu.uci.ics.jung.graph.Graph<V,E>,V,E>
- java.lang.Object
-
- edu.uci.ics.jung.io.PajekNetReader<G,V,E>
-
public class PajekNetReader<G extends edu.uci.ics.jung.graph.Graph<V,E>,V,E> extends java.lang.ObjectReads aGraphfrom 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
IllegalArgumentExceptionis 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:- vertex ids (each must have a value from 1 to n, where n is the number of vertices)
- vertex labels (must be in quotes if interrupted by whitespace)
- directed edge connections (single or list)
- undirected edge connections (single or list)
- edge weights (not compatible with edges specified in list form)
note: this version of PajekNetReader does not support multiple edge weights, as PajekNetFile does; this behavior is consistent with the NET format. vertex locations (x and y; z coordinate is ignored)
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
- 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
Nested Classes Modifier and Type Class Description protected static classPajekNetReader.ListTagPredA Predicate which evaluates totrueif the argument ends with the string "list".protected static classPajekNetReader.StartsWithPredicateA Predicate which evaluates totrueif the argument starts with the constructor-specified String.
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.collections4.Factory<E>edge_factoryprotected edu.uci.ics.jung.algorithms.util.SettableTransformer<E,java.lang.Number>edge_weightsprotected static org.apache.commons.collections4.Predicate<java.lang.String>l_predprotected org.apache.commons.collections4.Factory<V>vertex_factoryprotected edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.lang.String>vertex_labelsThe map for vertex labels (if any) created by this class.protected edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.awt.geom.Point2D>vertex_locationsThe map for vertex locations (if any) defined by this class.
-
Constructor Summary
Constructors Constructor Description PajekNetReader(org.apache.commons.collections4.Factory<E> edge_factory)Creates a PajekNetReader instance with the specified edge factory, and whose vertex objects correspond to the integer IDs assigned in the file.PajekNetReader(org.apache.commons.collections4.Factory<V> vertex_factory, org.apache.commons.collections4.Factory<E> edge_factory)Creates a PajekNetReader instance with the specified vertex and edge factories.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected EcreateAddEdge(java.util.StringTokenizer st, V v1, edu.uci.ics.jung.graph.util.EdgeType directed, edu.uci.ics.jung.graph.Graph<V,E> g, java.util.List<V> id, org.apache.commons.collections4.Factory<E> edge_factory)edu.uci.ics.jung.algorithms.util.SettableTransformer<E,java.lang.Number>getEdgeWeightTransformer()Returns a transformer from edges to their weights.edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.lang.String>getVertexLabeller()Returns a transformer from vertices to their labels.edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.awt.geom.Point2D>getVertexLocationTransformer()Gload(java.io.Reader reader, G g)Populates the graphgwith the graph represented by the Pajek-format data supplied byreader.Gload(java.io.Reader reader, org.apache.commons.collections4.Factory<? extends G> graph_factory)Returns the graph created by parsing the specified reader, as created by the specified factory.Gload(java.lang.String filename, G g)Returns the graph created by parsing the specified file, by populating the specified graph.Gload(java.lang.String filename, org.apache.commons.collections4.Factory<? extends G> graph_factory)Returns the graph created by parsing the specified file, as created by the specified factory.voidsetEdgeWeightTransformer(edu.uci.ics.jung.algorithms.util.SettableTransformer<E,java.lang.Number> edge_weights)Provides a transformer which will be used to write out edge weights.voidsetVertexLabeller(edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.lang.String> vertex_labels)Provides a transformer which will be used to write out the vertex labels.voidsetVertexLocationTransformer(edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.awt.geom.Point2D> vertex_locations)Provides a transformer which will be used to write out the vertex locations.protected java.lang.Stringskip(java.io.BufferedReader br, org.apache.commons.collections4.Predicate<java.lang.String> p)Returns the first line read frombrfor whichpreturnstrue, ornullif there is no such line.
-
-
-
Field Detail
-
vertex_factory
protected org.apache.commons.collections4.Factory<V> vertex_factory
-
edge_factory
protected org.apache.commons.collections4.Factory<E> edge_factory
-
vertex_labels
protected edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.lang.String> vertex_labels
The map for vertex labels (if any) created by this class.
-
vertex_locations
protected edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.awt.geom.Point2D> vertex_locations
The map for vertex locations (if any) defined by this class.
-
edge_weights
protected edu.uci.ics.jung.algorithms.util.SettableTransformer<E,java.lang.Number> edge_weights
-
l_pred
protected static final org.apache.commons.collections4.Predicate<java.lang.String> l_pred
-
-
Constructor Detail
-
PajekNetReader
public PajekNetReader(org.apache.commons.collections4.Factory<V> vertex_factory, org.apache.commons.collections4.Factory<E> edge_factory)
Creates a PajekNetReader instance with the specified vertex and edge factories.- Parameters:
vertex_factory- the factory to use to create vertex objectsedge_factory- the factory to use to create edge objects
-
PajekNetReader
public PajekNetReader(org.apache.commons.collections4.Factory<E> edge_factory)
Creates a PajekNetReader instance with the specified edge factory, and whose vertex objects correspond to the integer IDs assigned in the file. Note that this requiresVto be assignment-compatible with anIntegervalue.- Parameters:
edge_factory- the factory to use to create edge objects
-
-
Method Detail
-
load
public G load(java.lang.String filename, org.apache.commons.collections4.Factory<? extends G> graph_factory) throws java.io.IOException
Returns the graph created by parsing the specified file, as created by the specified factory.- Throws:
java.io.IOException
-
load
public G load(java.io.Reader reader, org.apache.commons.collections4.Factory<? extends G> graph_factory) throws java.io.IOException
Returns the graph created by parsing the specified reader, as created by the specified factory.- Throws:
java.io.IOException
-
load
public G load(java.lang.String filename, G g) throws java.io.IOException
Returns the graph created by parsing the specified file, by populating the specified graph.- Throws:
java.io.IOException
-
load
public G load(java.io.Reader reader, G g) throws java.io.IOException
Populates the graphgwith the graph represented by the Pajek-format data supplied byreader. Stores edge weights, if any, according tonev(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, ifgonly accepts directed edges, any undirected edges in the input are ignored.- Throws:
java.io.IOException
-
createAddEdge
protected E createAddEdge(java.util.StringTokenizer st, V v1, edu.uci.ics.jung.graph.util.EdgeType directed, edu.uci.ics.jung.graph.Graph<V,E> g, java.util.List<V> id, org.apache.commons.collections4.Factory<E> edge_factory)
-
skip
protected java.lang.String skip(java.io.BufferedReader br, org.apache.commons.collections4.Predicate<java.lang.String> p) throws java.io.IOExceptionReturns the first line read frombrfor whichpreturnstrue, ornullif there is no such line.- Throws:
java.io.IOException
-
getVertexLocationTransformer
public edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.awt.geom.Point2D> getVertexLocationTransformer()
- Returns:
- the vertexLocationTransformer
-
setVertexLocationTransformer
public void setVertexLocationTransformer(edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.awt.geom.Point2D> vertex_locations)
Provides a transformer which will be used to write out the vertex locations.
-
getVertexLabeller
public edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.lang.String> getVertexLabeller()
Returns a transformer from vertices to their labels.
-
setVertexLabeller
public void setVertexLabeller(edu.uci.ics.jung.algorithms.util.SettableTransformer<V,java.lang.String> vertex_labels)
Provides a transformer which will be used to write out the vertex labels.
-
getEdgeWeightTransformer
public edu.uci.ics.jung.algorithms.util.SettableTransformer<E,java.lang.Number> getEdgeWeightTransformer()
Returns a transformer from edges to their weights.
-
setEdgeWeightTransformer
public void setEdgeWeightTransformer(edu.uci.ics.jung.algorithms.util.SettableTransformer<E,java.lang.Number> edge_weights)
Provides a transformer which will be used to write out edge weights.
-
-