1515from mathics .core .convert .expression import ListExpression , from_python , to_mathics_list
1616from mathics .core .element import BaseElement
1717from mathics .core .expression import Expression
18+ from mathics .core .pattern import pattern_objects
1819from mathics .core .symbols import Symbol , SymbolList , SymbolTrue
1920from mathics .core .systemsymbols import (
2021 SymbolBlank ,
@@ -81,7 +82,7 @@ def graph_helper(
8182 graph_generator_func : Callable ,
8283 options : dict ,
8384 can_digraph : bool ,
84- graph_layout : str ,
85+ graph_layout : Optional [ str ] ,
8586 evaluation ,
8687 root : Optional [int ] = None ,
8788 * args ,
@@ -124,7 +125,7 @@ def graph_helper(
124125
125126
126127def has_directed_option (options : dict ) -> bool :
127- return options .get ("System`DirectedEdges" , False ). to_python ()
128+ return options .get ("System`DirectedEdges" , False )
128129
129130
130131def _process_graph_options (g , options : dict ) -> None :
@@ -173,15 +174,15 @@ def _process_graph_options(g, options: dict) -> None:
173174
174175
175176def _circular_layout (G ):
176- return nx .drawing .circular_layout (G , scale = 1.5 )
177+ return nx .drawing .circular_layout (G , scale = 1 )
177178
178179
179180def _spectral_layout (G ):
180- return nx .drawing .spectral_layout (G , scale = 2.0 )
181+ return nx .drawing .spectral_layout (G , scale = 2 )
181182
182183
183184def _shell_layout (G ):
184- return nx .drawing .shell_layout (G , scale = 2.0 )
185+ return nx .drawing .shell_layout (G , scale = 2 )
185186
186187
187188def _generic_layout (G , warn ):
@@ -840,7 +841,6 @@ class AdjacencyList(_NetworkXBuiltin):
840841 matching $pattern$.
841842 </dl>
842843
843- >> LoadModule["pymathics.graph"];
844844 >> AdjacencyList[{1 -> 2, 2 -> 3}, 3]
845845 = {2}
846846
@@ -854,8 +854,6 @@ class AdjacencyList(_NetworkXBuiltin):
854854 summary_text = "list the adjacent vertices"
855855
856856 def _retrieve (self , graph , what , neighbors , expression , evaluation ):
857- from mathics .core .pattern import pattern_objects
858-
859857 if what .get_head_name () in pattern_objects :
860858 collected = set ()
861859 match = Matcher (what ).match
@@ -897,12 +895,11 @@ def neighbors(v):
897895
898896class DirectedEdge (Builtin ):
899897 """
900- <url>
901- :Directed edge :
898+ Edge of a <url>
899+ :Directed graph :
902900 https://en.wikipedia.org/wiki/Directed_graph</url> (<url>
903901 :NetworkX:
904- https://networkx.org/documentation/networkx-2.8.8/reference/classes/digraph.html</url>,
905- <url>
902+ https://networkx.org/documentation/networkx-2.8.8/reference/classes/digraph.html</url>, <url>
906903 :WMA:
907904 https://reference.wolfram.com/language/ref/DirectedEdge.html</url>)
908905
@@ -920,11 +917,10 @@ class EdgeConnectivity(_NetworkXBuiltin):
920917 """
921918 <url>
922919 :Edge connectivity:
923- https://en.wikipedia.org/wiki/Directed_graph</url> (<url>
920+ https://en.wikipedia.org/wiki/Directed_graph#Directed_graph_connectivity </url> (<url>
924921 :NetworkX:
925922 https://networkx.org/documentation/networkx-2.8.8/reference/algorithms/\
926- generated/networkx.algorithms.connectivity.connectivity.edge_connectivity.html</url>,
927- <url>
923+ generated/networkx.algorithms.connectivity.connectivity.edge_connectivity.html</url>, <url>
928924 :WMA:
929925 https://reference.wolfram.com/language/ref/EdgeConnectivity.html</url>)
930926
@@ -970,7 +966,7 @@ def eval_st(self, graph, s, t, expression, evaluation, options):
970966class EdgeIndex (_NetworkXBuiltin ):
971967 """
972968 <url>
973- :WMA:
969+ :WMA link :
974970 https://reference.wolfram.com/language/ref/EdgeIndex.html</url>
975971
976972 <dl>
@@ -998,7 +994,7 @@ def eval(self, graph, v, expression, evaluation, options):
998994class EdgeList (_PatternList ):
999995 """
1000996 <url>
1001- :WMA:
997+ :WMA link :
1002998 https://reference.wolfram.com/language/ref/EdgeList.html</url>
1003999
10041000 <dl>
@@ -1016,7 +1012,7 @@ def _items(self, graph):
10161012class EdgeRules (_NetworkXBuiltin ):
10171013 """
10181014 <url>
1019- :WMA:
1015+ :WMA link :
10201016 https://reference.wolfram.com/language/ref/EdgeRules.html</url>
10211017
10221018 <dl>
@@ -1048,8 +1044,7 @@ class FindShortestPath(_NetworkXBuiltin):
10481044 https://en.wikipedia.org/wiki/Shortest_path_problem</url> (<url>
10491045 :NetworkX:
10501046 https://networkx.org/documentation/networkx-2.8.8/reference/algorithms\
1051- /generated/networkx.algorithms.shortest_paths.generic.shortest_path.html</url>,
1052- <url>
1047+ /generated/networkx.algorithms.shortest_paths.generic.shortest_path.html</url>, <url>
10531048 :WMA:
10541049 https://reference.wolfram.com/language/ref/FindShortestPath.html</url>)
10551050
@@ -1083,7 +1078,7 @@ class FindShortestPath(_NetworkXBuiltin):
10831078 summary_text = "find the shortest path between two vertices"
10841079
10851080 def eval_s_t (self , graph , s , t , expression , evaluation , options ):
1086- "%(name)s [graph_, s_, t_, OptionsPattern[%(name)s ]]"
1081+ "FindShortestPath [graph_, s_, t_, OptionsPattern[FindShortestPath ]]"
10871082 graph = self ._build_graph (graph , evaluation , options , expression )
10881083 if not graph :
10891084 return
@@ -1169,8 +1164,7 @@ def eval_st(self, graph, s, t, expression, evaluation, options):
11691164
11701165class GraphAtom (AtomBuiltin ):
11711166 """
1172- <url>:Graph:https://en.wikipedia.org/wiki/graph</url> (
1173- <url>:WMA:
1167+ <url>:Graph:https://en.wikipedia.org/wiki/graph</url> (<url>:WMA:
11741168 https://reference.wolfram.com/language/ref/Graph.html</url>)
11751169 <dl>
11761170 <dt>'Graph[{$e1, $e2, ...}]'
@@ -1224,7 +1218,7 @@ def eval_1(self, vertices, edges, evaluation, options):
12241218class HighlightGraph (_NetworkXBuiltin ):
12251219 """
12261220 <url>
1227- :WMA:
1221+ :WMA link :
12281222 https://reference.wolfram.com/language/ref/HighlightGraph.html</url>
12291223
12301224 <dl>
@@ -1264,7 +1258,7 @@ def parse(item):
12641258class Property (Builtin ):
12651259 """
12661260 <url>
1267- :WMA:
1261+ :WMA link :
12681262 https://reference.wolfram.com/language/ref/Property.html</url>
12691263
12701264 <dl>
@@ -1280,7 +1274,7 @@ class Property(Builtin):
12801274class PropertyValue (Builtin ):
12811275 """
12821276 <url>
1283- :WMA:
1277+ :WMA link :
12841278 https://reference.wolfram.com/language/ref/PropertyValue.html</url>
12851279
12861280 <dl>
@@ -1323,7 +1317,7 @@ def eval(self, graph, item, name, evaluation):
13231317class VertexAdd (_NetworkXBuiltin ):
13241318 """
13251319 <url>
1326- :WMA:
1320+ :WMA link :
13271321 https://reference.wolfram.com/language/ref/VertexAdd.html</url>
13281322
13291323 <dl>
@@ -1343,7 +1337,7 @@ class VertexAdd(_NetworkXBuiltin):
13431337 summary_text = "add a vertex"
13441338
13451339 def eval (self , graph : Expression , what , expression , evaluation , options ):
1346- "%(name)s [graph_, what_, OptionsPattern[%(name)s ]]"
1340+ "VertexAdd [graph_, what_, OptionsPattern[VertexAdd ]]"
13471341 mathics_graph = self ._build_graph (graph , evaluation , options , expression )
13481342 if mathics_graph :
13491343 if what .get_head_name () == "System`List" :
@@ -1357,7 +1351,7 @@ def eval(self, graph: Expression, what, expression, evaluation, options):
13571351class VertexConnectivity (_NetworkXBuiltin ):
13581352 """
13591353 <url>
1360- :WMA:
1354+ :WMA link :
13611355 https://reference.wolfram.com/language/ref/VertexConnectivity.html</url>
13621356
13631357 <dl>
@@ -1408,7 +1402,7 @@ def eval_st(self, graph, s, t, expression, evaluation, options):
14081402class VertexDelete (_NetworkXBuiltin ):
14091403 """
14101404 <url>
1411- :WMA:
1405+ :WMA link :
14121406 https://reference.wolfram.com/language/ref/VertexDelete.html</url>
14131407
14141408 <dl>
@@ -1431,8 +1425,6 @@ def eval(self, graph, what, expression, evaluation, options) -> Optional[Graph]:
14311425 "VertexDelete[graph_, what_, OptionsPattern[VertexDelete]]"
14321426 graph = self ._build_graph (graph , evaluation , options , expression )
14331427 if graph :
1434- from mathics .core .pattern import pattern_objects
1435-
14361428 head_name = what .get_head_name ()
14371429 if head_name in pattern_objects :
14381430 cases = Expression (
@@ -1449,7 +1441,7 @@ def eval(self, graph, what, expression, evaluation, options) -> Optional[Graph]:
14491441class VertexIndex (_NetworkXBuiltin ):
14501442 """
14511443 <url>
1452- :WMA:
1444+ :WMA link :
14531445 https://reference.wolfram.com/language/ref/VertexIndex.html</url>
14541446 <dl>
14551447 <dt>'VertexIndex'['g', 'v']
@@ -1477,7 +1469,7 @@ def eval(self, graph, v, expression, evaluation, options):
14771469class VertexList (_PatternList ):
14781470 """
14791471 <url>
1480- :WMA:
1472+ :WMA link :
14811473 https://reference.wolfram.com/language/ref/VertexList.html</url>
14821474 <dl>
14831475 <dt>'VertexList[$edgelist$]'
@@ -1495,7 +1487,7 @@ class VertexList(_PatternList):
14951487 = {10}
14961488 """
14971489
1498- summary_text = "list the vertex "
1490+ summary_text = "list the vertices of a graph "
14991491
15001492 def _items (self , graph ):
15011493 return graph .vertices
@@ -1504,7 +1496,7 @@ def _items(self, graph):
15041496class UndirectedEdge (Builtin ):
15051497 """
15061498 <url>
1507- :WMA:
1499+ :WMA link :
15081500 https://reference.wolfram.com/language/ref/UndirectedEdge.html</url>
15091501
15101502 <dl>
@@ -1544,9 +1536,9 @@ class UndirectedEdge(Builtin):
15441536
15451537class EdgeDelete (_NetworkXBuiltin ):
15461538 """
1547- <url>
1539+ Delete an Edge ( <url>
15481540 :WMA:
1549- https://reference.wolfram.com/language/ref/EdgeDelete.html</url>
1541+ https://reference.wolfram.com/language/ref/EdgeDelete.html</url>)
15501542
15511543 <dl>
15521544 <dt>'EdgeDelete'[$g$, $edge$]
@@ -1572,8 +1564,6 @@ def eval(self, graph, what, expression, evaluation, options) -> Optional[Graph]:
15721564 "EdgeDelete[graph_, what_, OptionsPattern[EdgeDelete]]"
15731565 graph = self ._build_graph (graph , evaluation , options , expression )
15741566 if graph :
1575- from mathics .core .pattern import pattern_objects
1576-
15771567 head_name = what .get_head_name ()
15781568 if head_name in pattern_objects :
15791569 cases = Expression (
0 commit comments