Ejemplo n.º 1
0
    def __init__(self, size=0):
        OrderedDict.__init__(self)

        for l in self.columns_def.split("\n"):
            l = l.strip().split()
            if l:
                self[l[0]] = Column(l[0], l[1], " ".join(l[2:]), size)
Ejemplo n.º 2
0
 def __init__(self, features=()):
     """
     @param features: a iterable of Feat instances describing feature
     properties
     
     @return: a _Descriptor object
     """
     self._odict = OrderedDict()
     self.extend(features)
Ejemplo n.º 3
0
 def __init__(self, size=0):
     OrderedDict.__init__(self)
     
     for l in self.columns_def.split("\n"):
         l = l.strip().split()
         if l:
             self[l[0]] = Column(l[0], 
                                 l[1], 
                                 " ".join(l[2:]),
                                 size)
Ejemplo n.º 4
0
 def __init__(self, features=()):
     """
     @param features: a iterable of Feat instances describing feature
     properties
     
     @return: a _Descriptor object
     """
     self._odict = OrderedDict()
     self.extend(features)
Ejemplo n.º 5
0
class _Descriptor(object):
    """
    Abstract class for feature descriptions
    
    A _Descriptor instance describes the features of a dataset (instances). The
    order is significant. It wraps an ordered dictionary where the keys are
    unique feature names and the values are Feat instances. Each Feat instance
    defines the properties of a feature (it's type, the associated feature
    function, etc.).
    """
    def __init__(self, features=()):
        """
        @param features: a iterable of Feat instances describing feature
        properties
        
        @return: a _Descriptor object
        """
        self._odict = OrderedDict()
        self.extend(features)

    def __getitem__(self, name):
        return self._odict[name]

    def __setitem__(self, name, feat):
        assert isinstance(feat, Feat)
        self._odict[name] = feat

    def __iter__(self):
        # in contrast to dict, iterates over values (i.e. features) rather
        # than keys (i.e. feature names)
        return iter(self._odict.values())

    def extend(self, features):
        for feat in features:
            self[feat.name] = feat

    @property
    def descr(self):
        """
        return feature description as a Numpy field description
        (list of feature name and type pairs)
        """
        return [(feat.name, feat.type) for feat in self]

    @property
    def dtype(self):
        """
        return feature description as a Numpy dtype
        """
        return numpy.dtype(self.descr)

    def pprint(self, out=sys.stdout):
        """
        pretty print feature description
        """
        # feature properties are hard coded...
        out.write("No:".ljust(4) + "\t" + "Name:".ljust(32) + "\t" +
                  "Type:".ljust(8) + "\t" + "Metric:".ljust(8) + "\t" +
                  "Function:".ljust(32) + "\t" +
                  "Preprep graph hooks:".ljust(32) + "\t" +
                  "Preprep node hooks:\n")

        for i, feat in enumerate(self):
            pp_graph_hooks = ", ".join(obj.__name__
                                       for obj in feat.pp_graph_hooks)
            pp_node_hooks = ", ".join(obj.__name__
                                      for obj in feat.pp_node_hooks)
            out.write("%-4d\t%-32s\t%-8s\t%-8s\t%-32s\t%-32s\t%-32s\n" %
                      (i + 1, feat.name, feat.type, feat.metric,
                       feat.function.func_name, pp_graph_hooks, pp_node_hooks))
Ejemplo n.º 6
0
class _Descriptor(object):
    """
    Abstract class for feature descriptions
    
    A _Descriptor instance describes the features of a dataset (instances). The
    order is significant. It wraps an ordered dictionary where the keys are
    unique feature names and the values are Feat instances. Each Feat instance
    defines the properties of a feature (it's type, the associated feature
    function, etc.).
    """
    
    def __init__(self, features=()):
        """
        @param features: a iterable of Feat instances describing feature
        properties
        
        @return: a _Descriptor object
        """
        self._odict = OrderedDict()
        self.extend(features)

        
    def __getitem__(self, name):
        return self._odict[name]
        
        
    def __setitem__(self, name, feat):
        assert isinstance(feat, Feat)
        self._odict[name] = feat
        
        
    def __iter__(self):
        # in contrast to dict, iterates over values (i.e. features) rather
        # than keys (i.e. feature names)
        return iter(self._odict.values())
        
        
    def extend(self, features):
        for feat in features: 
            self[feat.name] = feat 

    
    @property       
    def descr(self):
        """
        return feature description as a Numpy field description
        (list of feature name and type pairs)
        """
        return [ (feat.name, feat.type)
                 for feat in self ]

    
    @property 
    def dtype(self):
        """
        return feature description as a Numpy dtype
        """
        return numpy.dtype(self.descr)

    
    def pprint(self, out=sys.stdout):
        """
        pretty print feature description
        """
        # feature properties are hard coded...
        out.write("No:".ljust(4) + "\t" +
                  "Name:".ljust(32) + "\t" +
                  "Type:".ljust(8) + "\t" +
                  "Metric:".ljust(8) + "\t" +
                  "Function:".ljust(32) + "\t" +
                  "Preprep graph hooks:".ljust(32) + "\t" +
                  "Preprep node hooks:\n")
            
        for i, feat in enumerate(self):
            pp_graph_hooks = ", ".join(obj.__name__
                                       for obj in feat.pp_graph_hooks)
            pp_node_hooks = ", ".join(obj.__name__
                                       for obj in feat.pp_node_hooks)
            out.write("%-4d\t%-32s\t%-8s\t%-8s\t%-32s\t%-32s\t%-32s\n"  % (
                i+1,
                feat.name,
                feat.type,
                feat.metric,
                feat.function.func_name,
                pp_graph_hooks,
                pp_node_hooks))