Class CSVImporter<V,E>
- Type Parameters:
V- the graph vertex typeE- the graph edge type
- All Implemented Interfaces:
GraphImporter<V,E>
The importer supports various different formats which can be adjusted using the
setFormat method. The supported formats are the same CSV formats
used by Gephi . For some
of the formats, the behavior of the importer can be adjusted using the
setParameter method. See
CSVFormat for a description of the formats.
The importer respects rfc4180. The caller can also adjust the separator to something like semicolon or pipe instead of comma. In such a case, all fields are unescaped using the new separator. See Delimiter- separated values for more information.
This importer does not distinguish between CSVFormat.EDGE_LIST and
CSVFormat.ADJACENCY_LIST. In both cases it assumes the format is
CSVFormat.ADJACENCY_LIST.
The graph vertices and edges are build using the corresponding graph suppliers. The id of the vertices in the original file are reported as a vertex attribute named "ID".
The default behavior of the importer is to use the graph vertex supplier in order to create
vertices. The user can also bypass vertex creation by providing a custom vertex factory method
using setVertexFactory(Function). The factory method is responsible to create a new
graph vertex given the vertex identifier read from file.
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final charprivate static final Stringprivate static final Stringprivate charprivate CSVFormatprivate final Set<CSVFormat.Parameter> -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new importer using theCSVFormat.ADJACENCY_LISTformat as default.CSVImporter(CSVFormat format) Constructs a new importer.CSVImporter(CSVFormat format, char delimiter) Constructs a new importer. -
Method Summary
Modifier and TypeMethodDescriptioncharGet the delimiter (comma, semicolon, pipe, etc).Get the format that the importer is using.Get the user custom vertex factory.voidimportGraph(Graph<V, E> graph, Reader input) Import a graph.booleanReturn if a particular parameter of the exporter is enabledvoidsetDelimiter(char delimiter) Set the delimiter (comma, semicolon, pipe, etc).voidSet the format of the importervoidsetParameter(CSVFormat.Parameter p, boolean value) Set the value of a parameter of the exportervoidsetVertexFactory(Function<String, V> vertexFactory) Set the user custom vertex factory.Methods inherited from class BaseEventDrivenImporter
addEdgeAttributeConsumer, addEdgeConsumer, addEdgeCountConsumer, addEdgeWithAttributesConsumer, addGraphAttributeConsumer, addImportEventConsumer, addVertexAttributeConsumer, addVertexConsumer, addVertexCountConsumer, addVertexWithAttributesConsumer, notifyEdge, notifyEdgeAttribute, notifyEdgeCount, notifyEdgeWithAttributes, notifyGraphAttribute, notifyImportEvent, notifyVertex, notifyVertexAttribute, notifyVertexCount, notifyVertexWithAttributes, removeEdgeAttributeConsumer, removeEdgeConsumer, removeEdgeCountConsumer, removeEdgeWithAttributesConsumer, removeGraphAttributeConsumer, removeImportEventConsumer, removeVertexAttributeConsumer, removeVertexConsumer, removeVertexCountConsumer, removeVertexWithAttributesConsumerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface GraphImporter
importGraph, importGraph
-
Field Details
-
DEFAULT_DELIMITER
private static final char DEFAULT_DELIMITER- See Also:
-
DEFAULT_VERTEX_ID_KEY
- See Also:
-
DEFAULT_WEIGHT_KEY
- See Also:
-
format
-
delimiter
private char delimiter -
parameters
-
vertexFactory
-
-
Constructor Details
-
CSVImporter
public CSVImporter()Constructs a new importer using theCSVFormat.ADJACENCY_LISTformat as default. -
CSVImporter
Constructs a new importer.- Parameters:
format- format to use out of the supported ones
-
CSVImporter
Constructs a new importer.- Parameters:
format- format to use out of the supported onesdelimiter- delimiter to use (comma, semicolon, pipe, etc.)
-
-
Method Details
-
getFormat
-
setFormat
Set the format of the importer- Parameters:
format- the format to use
-
getDelimiter
public char getDelimiter()Get the delimiter (comma, semicolon, pipe, etc).- Returns:
- the delimiter
-
setDelimiter
public void setDelimiter(char delimiter) Set the delimiter (comma, semicolon, pipe, etc).- Parameters:
delimiter- the delimiter to use
-
isParameter
Return if a particular parameter of the exporter is enabled- Parameters:
p- the parameter- Returns:
trueif the parameter is set,falseotherwise
-
setParameter
Set the value of a parameter of the exporter- Parameters:
p- the parametervalue- the value to set
-
getVertexFactory
-
setVertexFactory
Set the user custom vertex factory. The default behavior is being null in which case the graph vertex supplier is used. If supplied the vertex factory is called every time a new vertex is encountered in the file. The method is called with parameter the vertex identifier from the file and should return the actual graph vertex to add to the graph.- Parameters:
vertexFactory- a vertex factory
-
importGraph
Import a graph.The provided graph must be able to support the features of the graph that is read. For example if the input contains self-loops then the graph provided must also support self-loops. The same for multiple edges.
If the provided graph is a weighted graph, the importer also reads edge weights.
- Specified by:
importGraphin interfaceGraphImporter<V,E> - Parameters:
graph- the graphinput- the input reader- Throws:
ImportException- in case an error occurs, such as I/O or parse error
-