Ticket #5936: trac5936_graphdatabase.patch

File trac5936_graphdatabase.patch, 3.5 KB (added by rlm, 12 years ago)

Referee edit of Emily's patch

  • sage/graphs/graph.py

    # HG changeset patch
    # User Emily Kirkman <>
    # Date 1242944980 25200
    # Node ID 6413fa78f7f27d9f7e484216a764196398873053
    # Parent  7c44855076d1a6a8d62a109f5ba535041f21a852
    graph database iterator and docstring updates
    
    diff -r 7c44855076d1 -r 6413fa78f7f2 sage/graphs/graph.py
    a b  
    284284There is a database available for searching for graphs that satisfy
    285285a certain set of parameters, including number of vertices and
    286286edges, density, maximum and minimum degree, diameter, radius, and
    287 connectivity. If you wish to search a database of graphs by
    288 parameter, type
    289 
    290 ::
    291 
    292     sage: graphs_query.[tab]             # not tested
    293 
    294 and hit ``tab``.
    295 
    296 ::
    297 
    298     sage: gq = GraphQuery(display_cols=['graph6'],num_vertices=7, diameter=5)
    299     sage: L = gq.get_graphs_list()
    300     sage: graphs_list.show_graphs(L)
     287connectivity. To see a list of all search parameter keywords broken
     288down by their designated table names, type
     289
     290::
     291   
     292    sage: graph_db_info()
     293    {...}
     294   
     295For more details on datatypes or keyword input, enter
     296
     297::
     298
     299    sage: GraphQuery?    # not tested
     300
     301The results of a query can be viewed with the show method, or can be
     302viewed individually by iterating through the results:
     303
     304::
     305
     306    sage: Q = GraphQuery(display_cols=['graph6'],num_vertices=7, diameter=5)
     307    sage: Q.show()
     308    Graph6
     309    --------------------
     310    F@?]O               
     311    F@OKg               
     312    F?`po               
     313    F?gqg               
     314    FIAHo               
     315    F@R@o               
     316    FA_pW               
     317    FGC{o               
     318    FEOhW
     319
     320Show each graph as you iterate through the results:
     321
     322::
     323
     324    sage: for g in Q:
     325    ...     show(g)
     326
    301327
    302328Visualization
    303329-------------
  • sage/graphs/graph_database.py

    diff -r 7c44855076d1 -r 6413fa78f7f2 sage/graphs/graph_database.py
    a b  
    475475                                # substitue disp_str and join_str back into self's query string
    476476                                self.__query_string__ = re.sub('SELECT.*WHERE ', disp_str + join_str + \
    477477                                                                                                'WHERE ', self.__query_string__)
    478                    
     478   
     479    def query_iterator(self):
     480        """
     481        Returns an iterator over the results list of the GraphQuery.
     482       
     483        EXAMPLE::
     484               
     485            sage: Q = GraphQuery(display_cols=['graph6'],num_vertices=7, diameter=5)
     486            sage: for g in Q:
     487            ...     print g.graph6_string()
     488            F@?]O
     489            F@OKg
     490            F?`po
     491            F?gqg
     492            FIAHo
     493            F@R@o
     494            FA_pW
     495            FGC{o
     496            FEOhW
     497       
     498            sage: Q = GraphQuery(display_cols=['graph6'],num_vertices=7, diameter=5)
     499            sage: it = iter(Q)
     500            sage: while True:
     501            ...     try: print it.next().graph6_string()
     502            ...     except StopIteration: break
     503            F@?]O
     504            F@OKg
     505            F?`po
     506            F?gqg
     507            FIAHo
     508            F@R@o
     509            FA_pW
     510            FGC{o
     511            FEOhW
     512
     513        """
     514        return iter(self.get_graphs_list())
     515       
     516    __iter__ = query_iterator
     517                                                 
    479518    def show(self, max_field_size=20, with_picture=False):
    480519        """
    481520        Displays the results of a query in table format.