gephi / gephi-plugins

Repository for Gephi Plugins maintained by the team. Each plugin has it's branch.
268 stars 620 forks source link

Delete node does not work if used from a method #278

Open arpicheck opened 1 year ago

arpicheck commented 1 year ago

Which Plugin?

python-scripting-plugin

Expected Behavior

del statement work from methods as well

Current Behavior

Using del statement works well when issued from the console, but does not have any effect, when used inside of a method.

Possible Solution

Steps to Reproduce

def removeNodes() for node in g.nodes: del node

removeNodes()

The above statement should result in all nodes removed from the graph. Instead, it has no effect. As far as I know, the plugin does not give any other solution for removing nodes.

I tried g.nodes.remove(...)

but couldn't figure out if this would work with any key.

Context

I can't use python scripts solving complex solutions. One has to always copy/paste scripts into console.

Your Environment

ypanagis commented 1 year ago

You can actually both delete noes and run a Python script from the python script plugin. I have created a gist that should work for you.

The gist filters nodes that have a specific modularity class, adds them to a subgraph and deletes them. You can run it from the scripting plugin by giving >>> execfile("/path_to_script/script.py") .

See some more functionality of the scripting pluging at the official plugin documentation.

ypanagis commented 1 year ago

The above does not actually work if the del v part, for node v, is inside a function. Perhaps delete inside a function, operates on node copies, but this is just a speculation so far

arpicheck commented 1 year ago

Other reasoning could be that 'del' is overridden somehow and has no effect at al, or does something else we don't recognize.