The congress.datalog.factset Module

class congress.datalog.factset.FactSet

Bases: object

Maintains a set of facts, and provides indexing for efficient iteration, given a partial or full match. Expects that all facts are the same width.

add(fact)

Add a fact to the FactSet

Returns True if the fact is absent from this FactSet and adds the fact, otherwise returns False.

create_index(columns)

Create an index

@columns is a tuple of column indicies that index into the facts in self. @columns must be sorted in ascending order, and each column index must be less than the width of a fact in self. If the index exists, do nothing.

find(partial_fact, iterations=None)

Find Facts given a partial fact

@partial_fact is a tuple of pair tuples. The first item in each pair tuple is an index into a fact, and the second item is a value to match again self._facts. Expects the pairs to be sorted by index in ascending order.

@iterations is either an empty list or None. If @iterations is an empty list, then find() will append the number of iterations find() used to compute the return value(this is useful for testing indexing).

Returns matching Facts.

has_index(columns)

Returns True if the index exists.

remove(fact)

Remove a fact from the FactSet

Returns True if the fact is in this FactSet and removes the fact, otherwise returns False.

remove_index(columns)

Remove an index

@columns is a tuple of column indicies that index into the facts in self. @columns must be sorted in ascending order, and each column index must be less than the width of a fact in self. If the index does not exists, raise KeyError.