next up previous contents
Next: Global vs Local Labelings Up: Labelings Previous: Removing Labels   Contents

Retrieving information

A Labeling isn't much good if you can't get any information out of it, so here are the methods available to query the Labeling about what label labels what.

Again, these methods parallel the functionality of the methods for attaching and removing labels. So, now that we have a full arsenal of methods to work with, let's try some examples. The first example will be to apply some simple labelings and retrieve data based on those labels.

>>> #
    # Create a dataset and labeling
    #

>>> ds = Dataset(MLab.rand(5,3))
>>> ds.setName('Test Dataset')
>>> lab = Labeling(ds)
>>> lab.setName('First Labeling')
>>> #
    # label all the rows and test querying
    #

>>> lab.labelRows(['row 0',1,'two','three',5.0])
>>> lab.getLabelsByRow(0)
['row 0']
>>> lab.getRowsByLabel('two')
[2]
>>> #
    # Add a single label to a column and test
    #

>>> lab.addLabelToCol('two',2)
>>> lab.getColsByLabel('two')
[2]
>>> lab.getKeysByLabel('two')
[2, 7]
>>> #
    # Add an existing row label to all rows, notice
    # that one row will be listed as being labeled
    # twice (which it is)

>>> lab.addLabelToRows(5,[0,2,4])
>>> lab.getLabels()
['three', 'two', 5.0, 'row 0', 1]
>>> lab.getRowsByLabel(5)
[0, 2, 4]
>>> lab.getRowsByLabel(5.0)
[0, 2, 4]
>>> #
    # Now remove some labels
    #

>>> lab.removeLabel(5)
>>> lab.getRowsByLabel(5.0)
[]
>>> lab.removeLabelsFromCol(2)
>>> lab.getLabels()
['row 0', 'two', 'three', 1]
>>> lab.removeAll()
>>> lab.getLabels()
[]
>>> ds.removeLabeling(lab)
>>> ds
Dataset: Test Dataset, 5 by 3
>>> ds.getLabelings()
[]



Lucas Scharenbroich 2003-08-27