Skip to content

Commit 023cc82

Browse files
authored
Merge pull request #39 from Mathics3/expression_argument
Adjust the use of `expression` parameter in eval_ methods
2 parents 93df099 + 89ad93f commit 023cc82

File tree

9 files changed

+62
-62
lines changed

9 files changed

+62
-62
lines changed

pymathics/graph/base.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -817,13 +817,13 @@ class _PatternList(_NetworkXBuiltin):
817817
def eval(
818818
self, graph, expression: Expression, evaluation: Evaluation, options: dict
819819
):
820-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
820+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
821821
graph = self._build_graph(graph, evaluation, options, expression)
822822
if graph:
823823
return ListExpression(*(from_python(q) for q in self._items(graph)))
824824

825825
def eval_patt(self, graph, patt, expression, evaluation, options):
826-
"%(name)s[graph_, patt_, OptionsPattern[%(name)s]]"
826+
"expression: %(name)s[graph_, patt_, OptionsPattern[%(name)s]]"
827827
graph = self._build_graph(graph, evaluation, options, expression)
828828
if graph:
829829
return Expression(SymbolCases, ListExpression(*self._items(graph)), patt)
@@ -875,7 +875,7 @@ def _retrieve(self, graph, what, neighbors, expression, evaluation):
875875
self._not_a_vertex(expression, 2, evaluation)
876876

877877
def eval(self, graph, what, expression, evaluation, options):
878-
"%(name)s[graph_, what_, OptionsPattern[%(name)s]]"
878+
"expression: %(name)s[graph_, what_, OptionsPattern[%(name)s]]"
879879
graph = self._build_graph(graph, evaluation, options, expression)
880880
if graph:
881881
G = graph.G.to_undirected() # FIXME inefficient
@@ -884,7 +884,7 @@ def eval(self, graph, what, expression, evaluation, options):
884884
)
885885

886886
def eval_d(self, graph, what, d, expression, evaluation, options):
887-
"%(name)s[graph_, what_, d_, OptionsPattern[%(name)s]]"
887+
"expression: %(name)s[graph_, what_, d_, OptionsPattern[%(name)s]]"
888888
py_d = d.to_mpmath()
889889
if py_d is None:
890890
return
@@ -967,13 +967,13 @@ class EdgeConnectivity(_NetworkXBuiltin):
967967
summary_text = "edge connectivity of a graph"
968968

969969
def eval(self, graph, expression, evaluation, options):
970-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
970+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
971971
graph = self._build_graph(graph, evaluation, options, expression)
972972
if graph and not graph.empty():
973973
return Integer(nx.edge_connectivity(graph.G))
974974

975975
def eval_st(self, graph, s, t, expression, evaluation, options):
976-
"%(name)s[graph_, s_, t_, OptionsPattern[%(name)s]]"
976+
"expression: %(name)s[graph_, s_, t_, OptionsPattern[%(name)s]]"
977977
graph = self._build_graph(graph, evaluation, options, expression)
978978
if graph and not graph.empty():
979979
return Integer(nx.edge_connectivity(graph.G, s, t))
@@ -995,7 +995,7 @@ class EdgeIndex(_NetworkXBuiltin):
995995
summary_text = "find the position of an edge"
996996

997997
def eval(self, graph, v, expression, evaluation, options):
998-
"%(name)s[graph_, v_, OptionsPattern[%(name)s]]"
998+
"expression: %(name)s[graph_, v_, OptionsPattern[%(name)s]]"
999999
graph = self._build_graph(graph, evaluation, options, expression)
10001000
if graph:
10011001
# FIXME: check if directionality must be considered or not.
@@ -1040,7 +1040,7 @@ class EdgeRules(_NetworkXBuiltin):
10401040
summary_text = "list the edge as rules"
10411041

10421042
def eval(self, graph, expression, evaluation, options):
1043-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
1043+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
10441044
graph = self._build_graph(graph, evaluation, options, expression)
10451045
if graph:
10461046

@@ -1096,7 +1096,7 @@ class FindShortestPath(_NetworkXBuiltin):
10961096
def eval_s_t(
10971097
self, graph, s, t, expression: Expression, evaluation: Evaluation, options: dict
10981098
):
1099-
"FindShortestPath[graph_, s_, t_, OptionsPattern[FindShortestPath]]"
1099+
"expression: FindShortestPath[graph_, s_, t_, OptionsPattern[FindShortestPath]]"
11001100
graph = self._build_graph(graph, evaluation, options, expression)
11011101
if not graph:
11021102
return
@@ -1153,7 +1153,7 @@ class FindVertexCut(_NetworkXBuiltin):
11531153
summary_text = "find the vertex cuts"
11541154

