public class PajekNetReader<G extends Graph<V,E>,V,E> extends 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.StartsWithPredicate
A Predicate which evaluates to
true if the
argument starts with the constructor-specified String. |
Modifier and Type | Field and Description |
---|---|
protected com.google.common.base.Supplier<E> |
edge_factory |
protected SettableTransformer<E,Number> |
edge_weights |
protected static com.google.common.base.Predicate<String> |
l_pred |
protected com.google.common.base.Supplier<V> |
vertex_factory |
protected SettableTransformer<V,String> |
vertex_labels
The map for vertex labels (if any) created by this class.
|
protected SettableTransformer<V,Point2D> |
vertex_locations
The map for vertex locations (if any) defined by this class.
|
Constructor and Description |
---|
PajekNetReader(com.google.common.base.Supplier<E> edge_factory)
Creates a PajekNetReader instance with the specified edge Supplier,
and whose vertex objects correspond to the integer IDs assigned in the file.
|
PajekNetReader(com.google.common.base.Supplier<V> vertex_factory,
com.google.common.base.Supplier<E> edge_factory)
Creates a PajekNetReader instance with the specified vertex and edge factories.
|
Modifier and Type | Method and Description |
---|---|
protected E |
createAddEdge(StringTokenizer st,
V v1,
EdgeType directed,
Graph<V,E> g,
List<V> id,
com.google.common.base.Supplier<E> edge_factory) |
SettableTransformer<E,Number> |
getEdgeWeightTransformer() |
SettableTransformer<V,String> |
getVertexLabeller() |
SettableTransformer<V,Point2D> |
getVertexLocationTransformer() |
G |
load(Reader reader,
G g)
Populates the graph
g with the graph represented by the
Pajek-format data supplied by reader . |
G |
load(Reader reader,
com.google.common.base.Supplier<? extends G> graph_factory)
Returns the graph created by parsing the specified reader, as created
by the specified Supplier.
|
G |
load(String filename,
G g)
Returns the graph created by parsing the specified file, by populating the
specified graph.
|
G |
load(String filename,
com.google.common.base.Supplier<? extends G> graph_factory)
Returns the graph created by parsing the specified file, as created
by the specified Supplier.
|
void |
setEdgeWeightTransformer(SettableTransformer<E,Number> edge_weights)
Provides a Function which will be used to write out edge weights.
|
void |
setVertexLabeller(SettableTransformer<V,String> vertex_labels)
Provides a Function which will be used to write out the vertex labels.
|
void |
setVertexLocationTransformer(SettableTransformer<V,Point2D> vertex_locations)
Provides a Function which will be used to write out the vertex locations.
|
protected String |
skip(BufferedReader br,
com.google.common.base.Predicate<String> p)
Returns the first line read from
br for which p
returns true , or null if there is no
such line. |
protected com.google.common.base.Supplier<V> vertex_factory
protected com.google.common.base.Supplier<E> edge_factory
protected SettableTransformer<V,String> vertex_labels
protected SettableTransformer<V,Point2D> vertex_locations
protected SettableTransformer<E,Number> edge_weights
protected static final com.google.common.base.Predicate<String> l_pred
public PajekNetReader(com.google.common.base.Supplier<V> vertex_factory, com.google.common.base.Supplier<E> edge_factory)
vertex_factory
- the Supplier to use to create vertex objectsedge_factory
- the Supplier to use to create edge objectspublic PajekNetReader(com.google.common.base.Supplier<E> edge_factory)
V
to be assignment-compatible with
an Integer
value.edge_factory
- the Supplier to use to create edge objectspublic G load(String filename, com.google.common.base.Supplier<? extends G> graph_factory) throws IOException
filename
- the file from which the graph is to be readgraph_factory
- used to provide a graph instanceIOException
- if the graph cannot be loadedpublic G load(Reader reader, com.google.common.base.Supplier<? extends G> graph_factory) throws IOException
reader
- the reader instance from which the graph is to be readgraph_factory
- used to provide a graph instanceIOException
- if the graph cannot be loadedpublic G load(String filename, G g) throws IOException
filename
- the file from which the graph is to be readg
- the graph instance to populateIOException
- if the graph cannot be loadedpublic G load(Reader reader, G g) throws 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.
reader
- the reader from which the graph is to be readg
- the graph instance to populateIOException
- if the graph cannot be loadedprotected E createAddEdge(StringTokenizer st, V v1, EdgeType directed, Graph<V,E> g, List<V> id, com.google.common.base.Supplier<E> edge_factory)
protected String skip(BufferedReader br, com.google.common.base.Predicate<String> p) throws IOException
br
for which p
returns true
, or null
if there is no
such line.br
- the reader from which the graph is being readp
- predicate specifying what line to acceptbr
that matches p
, or nullIOException
- if an error is encountered while reading from br
public SettableTransformer<V,Point2D> getVertexLocationTransformer()
public void setVertexLocationTransformer(SettableTransformer<V,Point2D> vertex_locations)
vertex_locations
- a container for the vertex locationspublic SettableTransformer<V,String> getVertexLabeller()
public void setVertexLabeller(SettableTransformer<V,String> vertex_labels)
vertex_labels
- a container for the vertex labelspublic SettableTransformer<E,Number> getEdgeWeightTransformer()
public void setEdgeWeightTransformer(SettableTransformer<E,Number> edge_weights)
edge_weights
- a container for the edge weightsCopyright © 2015. All rights reserved.