<commit_before>import string
from random import random

from Ch2.Graph import *
from Ch2.GraphWorld import CircleLayout, GraphWorld


class RandomGraph(Graph):
    def add_random_edges(self, p):
        vs = self.vertices()
        for i, v in enumerate(vs):
            for j, w in enumerate(vs):
                if i >= j: continue
                if random() > p: continue
                self.add_edge(Edge(v, w))


def main(script, n=10, p=0.2, *args):
    n = int(n)
    p = float(p)
    labels = string.ascii_lowercase + string.ascii_uppercase
    vs = [Vertex(c) for c in labels[:n]]

    # create a graph and a layout
    g = RandomGraph(vs)
    g.add_random_edges(p)
    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()


if __name__ == '__main__':
    import sys

    main(*sys.argv)
<commit_msg>ex 2-4 patch<commit_after>import string
from random import random

from Ch2.Graph import *
from Ch2.GraphWorld import CircleLayout, GraphWorld


class RandomGraph(Graph):
    def add_random_edges(self, p):
        vs = self.vertices()
        for i, v in enumerate(vs):
            for j, w in enumerate(vs):
                if i >= j: continue
                if random() > p: continue
                self.add_edge(Edge(v, w))
                self.add_edge(Edge(w, v))


def main(script, n=10, p=0.2, *args):
    n = int(n)
    p = float(p)
    labels = string.ascii_lowercase + string.ascii_uppercase
    vs = [Vertex(c) for c in labels[:n]]

    # create a graph and a layout
    g = RandomGraph(vs)
    g.add_random_edges(p)
    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()


if __name__ == '__main__':
    import sys

    main(*sys.argv)

{'fraction_non_alphanumeric': 0.11235326998323085, 'fraction_numerical': 0.007825600894354388, 'mean_word_length': 2.3457943925233646, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '65499', 'n_tokens_mistral': 625, 'n_tokens_neox': 594, 'n_words': 172}