parameters: (X, templates)
docstring: Generate features for an item sequence by applying feature templates.
      A feature template consists of a tuple of (name, offset) pairs,
      where name and offset specify a field name and offset from which
      the template extracts a feature value. Generated features are stored
      in the 'F' field of each item in the sequence.
  
      @type   X:      list of mapping objects
      @param  X:      The item sequence.
      @type   template:   tuple of (str, int)
      @param  template:   The feature template.
docstring_summary: Generate features for an item sequence by applying feature templates.
      A feature template consists of a tuple of (name, offset) pairs,
      where name and offset specify a field name and offset from which
      the template extracts a feature value. Generated features are stored
      in the 'F' field of each item in the sequence.
docstring_tokens: Generate features for an item sequence by applying feature templates . A feature template consists of a tuple of ( name offset ) pairs where name and offset specify a field name and offset from which the template extracts a feature value . Generated features are stored in the F field of each item in the sequence .
function: def apply_templates(X, templates):
      """
      Generate features for an item sequence by applying feature templates.
      A feature template consists of a tuple of (name, offset) pairs,
      where name and offset specify a field name and offset from which
      the template extracts a feature value. Generated features are stored
      in the 'F' field of each item in the sequence.
  
      @type   X:      list of mapping objects
      @param  X:      The item sequence.
      @type   template:   tuple of (str, int)
      @param  template:   The feature template.
      """
      for template in templates:
          name = '|'.join(['%s[%d]' % (f, o) for f, o in template])
          X_len = len(X)
          for t in range(X_len):
              values = []
              for field, offset in template:
                  p = t + offset
                  if p < 0 or p >= X_len: 
                      values = []
                      break
                  values.append(X[p][field])
              if values:
                  X[t]['F'].append('%s=%s' % (name, '|'.join(values)))
function_tokens: def apply_templates ( X , templates ) : for template in templates : name = '|' . join ( [ '%s[%d]' % ( f , o ) for f , o in template ] ) X_len = len ( X ) for t in range ( X_len ) : values = [ ] for field , offset in template : p = t + offset if p < 0 or p >= X_len : values = [ ] break values . append ( X [ p ] [ field ] ) if values : X [ t ] [ 'F' ] . append ( '%s=%s' % ( name , '|' . join ( values ) ) )