Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to create graphs with duplicate nodes #53

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ccossou
Copy link

@ccossou ccossou commented Feb 17, 2023

For some graphs, nodes can be duplicated because those nodes can represent the same entity in different namespace without it being an issue.

For now, Pyyed doesn't allow such a feature. With in mind the fact that the default behavior of Pyyed must remain the same, I made some changes to the code to allow duplicates given specific options. Of course, a better design is possible if by default duplicates are allowed, but this is not my choice to make as I'm not the main developer of this package.

To allow this, one has to define the graph with the allow_duplicates keyword. Then to add edges between those nodes, you need to use the add_edges_by_obj instead of the add_edges for the nodes that have duplicates because you don't have the node_id even if it's see, as it's automatic.

Here is an example to showcase how to do a graph with duplicate with the new code this branch proposes:

import pyyed
g = pyyed.Graph(allow_duplicates=True)

pnode = g.add_node("parent")

n1 = g.add_node("child")
n2 = g.add_node("child")

g.add_edge_by_obj(pnode, n1)
g.add_edge_by_obj(pnode, n2)

g.write_graph("test.graphml", pretty_print=True)

…nodes that have the same name).

To allow this, one has to define the graph with the allow_duplicates keyword. Then to add edges between those nodes, you need to use the add_edges_by_obj instead of the add_edges for the nodes that have duplicates because you don't have the node_id even if it's see, as it's automatic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant