Package es.uam.eps.ir.relison.io.graph
Class TextGraphReader<V>
java.lang.Object
es.uam.eps.ir.relison.io.graph.TextGraphReader<V>
- Type Parameters:
V
- The type of the vertices.
- All Implemented Interfaces:
GraphReader<V>
- Direct Known Subclasses:
TextMultiGraphReader
public class TextGraphReader<V> extends java.lang.Object implements GraphReader<V>
Reads a graph from a file.
The file data format is the following:
nodeA nodeB (weight) (types)
where the weight must appear only if the graph is weighted. Otherwise, this column will be ignored. The type must only appear if it is going to be read. In that case, the fourth column will be read. otherwise, it will be ignored. A weight column must exist in case the types appear, but it can be empty. Every column apart from these ones will be ignored when loading the graph. Columns are separated by a certain delimiter. By default, this delimiter is a tab space.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
delimiter
Field delimiter.private boolean
directed
Indicates if the graph to read is directed (true) or not (false).private boolean
multigraph
Indicates if te graph to read is a multigraph (true) or not (false)private boolean
selfloops
Indicates if the graph to read allows autoloops (true) or not (false).private org.ranksys.formats.parsing.Parser<V>
uParser
Parser for reading the vertices.private boolean
weighted
Indicates if the graph to read is weighted (true) or not (false). -
Constructor Summary
Constructors Modifier Constructor Description protected
TextGraphReader(boolean multigraph, boolean directed, boolean weighted, boolean selfloops, java.lang.String delimiter, org.ranksys.formats.parsing.Parser<V> uParser)
Constructor.TextGraphReader(boolean directed, boolean weighted, boolean selfloops, java.lang.String delimiter, org.ranksys.formats.parsing.Parser<V> uParser)
Constructor. -
Method Summary
Modifier and Type Method Description Graph<V>
read(java.io.InputStream stream)
Given an input stream, reads a file from it (for reading embedded graphs in greater files).Graph<V>
read(java.io.InputStream stream, boolean readWeights, boolean readTypes)
Given an input stream, reads a file from it (for reading embedded graphs in greater files).Graph<V>
read(java.io.InputStream stream, boolean readWeights, boolean readTypes, Index<V> nodes)
Given an input stream, reads a file from it (for reading embedded graphs in greater files).Graph<V>
read(java.lang.String file)
Given a file, reads a graph.Graph<V>
read(java.lang.String file, boolean readWeights, boolean readTypes)
Given a file, reads a graph.Graph<V>
read(java.lang.String file, boolean readWeights, boolean readTypes, Index<V> nodes)
Given an file, reads a graph.
-
Field Details
-
multigraph
private final boolean multigraphIndicates if te graph to read is a multigraph (true) or not (false) -
directed
private final boolean directedIndicates if the graph to read is directed (true) or not (false). -
weighted
private final boolean weightedIndicates if the graph to read is weighted (true) or not (false). -
selfloops
private final boolean selfloopsIndicates if the graph to read allows autoloops (true) or not (false). -
uParser
Parser for reading the vertices. -
delimiter
private final java.lang.String delimiterField delimiter.
-
-
Constructor Details
-
TextGraphReader
public TextGraphReader(boolean directed, boolean weighted, boolean selfloops, java.lang.String delimiter, org.ranksys.formats.parsing.Parser<V> uParser)Constructor.- Parameters:
directed
- Indicates if the graph to read is directed (true) or not (false).weighted
- Indicates if the graph to read is weighted (true) or not (false).selfloops
- Indicates if the graph to read allows autoloops (true) or not (false).delimiter
- Field delimiter.uParser
- Parser for reading the vertices.
-
TextGraphReader
protected TextGraphReader(boolean multigraph, boolean directed, boolean weighted, boolean selfloops, java.lang.String delimiter, org.ranksys.formats.parsing.Parser<V> uParser)Constructor.- Parameters:
multigraph
- Indicates if the graph to read is a multigraph (true) or not (false).directed
- Indicates if the graph to read is directed (true) or not (false).weighted
- Indicates if the graph to read is weighted (true) or not (false).selfloops
- Indicates if the graph to read allows autoloops (true) or not (false).delimiter
- Field delimiter.uParser
- Parser for reading the vertices.
-
-
Method Details
-
read
Description copied from interface:GraphReader
Given a file, reads a graph.- Specified by:
read
in interfaceGraphReader<V>
- Parameters:
file
- The file containing the nodes.- Returns:
- the graph if everything goes ok, null otherwise.
-
read
Description copied from interface:GraphReader
Given a file, reads a graph.- Specified by:
read
in interfaceGraphReader<V>
- Parameters:
file
- The file containing the graph.readWeights
- True if the file contains weights, false otherwise.readTypes
- True if the file contains types, false otherwise.- Returns:
- the graph if everything goes ok, null otherwise.
-
read
Description copied from interface:GraphReader
Given an input stream, reads a file from it (for reading embedded graphs in greater files). By default, assumes the graph contains information about weights, but not about types.- Specified by:
read
in interfaceGraphReader<V>
- Parameters:
stream
- The input stream we read the graph from.- Returns:
- the graph if everything goes ok, null otherwise.
-
read
Description copied from interface:GraphReader
Given an input stream, reads a file from it (for reading embedded graphs in greater files).- Specified by:
read
in interfaceGraphReader<V>
- Parameters:
stream
- The input stream we read the graph from.readWeights
- True if the file contains weights, false otherwise.readTypes
- True if the file contains graph types.- Returns:
- the graph if everything goes ok, null otherwise.
-
read
public Graph<V> read(java.lang.String file, boolean readWeights, boolean readTypes, Index<V> nodes)Description copied from interface:GraphReader
Given an file, reads a graph.- Specified by:
read
in interfaceGraphReader<V>
- Parameters:
file
- The file containing the graph.readWeights
- True if the file contains weights, false otherwise.readTypes
- True if the file contains graph types.nodes
- An index containing the nodes in the network.- Returns:
- the graph if everything goes ok, null otherwise.
-
read
public Graph<V> read(java.io.InputStream stream, boolean readWeights, boolean readTypes, Index<V> nodes)Description copied from interface:GraphReader
Given an input stream, reads a file from it (for reading embedded graphs in greater files).- Specified by:
read
in interfaceGraphReader<V>
- Parameters:
stream
- The input stream we read the graph from.readWeights
- True if the file contains weights, false otherwise.readTypes
- True if the file contains graph types.nodes
- An index containing the nodes in the network.- Returns:
- the graph if everything goes ok, null otherwise.
-