import org.graphstream.graph.Graph;
import org.graphstream.graph.implementations.DefaultGraph;
import org.graphstream.stream.file.FileSource;
import org.graphstream.stream.file.FileSourceDGS;

import java.io.*;
import java.util.Locale;

/**
 * The goal of this class is to compute the correlation Dimension of the graph store in a dgs file
 *
 */
public class CorrelationDimension {

	/**
	 * The goal of the function is to add to the input argument graph g all the nodes present in the dgs file at the
	 * argument path.
	 *
	 * @param g graph to which we want to add the nodes
	 * @param path the path to the dgs file where the graph data is store
	 */
	public void add_node_to_graph_from_dgs_file(Graph g, String path) throws IOException {
		FileSource fs = new FileSourceDGS();

		fs.addSink(g);
		try {
			fs.begin(path);

			while (fs.nextEvents()) {
			}
		} catch( IOException e) {
			throw  new IOException(e);
		}
	}

	public static void main(String... args) {
		String path = args[0];
		if (path.endsWith("dgs")) {
			Graph g = new DefaultGraph("graph_test");
			CorrelationDimension correlationDimension = new CorrelationDimension();
			try {
				correlationDimension.add_node_to_graph_from_dgs_file(g, path);
			} catch (IOException e) {
				e.printStackTrace();
			}
			System.out.println("nombre de noeud : " + g.getNodeCount());
		}
	}
}

/* step by step
java.io.IOException: java.io.IOException: org.graphstream.util.parser.ParseException: parse error at (4067;169) : attribute key expected
	at CorrelationDimension.add_node_to_graph_from_dgs_file(CorrelationDimension.java:33)
	at CorrelationDimension.main(CorrelationDimension.java:44)
Caused by: java.io.IOException: org.graphstream.util.parser.ParseException: parse error at (4067;169) : attribute key expected
	at org.graphstream.stream.file.FileSourceParser.nextEvents(FileSourceParser.java:209)
	at CorrelationDimension.add_node_to_graph_from_dgs_file(CorrelationDimension.java:30)
	... 1 more
Caused by: org.graphstream.util.parser.ParseException: parse error at (4067;169) : attribute key expected
	at org.graphstream.stream.file.dgs.DGSParser.parseException(DGSParser.java:786)
	at org.graphstream.stream.file.dgs.DGSParser.attribute(DGSParser.java:373)
	at org.graphstream.stream.file.dgs.DGSParser.attributes(DGSParser.java:347)
	at org.graphstream.stream.file.dgs.DGSParser.next(DGSParser.java:261)
	at org.graphstream.stream.file.FileSourceParser.nextEvents(FileSourceParser.java:207)
	... 2 more
 */


/*
read all
 */