Last active
December 28, 2015 23:09
-
-
Save dustalov/7577229 to your computer and use it in GitHub Desktop.
Using Gephi Toolkit to compute the average degree of the given graph in the GraphML format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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()) |
Nice! A slightly more idiomatic Groovy version:
#!/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.default.lookup(ProjectController)
pc.newProject()
workspace = pc.currentWorkspace
importController = Lookup.default.lookup(ImportController)
graphModel = Lookup.default.lookup(GraphController).model
attributeModel = Lookup.default.lookup(AttributeController).model
container = importController.importFile(args[0] as File)
container.loader.edgeDefault = EdgeDefault.UNDIRECTED
importController.process(container, new DefaultProcessor(), workspace)
graph = graphModel.undirectedGraph
degree = new Degree()
degree.execute(graph.graphModel, attributeModel)
println(degree.averageDegree)
@melix, thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget to place the
gephi-toolkit.jar
into the Groovy's lib/ folder.