Skip to content

Commit

Permalink
add GraphType.of() class method
Browse files Browse the repository at this point in the history
  • Loading branch information
erivlis committed Dec 1, 2024
1 parent 464bc37 commit e46888f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/graphinate/builders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Build classes that can generate graph data structures from a GraphModel
Builder classes that generate graph data structures from a GraphModel
"""
import base64
import functools
Expand Down Expand Up @@ -102,6 +102,18 @@ class GraphType(Enum):
MultiDiGraph = nx.MultiDiGraph
MultiGraph = nx.MultiGraph

@classmethod
def of(cls, graph: nx.Graph):
if graph.is_directed() and graph.is_multigraph():
return cls.MultiDiGraph
elif graph.is_directed():
return cls.MultiGraph
elif graph.is_multigraph():
return cls.MultiDiGraph.MultiGraph
else:
return cls.Graph



class Builder(ABC):
"""Builder abstract base class"""
Expand Down

0 comments on commit e46888f

Please sign in to comment.