# Path: tagset.py
# class Tag:
#     def __init__(self, field, position, tagset):
#         self.field = field
#         self.position = position
#         self.tagset = tagset
#         tagset.tag_fields.add(field)
# 
#     def c_value(self):
#         if self.position == 0:
#             return 'tag'
#         else:
#             return '((i>=%d)? history[i-%d] : %s)' % (
#                     -self.position, -self.position, self.tagset.c_n_tags)


import sys
import hashlib, math
from collections import defaultdict
from tagset import Tag

        for idx, hash_name in enumerate(pi_hashes):
            f.write('    pi_hashes[%d] = %s;\n' % (idx, hash_name))

        f.write('''
    field_buf += n_fields;
    field_len += n_fields;
    pi_hashes += %d;
}
return 0;
}

#define N_INVARIANTS    %d
#define N_FEATURES      %d
''' % (len(pi_hashes), len(pi_hashes), len(self.terms)))

        f.write('''
static void extract_features(
        const label *history,
        label tag,
        size_t i,
        size_t n_items,
        const partial_hash_t *pi_hashes,
        feat_hash_t *feature_hashes)
{
''')

        pi_hashes_idx = { s: i for i, s in enumerate(pi_hashes) }
        for idx,cons in enumerate(self.terms):
            form_cons = [con for con in cons if isinstance(con, Form)]

# Path: tagset.py
# class Tag:
#     def __init__(self, field, position, tagset):
#         self.field = field
#         self.position = position
#         self.tagset = tagset
#         tagset.tag_fields.add(field)
# 
#     def c_value(self):
#         if self.position == 0:
#             return 'tag'
#         else:
#             return '((i>=%d)? history[i-%d] : %s)' % (
#                     -self.position, -self.position, self.tagset.c_n_tags)


# Path: form.py
import sys
import hashlib, math
from collections import defaultdict
from tagset import Tag


        for idx, hash_name in enumerate(pi_hashes):
            f.write('    pi_hashes[%d] = %s;\n' % (idx, hash_name))

        f.write('''
    field_buf += n_fields;
    field_len += n_fields;
    pi_hashes += %d;
}
return 0;
}

#define N_INVARIANTS    %d
#define N_FEATURES      %d
''' % (len(pi_hashes), len(pi_hashes), len(self.terms)))

        f.write('''
static void extract_features(
        const label *history,
        label tag,
        size_t i,
        size_t n_items,
        const partial_hash_t *pi_hashes,
        feat_hash_t *feature_hashes)
{
''')

        pi_hashes_idx = { s: i for i, s in enumerate(pi_hashes) }
        for idx,cons in enumerate(self.terms):
            form_cons = [con for con in cons if isinstance(con, Form)]

            tag_cons = [con for con in cons if isinstance(con, Tag)]