Package org.deeplearning4j.graph.data
Class GraphLoader
- java.lang.Object
-
- org.deeplearning4j.graph.data.GraphLoader
-
public class GraphLoader extends Object
Utility methods for loading graphs
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V,E>
Graph<V,E>loadGraph(String vertexFilePath, String edgeFilePath, VertexLoader<V> vertexLoader, EdgeLineProcessor<E> edgeLineProcessor, boolean allowMultipleEdges)
Load graph, assuming vertices are in one file and edges are in another file.static <V,E>
Graph<V,E>loadGraph(String path, EdgeLineProcessor<E> lineProcessor, VertexFactory<V> vertexFactory, int numVertices, boolean allowMultipleEdges)
Load a graph into memory, using a given EdgeLineProcessor.static Graph<String,String>
loadUndirectedGraphEdgeListFile(String path, int numVertices, String delim)
Simple method for loading an undirected graph, where the graph is represented by a edge list with one edge per line with a delimiter in between
This method assumes that all lines in the file are of the formi<delim>j
where i and j are integers in range 0 to numVertices inclusive, and "" is the user-provided delimiter Note: this method calls loadUndirectedGraphEdgeListFile(String, int, String, boolean)
with allowMultipleEdges = true.static Graph<String,String>
loadUndirectedGraphEdgeListFile(String path, int numVertices, String delim, boolean allowMultipleEdges)
Simple method for loading an undirected graph, where the graph is represented by a edge list with one edge per line with a delimiter in between
This method assumes that all lines in the file are of the formi<delim>j
where i and j are integers in range 0 to numVertices inclusive, and "" is the user-provided delimiter static Graph<String,Double>
loadWeightedEdgeListFile(String path, int numVertices, String delim, boolean directed, boolean allowMultipleEdges, String... ignoreLinesStartingWith)
Method for loading a weighted graph from an edge list file, where each edge (inc.static Graph<String,Double>
loadWeightedEdgeListFile(String path, int numVertices, String delim, boolean directed, String... ignoreLinesStartingWith)
Method for loading a weighted graph from an edge list file, where each edge (inc.
-
-
-
Method Detail
-
loadUndirectedGraphEdgeListFile
public static Graph<String,String> loadUndirectedGraphEdgeListFile(String path, int numVertices, String delim) throws IOException
Simple method for loading an undirected graph, where the graph is represented by a edge list with one edge per line with a delimiter in between
This method assumes that all lines in the file are of the formi<delim>j
where i and j are integers in range 0 to numVertices inclusive, and "" is the user-provided delimiter Note: this method calls loadUndirectedGraphEdgeListFile(String, int, String, boolean)
with allowMultipleEdges = true.- Parameters:
path
- Path to the edge list filenumVertices
- number of vertices in the graph- Returns:
- graph
- Throws:
IOException
- if file cannot be read
-
loadUndirectedGraphEdgeListFile
public static Graph<String,String> loadUndirectedGraphEdgeListFile(String path, int numVertices, String delim, boolean allowMultipleEdges) throws IOException
Simple method for loading an undirected graph, where the graph is represented by a edge list with one edge per line with a delimiter in between
This method assumes that all lines in the file are of the formi<delim>j
where i and j are integers in range 0 to numVertices inclusive, and "" is the user-provided delimiter - Parameters:
path
- Path to the edge list filenumVertices
- number of vertices in the graphallowMultipleEdges
- If set to false, the graph will not allow multiple edges between any two vertices to exist. However, checking for duplicates during graph loading can be costly, so use allowMultipleEdges=true when possible.- Returns:
- graph
- Throws:
IOException
- if file cannot be read
-
loadWeightedEdgeListFile
public static Graph<String,Double> loadWeightedEdgeListFile(String path, int numVertices, String delim, boolean directed, String... ignoreLinesStartingWith) throws IOException
Method for loading a weighted graph from an edge list file, where each edge (inc. weight) is represented by a single line. Graph may be directed or undirected
This method assumes that edges are of the format:fromIndex<delim>toIndex<delim>edgeWeight
where<delim>
is the delimiter. Note: this method callsloadWeightedEdgeListFile(String, int, String, boolean, boolean, String...)
with allowMultipleEdges = true.- Parameters:
path
- Path to the edge list filenumVertices
- The number of vertices in the graphdelim
- The delimiter used in the file (typically: "," or " " etc)directed
- whether the edges should be treated as directed (true) or undirected (false)ignoreLinesStartingWith
- Starting characters for comment lines. May be null. For example: "//" or "#"- Returns:
- The graph
- Throws:
IOException
-
loadWeightedEdgeListFile
public static Graph<String,Double> loadWeightedEdgeListFile(String path, int numVertices, String delim, boolean directed, boolean allowMultipleEdges, String... ignoreLinesStartingWith) throws IOException
Method for loading a weighted graph from an edge list file, where each edge (inc. weight) is represented by a single line. Graph may be directed or undirected
This method assumes that edges are of the format:fromIndex<delim>toIndex<delim>edgeWeight
where<delim>
is the delimiter.- Parameters:
path
- Path to the edge list filenumVertices
- The number of vertices in the graphdelim
- The delimiter used in the file (typically: "," or " " etc)directed
- whether the edges should be treated as directed (true) or undirected (false)allowMultipleEdges
- If set to false, the graph will not allow multiple edges between any two vertices to exist. However, checking for duplicates during graph loading can be costly, so use allowMultipleEdges=true when possible.ignoreLinesStartingWith
- Starting characters for comment lines. May be null. For example: "//" or "#"- Returns:
- The graph
- Throws:
IOException
-
loadGraph
public static <V,E> Graph<V,E> loadGraph(String path, EdgeLineProcessor<E> lineProcessor, VertexFactory<V> vertexFactory, int numVertices, boolean allowMultipleEdges) throws IOException
Load a graph into memory, using a given EdgeLineProcessor. Assume one edge per line- Parameters:
path
- Path to the file containing the edges, one per linelineProcessor
- EdgeLineProcessor used to convert lines of text into a graph (or null for comment lines etc)vertexFactory
- Used to create verticesnumVertices
- number of vertices in the graphallowMultipleEdges
- whether the graph should allow multiple edges between a given pair of vertices or not- Returns:
- IGraph
- Throws:
IOException
-
loadGraph
public static <V,E> Graph<V,E> loadGraph(String vertexFilePath, String edgeFilePath, VertexLoader<V> vertexLoader, EdgeLineProcessor<E> edgeLineProcessor, boolean allowMultipleEdges) throws IOException
Load graph, assuming vertices are in one file and edges are in another file.- Parameters:
vertexFilePath
- Path to file containing vertices, one per lineedgeFilePath
- Path to the file containing edges, one per linevertexLoader
- VertexLoader, for loading vertices from the fileedgeLineProcessor
- EdgeLineProcessor, converts text lines into edgesallowMultipleEdges
- whether the graph should allow (or filter out) multiple edges- Returns:
- IGraph loaded from files
- Throws:
IOException
-
-