-
Notifications
You must be signed in to change notification settings - Fork 2
/
Access_the_toolkit.py
211 lines (179 loc) · 7.46 KB
/
Access_the_toolkit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#-----IMPORT A DAMN CLASS FROM THE TOOLKIT
# the first step can be done in 2 ways:
# the long way is to follow these instructions and get lost(<-- https://wiki.gephi.org/index.php/How_to_build_the_Gephi_Toolkit )
# the short way is to exploit milombo's work and download the libs from the dropbox invitation
# So...
# YOU SHOULD HAVE DOWNLOADED THE FILE FROM MY DROPBOX INVITATION IN YOUR MAIL>>> DO IT NOW!
# DO THAT
# NOW
#
# DONE?
# OK, NOW ADJUST THE PATH TO ACCESS THE SUBFOLDER gephi-toolkit
toolspath="C:\\Users\MangustaMegaMastar\\Downloads\\4gephi\\gephi-0.8.1-beta.sources\\gephi-0.8.1-beta.sources\\toolkit\\gephi-toolkit\\"
algopath= toolspath+"org-gephi-algorithms.jar"
graphpath= toolspath + "org-gephi-graph-api.jar"
attr_path= toolspath + "org-gephi-data-attributes-api.jar"
#attrtype_path=toolspath + " .jar"
viz_path=toolspath + "org-gephi-visualization-api.jar"
project_path=toolspath + "org-gephi-project-api.jar"
ioimporter_path=toolspath + "org-gephi-io-importer-api.jar"
import java.io
import sys
sys.path.append(algopath)
sys.path.append(graphpath)
sys.path.append(algopath)
sys.path.append(attr_path)
sys.path.append(viz_path)
sys.path.append(project_path)
# Import single methods/interfaces as this:
from org.gephi.graph.api import GraphView
from org.gephi.algorithms.shortestpath import AbstractShortestPathAlgorithm
from org.gephi.algorithms.shortestpath import BellmanFordShortestPathAlgorithm
#------------------------------------
# this allowed to import methods/interfaces that were PREVIOUSLY UNACCESSIBLE.
# WE NEED TO LEARN HOW TO USE THEM.
# PROBABLY MORE OBJECTS ARE NEEDED.
# IT IS NOW POSSIBLE TO DO THE SAME THAT THESE GUYS DO: http://wiki.gephi.org/index.php/Script_plugin
# BELOW AN EXAMPLE FROM GEPHI SCRIPT-PLUGIN DEVELOPERS: NOT YET WORKING
# GET INSPIRED BY IT AND MAKE IT WORKING (changing the import way as the 3 lines above)
#-----------------------------------
from org.gephi import graph.api
import org.gephi.graph.api as graph_api
import org.gephi.data.attributes.api as attributes_api
import org.gephi.data.attributes.api.AttributeType as AttributeType
import org.gephi.visualization.VizController as viz
import org.gephi.project.api as project_api
import org.gephi.io.importer.api as importer_api
import java.io
#----------- THIS IS THE BEST INITIALIZATION, combining demo http://wiki.gephi.org/index.php/Toolkit_-_Manipulate_attributes
#------------ with code of the API http://wiki.gephi.org/index.php/Script_plugin
#----------- HOW DO WE INITIALIZE AND GET A MODEL?? it always wants an input, even when making a new model
# our interfaces http://gephi.org/docs/api/org/gephi/graph/api/package-summary.html
from org.gephi.project.api import ProjectController
ProjectController.closeCurrentProject()
ProjectController.newProject();
ProjectController.getCurrentWorkspace()
ProjectController.getCurrentProject()
#
gu =g.getUnderlyingGraph()
ga = gu.getAttributes()
#
from org.gephi.graph.api import GraphController
from org.gephi.graph.api import GraphModel
from org.gephi.graph.api import Graph
from org.gephi.data.attributes.api import AttributeController
from org.gephi.data.attributes.api import AttributeModel
GraphController.getModel() #getGraphModel()
AttributeController.getModel() #getAttributeModel()
AttributeController.getModel().getDirectedGraph()
AttributeController.getModel().getDirectedGraph().getGraph()
Graph.getGraphModel() #Graph.graphModel() #not working
GraphModel.getGraph()
GraphModel
ungra =g.getUnderlyingGraph()
from org.gephi.statistics.plugin import GraphDistance
GraphDistance.execute(ungra, )
#----- we need org.gephi.data.attributes.api.AttributeModel
org.gephi.graph.api.GraphModel
#------ perhaps even this is usefule g.getUnderlyingGraph().getGraphModel()
#------- perhaps we need this Lookup
import org.openide.awt.ActionRegistration;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionID;
import org.openide.util.Lookup;
import org.openide.util.NbBundle.Messages;
:In order to compile this Action, you have to add the following module dependencies to your plugin module:
Graph API
Lookup API
Project API
#----- STACKOVERFLOW gives 3 advices
#If you have the source for the .jar, open up the .java file containing the code you wish to utilise, and look for a line near the top that specifies the package. If you find a line that says something like package foo.bar.myJavaPackage;, then you must do one of
#import it like
import foo.bar.myJavaPackage #, and use the contents like
obj = foo.bar.myJavaPackage.someClass #, or
#import it like
from foo.bar import myJavaPackage #, and use the contents like
obj = myJavaPackage.someClass #, or
#import it like
from foo.bar.myJavaPackage import someClass #, and use it like
obj = myClass #, but careful of name collisions using this method.
#--- OF WHICH< ONLY THE LAST WORKS FOR US:
>>> import sys
>>> sys.path.append("/var/javalib/some-thobe-package.jar") # add the jar to your path
>>> from org.thobe.somepackage import SomeClass # it's now possible to import the package
>>> some_object = SomeClass() # You can now use your java class
import os
os.chdir(toolspath)
os.curdir
"""
This file is loaded when the gephi script engine is used first (before the first user script execution)
It contains the specific gephi python api accessible from script
"""
def help(obj = None) :
"""
See help
"""
if obj == None :
print "Python console"
print "Available functions : "
print dir(sys.modules[__name__])
else :
try :
print obj.__doc__
except :
print "Object has no documentation"
def getGraphModel() :
"""
getGraphModel() :
Return the graph model of the currently displayed graph.
"""
return gephi.getLookup().lookup(graph_api.GraphController).getModel()
def getAttributeModel() :
"""
getAttributeModel() :
Return the attribute model of the currently displayed graph
"""
return gephi.getLookup().lookup(attributes_api.AttributeController).getModel()
#graph management
def getDirectedGraph() :
"""
getDirectedGraph() :
Get the currently displayed graph as a directed graph
Example :
dg = getDirectedGraph()
#values :
print "Nodes:", dg.getNodeCount(),"Edges: ", dg.getEdgeCount()
#iterating :
for e in dg.edges :
print "source : ", e.getSource(), "dest:", e.getTarget()
node2 = dg.getNode("n2") #using its id, see find_node to search with label.
print "Degree:", dg.getDegree(node2)
"""
return getGraphModel().getDirectedGraph()
def getGraph() :
"""
getGraph() :
Get the currently displayed graph as a non directed graph
Example :
dg = getDirectedGraph()
#values :
print "Nodes:", dg.getNodeCount(),"Edges: ", dg.getEdgeCount()
#iterating :
for e in dg.edges :
print "source : ", e.getSource(), "dest:", e.getTarget()
node2 = dg.getNode("n2") #using its id, see find_node to search with label.
print "Degree:", dg.getDegree(node2)
"""
return getGraphModel().getGraph()
#----alternative untested method
#In your case you probably want to use the path of your package to find the jar:
# yourpackage/__init__.py
import sys, os
if 'java' in sys.platform.lower():
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"your-lib.jar"))
from jython_implementation import library
else:
from cpython_implementation import library
#Hope that helps!