gephi / gephi/gephi-toolkit-demos

how to export csv table by gephi-toolkit

Open
#7 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
96
Forks
89
Avg merge
3d 14h
Merged PRs (30d)
2

Description

recently I'm trying to use gephi-toolkit to do some statistics for several networks,it works fine to import the csv file and do some metrics computation, but if I want to export the csv table like what I do below in the Gephi, I do not find any tutorials and there is not description in the [javadoc](https://gephi.org/gephi-toolkit/0.9.2/apidocs/).

![test](https://user-images.githubusercontent.com/15278783/33791656-2001a27e-dcca-11e7-936b-78471164dc93.jpg)

since I want to do the same operations for different networks,I want to use **gephi-toolkit** to implement the same function,but I've checked the [demos](https://github.com/gephi/gephi-toolkit-demos/tree/master/src/main/java/org/gephi/toolkit/demos) and google for it but failed to get the result I want.

---

To describe my question clearer,I post my current code below, now I've tried two methods, one is using the methods of _ExporterCSV_ which only returned me with the matrix in csv file format while what I want is a node csv file and an edge csv file after computing several metrics like betweenness centrality, closeness centrality and so on for each node of each network. And the other method I've tried is using _DataTableControllerImpl_ but it seems that no files has been created, I want to know if there is something wrong with my code, any help is appreciated.

public class Transfer95 {
public void script() {
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();

//Get controllers and models
ImportController importController = Lookup.getDefault().lookup(ImportController.class);

//Get models and controllers for this new workspace - will be useful later
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel();

//Import file
Container container,container2;
try {
File file_node = new File(getClass().getResource("/resource/season2/club_1_1995.csv").toURI());
container = importController.importFile(file_node);
container.getLoader().setEdgeDefault(EdgeDirectionDefault.DIRECTED); //Force DIRECTED
container.getLoader().setAllowAutoNode(true); //create missing nodes
container.getLoader().setEdgesMergeStrategy(EdgeMergeStrategy.SUM);
container.getLoader().setAutoScale(true);

File file_edge = new File(getClass().getResource("/resource/season2/transfer_1_1995.csv").toURI());
container2 = importController.importFile(file_edge);
container2.getLoader().setEdgeDefault(EdgeDirectionDefault.DIRECTED); //Force DIRECTED
container2.getLoader().setAllowAutoNode(true); //create missing nodes
container2.getLoader().setEdgesMergeStrategy(EdgeMergeStrategy.SUM);
container2.getLoader().setAutoScale(true);

} catch (Exception ex) {
ex.printStackTrace();
return;
}

//Append imported data to GraphAPI
importController.process(container, new DefaultProcessor(), workspace);
importController.process(container2, new AppendProcessor(), workspace); //Use AppendProcessor to append to current workspace


//See if graph is well imported
DirectedGraph graph = graphModel.getDirectedGraph();
System.out.println("Nodes: " + graph.getNodeCount());
System.out.println("Edges: " + graph.getEdgeCount());

//count several metrics
Degree degree=new Degree();
degree.execute(graph.getModel());
System.out.println("Average Degree: "+degree.getAverageDegree());

WeightedDegree weightedDegree=new WeightedDegree();
weightedDegree.execute(graph.getModel());
System.out.println("Average Weighted Degree: "+weightedDegree.getAverageDegree());

ClusteringCoefficient clusteringcoefficient=new ClusteringCoefficient();
clusteringcoefficient.execute(graph.getModel());
System.out.println("Average Clustering Coefficient: "+clusteringcoefficient.getAverageClusteringCoefficient());

GraphDistance graphDistance=new GraphDistance();
graphDistance.execute(graph.getModel());
System.out.println("Average Path Length: "+graphDistance.getPathLength());
System.out.println("Network Diameter: "+graphDistance.getDiameter());

Modularity modularity=new Modularity();
modularity.execute(graph.getModel());
System.out.println("Modularity: "+modularity.getModularity());

GraphDensity graphDensity=new GraphDensity();
graphDensity.execute(graph.getModel());
System.out.println("Graph Density: "+graphDensity.getDensity());


//Export method 1
// ExportController ec = Lookup.getDefault().lookup(ExportController.class);
// ExporterCSV exporterCSV=(ExporterCSV)ec.getExporter("csv");
// try {
//// ec.exportFile(new File("src/resource/output/test_95.csv"));
// ec.exportFile(new File("src/resource/output/test_95.csv"), exporterCSV);
// } catch (IOException ex) {
// ex.printStackTrace();
// return;
// }

//Export method 2
// Lookup.getDefault().lookup(DataTablesController.class).setDataTablesEventListener(DataTableTopComponent.this);
DataTablesControllerImpl csvExp=new DataTablesControllerImpl();
// Lookup.getDefault().lookup(DataTablesControllerImpl.class).setDataTablesEventListener(csvExp.getDataTablesEventListener());
// DataTablesControllerImpl dataTablesController = Lookup.getDefault().lookup(DataTablesController.class);
csvExp.exportCurrentTable();

}

public static void main(String[] args){
Transfer95 test=new Transfer95();
test.script();
}
}

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the gephi-toolkit-demos examples under src/main/java/org/gephi/toolkit/demos, the linked 0.9.2 Javadoc, and the ExporterCSV and DataTablesControllerImpl entry points shown in the issue. Clarify the supported toolkit workflow and document how completion is verified by producing node and edge CSV files after metrics are computed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.