Skip to content

Instantly share code, notes, and snippets.

@sheymann
Forked from dustalov/avgdegree.groovy
Created November 21, 2013 16:49
Show Gist options
  • Save sheymann/7585322 to your computer and use it in GitHub Desktop.
Save sheymann/7585322 to your computer and use it in GitHub Desktop.
#!/usr/bin/env groovy
import org.gephi.data.attributes.api.AttributeController
import org.gephi.graph.api.GraphController
import org.gephi.io.importer.api.EdgeDefault
import org.gephi.io.importer.api.ImportController
import org.gephi.io.processor.plugin.DefaultProcessor
import org.gephi.project.api.ProjectController
import org.gephi.statistics.plugin.Degree
import org.openide.util.Lookup
pc = Lookup.getDefault().lookup(ProjectController.class)
pc.newProject()
workspace = pc.getCurrentWorkspace()
importController = Lookup.getDefault().lookup(ImportController.class)
graphModel = Lookup.getDefault().lookup(GraphController.class).getModel()
attributeModel = Lookup.getDefault().lookup(AttributeController.class).getModel()
container = importController.importFile(new File(args[0]))
container.getLoader().setEdgeDefault(EdgeDefault.UNDIRECTED)
importController.process(container, new DefaultProcessor(), workspace)
graph = graphModel.getUndirectedGraph()
degree = new Degree()
degree.execute(graph.getGraphModel(), attributeModel)
println(degree.getAverageDegree())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment