I have a path graph
, which is basically a single long path. To give a better Idea, consider the case that I need to represent 4 stanzas of a poem as a path.
Two roads diverged in a wood, and I
I took the one less traveled by,
And that has made all the difference
Now my path looks like
Two -> roads -> diverged -> ....... -> all -> the -> difference
Now, I need to add the information of the line (stanza) number in which the word is appearing in, along with the word number order in the line, i.e.
i.e. the word Two
is stanza 1, word 1. roads
is stanza 1, word 2. simialrly word difference
is stanza 3 word 7. I need to add this information. I was wondering, if I can set a path attribute, such that I can define a path (or a sub-path/sub-graph), whihc I can label as stanza 1 and so on.
But I am not able to dind any such functionality in networks.
All I can find are two alternate ways:
1) Store the stanzaa and word number as two node attributes. 2) Ad hyperedge, such that I can label the hyperedge.
But these does not give any additioanl advantage over the overhead that I have to take. Is there a more elegant solution.
I am looking for having a set of labeled paths (or sub-paths). If not in networkx, I am open to try any python graph libraries like snap
or igraph
etc.
Current implementation
Currently, I am giving the stanza umber to each of the edge using the methods
G.add_path([7,8,9,11],stanza=5)
.
Now I can access the same using nx.get_edge_attributes(G,'stanza')
. Please let me know if anything more elegant is vailable