Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Fixed docstrings.

This commit is contained in:
Einar Ryeng 2007-08-02 10:08:52 +00:00
parent 4c24061575
commit f12fe23c1b
1 changed files with 27 additions and 0 deletions

View File

@ -36,6 +36,7 @@ class Dataset:
data = Dataset(rand(10,20)) (generates dims and ids (no links))
"""
def __init__(self, array, identifiers=None, name='Unnamed dataset'):
self._dims = [] #existing dimensions in this dataset
self._map = {} # internal mapping for dataset: identifier <--> index
@ -195,6 +196,20 @@ class Dataset:
return asarray(index)
def existing_identifiers(self, dim, idents):
"""Filters a list of identifiers to find those that are present in the
dataset.
The most common use of this function is to get a list of
identifiers who correspond one to one with the list of indices produced
when get_indices is given an identifier list. That is
ds.get_indices(dim, idents) and ds.exisiting_identifiers(dim, idents)
will have the same order.
@param dim: A dimension present in the dataset.
@param idents: A list of identifiers along the given dimension.
@return: A list of identifiers in the same order as idents, but
without elements not present in the dataset.
"""
if not isinstance(idents, list) and not isinstance(idents, set):
raise ValueError("idents needs to be a list/set got: %s" %type(idents))
@ -410,6 +425,12 @@ class Selection(dict):
def write_ftsv(fd, ds):
"""Writes a dataset in fluents tab separated values (ftsv) form.
@param fd: An open file descriptor to the output file.
@param ds: The dataset to be written. The function handles datasets
of these classes: Dataset, CategoryDataset and GraphDataset
"""
# Write header information
if isinstance(ds, CategoryDataset):
type = 'category'
@ -443,6 +464,12 @@ def write_ftsv(fd, ds):
def read_ftsv(fd):
"""Read a dataset in fluents tab separated values (ftsv) form and return it.
@param fd: An open file descriptor.
@return: A Dataset, CategoryDataset or GraphDataset depending on the information
read.
"""
split_re = re.compile('^#\s*(\w+)\s*:\s*(.+)')
dimensions = []
identifiers = {}