11551155
def eval(self, graph, expression, evaluation, options):
1156-
"FindVertexCut[graph_, OptionsPattern[%(name)s]]"
1156+
"expression: FindVertexCut[graph_, OptionsPattern[%(name)s]]"
11571157
graph = self._build_graph(graph, evaluation, options, expression)
11581158
if graph:
11591159
if graph.empty() or not is_connected(graph.G):
@@ -1164,7 +1164,7 @@ def eval(self, graph, expression, evaluation, options):
11641164
)
11651165

11661166
def eval_st(self, graph, s, t, expression, evaluation, options):
1167-
"FindVertexCut[graph_, s_, t_, OptionsPattern[%(name)s]]"
1167+
"expression: FindVertexCut[graph_, s_, t_, OptionsPattern[%(name)s]]"
11681168
graph = self._build_graph(graph, evaluation, options, expression)
11691169
if not graph:
11701170
return
@@ -1248,7 +1248,7 @@ class HighlightGraph(_NetworkXBuiltin):
12481248
summary_text = "highlight elements in a graph"
12491249

12501250
def eval(self, graph, what, expression, evaluation, options):
1251-
"HighlightGraph[graph_, what_List, OptionsPattern[%(name)s]]"
1251+
"expression: HighlightGraph[graph_, what_List, OptionsPattern[%(name)s]]"
12521252
default_highlight = [Expression(SymbolRGBColor, Integer1, Integer0, Integer0)]
12531253

12541254
def parse(item):
@@ -1355,7 +1355,7 @@ class VertexAdd(_NetworkXBuiltin):
13551355
summary_text = "add a vertex"
13561356

13571357
def eval(self, graph: Expression, what, expression, evaluation, options):
1358-
"VertexAdd[graph_, what_, OptionsPattern[VertexAdd]]"
1358+
"expression: VertexAdd[graph_, what_, OptionsPattern[VertexAdd]]"
13591359
mathics_graph = self._build_graph(graph, evaluation, options, expression)
13601360
if mathics_graph:
13611361
if what.get_head_name() == "System`List":
@@ -1399,7 +1399,7 @@ class VertexConnectivity(_NetworkXBuiltin):
13991399
summary_text = "vertex connectivity"
14001400

14011401
def eval(self, graph, expression, evaluation, options):
1402-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
1402+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
14031403
graph = self._build_graph(graph, evaluation, options, expression)
14041404
if graph and not graph.empty():
14051405
if not is_connected(graph.G):
@@ -1408,7 +1408,7 @@ def eval(self, graph, expression, evaluation, options):
14081408
return Integer(nx.node_connectivity(graph.G))
14091409

14101410
def eval_st(self, graph, s, t, expression, evaluation, options):
1411-
"%(name)s[graph_, s_, t_, OptionsPattern[%(name)s]]"
1411+
"expression: %(name)s[graph_, s_, t_, OptionsPattern[%(name)s]]"
14121412
graph = self._build_graph(graph, evaluation, options, expression)
14131413
if graph and not graph.empty():
14141414
if not is_connected(graph.G):
@@ -1440,7 +1440,7 @@ class VertexDelete(_NetworkXBuiltin):
14401440
summary_text = "remove a vertex"
14411441

14421442
def eval(self, graph, what, expression, evaluation, options) -> Optional[Graph]:
1443-
"VertexDelete[graph_, what_, OptionsPattern[VertexDelete]]"
1443+
"expression: VertexDelete[graph_, what_, OptionsPattern[VertexDelete]]"
14441444
graph = self._build_graph(graph, evaluation, options, expression)
14451445
if graph:
14461446
head_name = what.get_head_name()
@@ -1475,7 +1475,7 @@ class VertexIndex(_NetworkXBuiltin):
14751475
summary_text = "find the position of a vertex"
14761476

14771477
def eval(self, graph, v, expression, evaluation, options):
1478-
"%(name)s[graph_, v_, OptionsPattern[%(name)s]]"
1478+
"expression: %(name)s[graph_, v_, OptionsPattern[%(name)s]]"
14791479
graph = self._build_graph(graph, evaluation, options, expression)
14801480
if graph:
14811481
try:
@@ -1579,7 +1579,7 @@ class EdgeDelete(_NetworkXBuiltin):
15791579
summary_text = "remove an edge"
15801580

