I've imported a graphml from Gephi to NetworkX.
G = nx.read_graphml(r"pah\\EXPORTCM0606.graphml")
In Gephi I had calculated modularity class obtaining 6 main communities and I would like to get these communities now in NetworkX in order to obtain the most frequent words in their tweets. So my question is double: How can I get these modularity class communities already calculated in Gephi from G using NetworkX?
How can I then match the graph I generate, from MongoDB with the tweets and the imported graph from Gephi? Code to generate the graph from MongoDB with the tweets:
from pymongo import MongoClient
client = MongoClient()
db = client.CuartoMilenio06062021
import networkx as nx
G = nx.DiGraph()
for result in db.tweets.find():
uid = result['user']['screen_name']
G.add_node(uid)
#Attributes
if 'quoted_status' in result and 'text' in result:
node_attrs = {uid: {"text": result['quoted_status']['text']}}
nx.set_node_attributes(G, node_attrs)
Thanks.
I will show you a very simple example that I hope it will work. Having used used the network Power Grid.gml
, included with Gephi, I calculated the modularity inside Gephi, exported the graph as graphml
and read with networkx
.
# read the network
import networkx as nx
G = nx.read_graphml('Power Grid.graphml')
Then giving something like G.nodes[<id>]
, will list all node attributes. Below an example for the node with id 0
. When accessing the node with:
G.nodes['0']
it gives us the following:
{'label': '0',
'Modularity Class': 3,
'size': 10.0,
'r': 0,
'g': 0,
'b': 0,
'x': -445.68524,
'y': 141.22151}
Please note that the node has an attribute named 'Modularity Class'
, that is the _modularity class computed by Gephi?. One can then eg. iterate the nodes and access Modularity class like in the following:
# Print the modularity class for each node
for u in G.nodes():
print(G.nodes[u]['Modularity Class'])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.