'Construct a Template for generating Rules.
Takes a list of Features. A C{Feature} is a combination
of a specific property and its relative positions and should be
a subclass of L{nltk.tbl.feature.Feature}.
An alternative calling convention (kept for backwards compatibility,
but less expressive as it only permits one feature type) is
Template(Feature, (start1, end1), (start2, end2), ...)
In new code, that would be better written
Template(Feature(start1, end1), Feature(start2, end2), ...)
#For instance, importing some features
>>> from nltk.tbl.template import Template
>>> from nltk.tag.brill import Word, Pos
#create some features
>>> wfeat1, wfeat2, pfeat = (Word([-1]), Word([1,2]), Pos([-2,-1]))
#Create a single-feature template
>>> Template(wfeat1)
Template(Word([-1]))
#or a two-feature one
>>> Template(wfeat1, wfeat2)
Template(Word([-1]),Word([1, 2]))
#or a three-feature one with two different feature types
>>> Template(wfeat1, wfeat2, pfeat)
Template(Word([-1]),Word([1, 2]),Pos([-2, -1]))
#deprecated api: Feature subclass, followed by list of (start,end) pairs
#(permits only a single Feature)
>>> Template(Word, (-2,-1), (0,0))
Template(Word([-2, -1]),Word([0]))
#incorrect specification raises TypeError
>>> Template(Word, (-2,-1), Pos, (0,0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "nltk/tag/tbl/template.py", line 143, in __init__
raise TypeError(
TypeError: expected either Feature1(args), Feature2(args), ... or Feature, (start1, end1), (start2, end2), ...
:type features: list of Features
:param features: the features to build this Template on'

def __init__(self, *features):

    if all((isinstance(f, Feature) for f in features)):
        self._features = features
    elif (issubclass(features[0], Feature) and all((isinstance(a, tuple) for a in features[1:]))):
        self._features = [features[0](*tp) for tp in features[1:]]
    else:
        raise TypeError('expected    either    Feature1(args),    Feature2(args),    ...    or    Feature,    (start1,    end1),    (start2,    end2),    ...')
    self.id = '{0:03d}'.format(len(self.ALLTEMPLATES))
    self.ALLTEMPLATES.append(self)
