Skip to content

Commit af55110

Browse files
committed
Back off guide sections...
Until pymathics can handle this.
1 parent ac07be9 commit af55110

4 files changed

Lines changed: 58 additions & 36 deletions

File tree

pymathics/graph/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
VertexList,
5151
)
5252

53-
from pymathics.graph.measures_and_metrics.basic import EdgeCount, VertexCount
54-
from pymathics.graph.measures_and_metrics.degree import VertexDegree
53+
from pymathics.graph.measures_and_metrics import EdgeCount, VertexCount, VertexDegree
5554

5655
from pymathics.graph.algorithms import * # noqa
5756
from pymathics.graph.generators import * # noqa

pymathics/graph/measures_and_metrics/basic.py renamed to pymathics/graph/measures_and_metrics.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
"""
2-
Basic Graph Measures
2+
Graph Measures and Metrics
3+
4+
Measures include basic measures, such as the number of vertices and edges, \
5+
connectivity, degree measures, centrality, and so on.
36
"""
47

8+
59
from typing import Optional
610

711
from mathics.core.atoms import Integer
812
from mathics.core.convert.expression import ListExpression
913
from mathics.core.expression import Expression
1014
from mathics.core.symbols import Symbol
15+
from mathics.core.systemsymbols import SymbolLength
1116

1217
from pymathics.graph.base import _NetworkXBuiltin
1318

1419
# FIXME: add context
15-
SymbolLength = Symbol("Length")
1620
SymbolCases = Symbol("Cases")
1721

1822

23+
# FIXME put this in its own file/module basic
24+
# when pymathics doc can handle this.
25+
# """
26+
# Basic Graph Measures
27+
# """
1928
class _PatternCount(_NetworkXBuiltin):
2029
"""
2130
Counts of vertices or edges, allowing rules to specify the graph.
@@ -62,6 +71,7 @@ class EdgeCount(_PatternCount):
6271
= 2
6372
"""
6473

74+
no_doc = False
6575
summary_text = "count edges in graph"
6676

6777
def _items(self, graph):
@@ -92,7 +102,52 @@ class VertexCount(_PatternCount):
92102
= 2
93103
"""
94104

105+
no_doc = False
95106
summary_text = "count vertices in graph"
96107

97108
def _items(self, graph):
98109
return graph.G.nodes
110+
111+
112+
# Put this in its own file/module "degree.py"
113+
# when pymathics doc can handle.
114+
# """
115+
# Graph Degree Measures
116+
# """
117+
118+
119+
class VertexDegree(_NetworkXBuiltin):
120+
"""
121+
<url>
122+
:WMA link:
123+
https://reference.wolfram.com/language/ref/EdgeCount.html</url>
124+
125+
<dl>
126+
<dt>'VertexDegree[$g$]'
127+
<dd>returns a list of the degrees of each of the vertices in graph $g$.
128+
129+
<dt>'EdgeCount[$g$, $patt$]'
130+
<dd>returns the number of edges that match the pattern $patt$.
131+
132+
<dt>'EdgeCount[{$v$->$w}, ...}, ...]'
133+
<dd>uses rules $v$->$w$ to specify the graph $g$.
134+
</dl>
135+
136+
>> VertexDegree[{1 <-> 2, 2 <-> 3, 2 <-> 4}]
137+
= {1, 3, 1, 1}
138+
"""
139+
140+
no_doc = False
141+
summary_text = "list graph vertex degrees"
142+
143+
def eval(self, graph, evaluation, options):
144+
"%(name)s[graph_, OptionsPattern[%(name)s]]"
145+
146+
def degrees(graph):
147+
degrees = dict(list(graph.G.degree(graph.vertices)))
148+
return ListExpression(*[Integer(degrees.get(v, 0)) for v in graph.vertices])
149+
150+
return self._evaluate_atom(graph, options, degrees)
151+
152+
153+
# TODO: VertexInDegree, VertexOutDegree

pymathics/graph/measures_and_metrics/__init__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

pymathics/graph/measures_and_metrics/degree.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)