I have a word and its dependent words:
modifiers = counter ()
For Tree In B:
D = DependencyGraph (Tree)
d.root = d.Nodes [0]
Triples = List (d.triples ())
For E1, REL, E2 in Triples:
IF E1 [0] == 'Watch' and REL == 'OBJ':
Modifiers [E2 [0]] + = 1
AV = DICT (modifiers)
{'pity': 1, 'for a long time': 1, 'children': 1, 'tragic': 2, 'face': 1, 'pleasure': 1, 'Opportunity': 1, 'His': 1,' Action ': 1,' Gadko ': 1}
I also have dependent dependent words.
For example, for the word “nothing”:
modifiers2 = counter ()
For Tree In B:
D = DependencyGraph (Tree)
d.root = d.Nodes [0]
Triples = List (d.triples ())
For E1, REL, E2 in Triples:
IF E1 [0] == 'Nothing' and Rel == 'Amod':
Modifiers2 [E2 [0]] + = 1
Now I need to draw a graph, but I do not know how. Can you please help.
Answer 1, Authority 100%
In order to draw a graph using the NETWORKX
module, you must first create a graph. This can be done in different ways, for example, by setting a list of edges or an adjacent matrix.
Example with a list of edges and a dictionary with vertex weights:
import networkx as nx
Import Matplotlib.pyPlot AS PLT
Data = [
["Watch", "Runway"], ["Watch", "children"],
["For a long time", "sleep"], ["for a long time", "sit"],
["Sleep", "Sweet"], ["sleep", "firmly"],
["Children", "educate"], ["children", "care"]
]
Weights = {
'Watch': 2, 'For a long time': 1.5, 'children': 1.5, 'sleep': 1, 'Sit': 1, 'Sweet': 1,
'Hard': 1, 'bring up': 1, 'Careful': 1
}
attrs = {Key: {"Weight": Val} for key, val in weights.items ()}
G = NX.Graph ()
G.add_edges_from (DATA)
nx.set_node_attributes (G, ATTRS)
node_size = [a ["Weight"] * 600 for n, a in g.nodes (Data = True)]
Fig, AX = PLT.SUBPLOTS (FIGSIZE = (10.10))
NX.DRAW (G, WITH_LABELS = TRUE, NODE_SIZE = NODE_SIZE, AX = AX)
Plt.Show ()