15811581
def eval(self, graph, what, expression, evaluation, options) -> Optional[Graph]:
1582-
"EdgeDelete[graph_, what_, OptionsPattern[EdgeDelete]]"
1582+
"expression: EdgeDelete[graph_, what_, OptionsPattern[EdgeDelete]]"
15831583
graph = self._build_graph(graph, evaluation, options, expression)
15841584
if graph:
15851585
head_name = what.get_head_name()

pymathics/graph/centralities.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class BetweennessCentrality(_Centrality):
9696
summary_text = "get Betweenness centrality"
9797

9898
def eval(self, graph, expression, evaluation, options):
99-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
99+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
100100
graph = self._build_graph(graph, evaluation, options, expression)
101101
if graph:
102102
weight = graph.update_weights(evaluation)
@@ -143,7 +143,7 @@ class ClosenessCentrality(_Centrality):
143143
summary_text = "get the closeness centrality"
144144

145145
def eval(self, graph, expression, evaluation, options):
146-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
146+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
147147
graph = self._build_graph(graph, evaluation, options, expression)
148148
if graph:
149149
weight = graph.update_weights(evaluation)
@@ -196,19 +196,19 @@ def _from_dict(self, graph, centrality):
196196
)
197197

198198
def eval(self, graph, expression, evaluation, options):
199-
"Pymathics`DegreeCentrality[graph_, OptionsPattern[]]"
199+
"expression: Pymathics`DegreeCentrality[graph_, OptionsPattern[]]"
200200
graph = self._build_graph(graph, evaluation, options, expression)
201201
if graph:
202202
return self._from_dict(graph, nx.degree_centrality(graph.G))
203203

204204
def eval_in(self, graph, expression, evaluation, options):
205-
'%(name)s[graph_, "In", OptionsPattern[]]'
205+
'expression: %(name)s[graph_, "In", OptionsPattern[]]'
206206
graph = self._build_graph(graph, evaluation, options, expression)
207207
if graph:
208208
return self._from_dict(graph, nx.in_degree_centrality(graph.G))
209209

210210
def eval_out(self, graph, expression, evaluation, options):
211-
'%(name)s[graph_, "Out", OptionsPattern[]]'
211+
'expression: %(name)s[graph_, "Out", OptionsPattern[]]'
212212
graph = self._build_graph(graph, evaluation, options, expression)
213213
if graph:
214214
return self._from_dict(graph, nx.out_degree_centrality(graph.G))
@@ -263,13 +263,13 @@ def _centrality(self, g, weight):
263263
return nx.eigenvector_centrality(g, max_iter=10000, tol=1.0e-7, weight=weight)
264264

265265
def eval(self, graph, expression, evaluation, options):
266-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
266+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
267267
graph = self._build_graph(graph, evaluation, options, expression)
268268
if graph:
269269
return self._compute(graph, evaluation)
270270

271271
def eval_in_out(self, graph, dir, expression, evaluation, options):
272-
"%(name)s[graph_, dir_String, OptionsPattern[%(name)s]]"
272+
"expression: %(name)s[graph_, dir_String, OptionsPattern[%(name)s]]"
273273
py_dir = dir.get_string_value()
274274
if py_dir not in ("In", "Out"):
275275
return
@@ -299,7 +299,7 @@ class HITSCentrality(_Centrality):
299299
summary_text = "get HITS centrality"
300300

301301
def eval(self, graph, expression, evaluation, options):
302-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
302+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
303303
graph = self._build_graph(graph, evaluation, options, expression)
304304
if graph:
305305
G, _ = graph.coalesced_graph(evaluation) # FIXME warn if weight > 1
@@ -364,7 +364,7 @@ def _centrality(self, g, weight, alpha, beta):
364364
)
365365

366366
def eval(self, graph, alpha, beta, expression, evaluation, options):
367-
"Pymathics`KatzCentrality[Pymathics`graph_, alpha_, beta_, OptionsPattern[%(name)s]]"
367+
"expression: Pymathics`KatzCentrality[Pymathics`graph_, alpha_, beta_, OptionsPattern[%(name)s]]"
368368
graph = self._build_graph(graph, evaluation, options, expression)
369369
if graph:
370370
try:
@@ -407,7 +407,7 @@ class PageRankCentrality(_Centrality):
407407
summary_text = "get the page rank centralities"
408408

