Monday 15 August 2011

python - Best practices for Querying graphs by edge and node attributes in NetworkX -


Use Network X for new social network analysis queries, and new in the library. By query, I mean choose / create subclients based on the properties of the nodes of both sides, where the edges are made, the nodes have attributes, the graph is using a multidi graph of the form

  G2 = nx.multiDiGraph () G2.add_node ("UserA", {"type": "Cat"}) G2.add_node ("UserB G2.add_node (" UserC ", {" type ":" mouse G2.add_node ("Like", {"type": "feeling"}) G2.G2.add_edge ("UserA", 'Hates', statementit = "1") G2.add_edge ("Hates" , 'UserB', Statement = "1" ("Hate", {"Type": "Experience"}) G2.add_edge G2.add_edge ("UserC", 'Hates', statementit = "2") G2.add_edge ("Hate", 'UserA', Statement = "2") G2.add_edge ("UserB", 'hate' G2.add_edge G2.add_edge ("Hate", "User", Statement = "3 G2.add_edge ("User C", 'Like', Statement = "3") G2.add_edge ("Like", "User B", Statement = "3")   

Inquiries with nodes for

 , data in G2.nodes_iter (data = true): if (data ['type'] == "cat"): # All edges from these nodes Removing # Then using a filter for a specific statement_id # or all with a specific statement ID Receive the edges # Find from node et "cat" reboot   

Is there a better way of query? Or is it best practice to create custom iterations to make a subfraph?

Alternatively (and a different question), the graph can be simplified, but I am not using the graph below because the object of type "Hate" will be with predecessors whether it is easy to ask ? G3 = NX G3.add_node ("UserA", {"Type": "Cat"}) G3.add_node ("UserB", {G3.add_gege ("UserA", "UserB", "UserB", "User", "User", "UserA", "UserA", "UserB", Statement = "1", label = "Hates"}), label = "Hates")

Other notes:

No comments:

Post a Comment