409409
def eval_alpha_beta(self, graph, alpha, expression, evaluation, options):
410-
"%(name)s[graph_, alpha_, OptionsPattern[%(name)s]]"
410+
"expression: %(name)s[graph_, alpha_, OptionsPattern[%(name)s]]"
411411
graph = self._build_graph(graph, evaluation, options, expression)
412412
if graph:
413413
py_alpha = float(alpha.to_mpmath())

pymathics/graph/components.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ConnectedComponents(_NetworkXBuiltin):
5252
def eval(
5353
self, graph, expression, evaluation: Evaluation, options: dict
5454
) -> Optional[ListExpression]:
55-
"ConnectedComponents[graph_, OptionsPattern[%(name)s]]"
55+
"expression: ConnectedComponents[graph_, OptionsPattern[%(name)s]]"
5656
graph = self._build_graph(graph, evaluation, options, expression)
5757
if graph:
5858
connect_fn = (
@@ -123,7 +123,7 @@ class WeaklyConnectedComponents(_NetworkXBuiltin):
123123
summary_text = "list the weakly connected components"
124124

125125
def eval(self, graph, expression, evaluation: Evaluation, options):
126-
"WeaklyConnectedComponents[graph_, OptionsPattern[WeaklyConnectedComponents]]"
126+
"expression: WeaklyConnectedComponents[graph_, OptionsPattern[WeaklyConnectedComponents]]"
127127
graph = self._build_graph(graph, evaluation, options, expression)
128128
if graph:
129129
components = nx.connected_components(graph.G.to_undirected())

pymathics/graph/curated.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class GraphData(_NetworkXBuiltin):
2828
def eval(
2929
self, name, expression, evaluation: Evaluation, options: dict
3030
) -> Optional[Graph]:
31-
"GraphData[name_String, OptionsPattern[GraphData]]"
31+
"expression: GraphData[name_String, OptionsPattern[GraphData]]"
3232
py_name = name.get_string_value()
3333
fn, layout = WL_TO_NETWORKX_FN.get(py_name, (None, None))
3434
if not fn:

pymathics/graph/measures_and_metrics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ class _PatternCount(_NetworkXBuiltin):
3131
no_doc = True
3232

3333
def eval(self, graph, expression, evaluation, options) -> Optional[Integer]:
34-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
34+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
3535
graph = self._build_graph(graph, evaluation, options, expression)
3636
if graph:
3737
return Integer(len(self._items(graph)))
3838

3939
def eval_patt(
4040
self, graph, patt, expression, evaluation, options
4141
) -> Optional[Expression]:
42-
"%(name)s[graph_, patt_, OptionsPattern[%(name)s]]"
42+
"expression: %(name)s[graph_, patt_, OptionsPattern[%(name)s]]"
4343
graph = self._build_graph(graph, evaluation, options, expression)
4444
if graph:
4545
return Expression(
@@ -132,7 +132,7 @@ class GraphDistance(_NetworkXBuiltin):
132132
def eval_s(
133133
self, graph, s, expression, evaluation: Evaluation, options: dict
134134
) -> Optional[ListExpression]:
135-
"GraphDistance[graph_, s_, OptionsPattern[GraphDistance]]"
135+
"expression: GraphDistance[graph_, s_, OptionsPattern[GraphDistance]]"
136136
graph = self._build_graph(graph, evaluation, options, expression)
137137
if graph:
138138
weight = graph.update_weights(evaluation)
@@ -141,7 +141,7 @@ def eval_s(
141141
return to_mathics_list(*[d.get(v, inf) for v in graph.vertices])
142142

143143
def eval_s_t(self, graph, s, t, expression, evaluation: Evaluation, options: dict):
144-
"GraphDistance[graph_, s_, t_, OptionsPattern[GraphDistance]]"
144+
"expression: GraphDistance[graph_, s_, t_, OptionsPattern[GraphDistance]]"
145145
graph = self._build_graph(graph, evaluation, options, expression)
146146
if not graph:
147147
return

pymathics/graph/operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FindSpanningTree(_NetworkXBuiltin):
4040
summary_text = "find a spanning tree"
4141

4242
def eval(self, graph, expression, evaluation: Evaluation, options: dict):
43-
"%(name)s[graph_, OptionsPattern[%(name)s]]"
43+
"expression: %(name)s[graph_, OptionsPattern[%(name)s]]"
4444
graph = self._build_graph(graph, evaluation, options, expression)
4545
if graph:
4646
graph.update_weights(evaluation)

0 commit comments

Comments
 (0)