# Path: features.py
# PICKLE_DIR = join_path(dirname(__file__), 'data/pickle')
# SIMSTRING_DBS_DIR = join_path(dirname(__file__), 'data/simstring')
# SIMSTRING_DBS = [join_path(SIMSTRING_DBS_DIR, p)
#         for p in listdir(SIMSTRING_DBS_DIR) if p.endswith('.db')]
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
# DATE_REGEX = _compile(r'^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$')
# SIMPLE_SPAN_INTERNAL_CLASSES = set((
#         StringPorterStemFeature,
#         StringFeature,
#         LowerCaseStringFeature,
#         PrefixStringFeature,
#         SuffixStringFeature,
#         ))
# class AbstractFeature(object):
# class EnsembleFeature(AbstractFeature):
# class StringPorterStemFeature(object):
# class StringFeature(object):
# class LowerCaseStringFeature(object):
# class WindowStringFeature(object):
# class WindowLowerCaseStringFeature(object):
# class PrefixStringFeature(object):
# class WindowPrefixStringFeature(object):
# class SuffixStringFeature(object):
# class WindowSuffixStringFeature(object):
# class SentenceStringFeature(object):
# class SentenceLowerCaseStringFeature(object):
# class SentencePorterStemStringFeature(object):
# class WindowPorterStemStringFeature(object):
# class CollinsPatternStringFeature(object):
# class SentenceCollinsPatternStringFeature(object):
# class CollapsedCollinsPatternStringFeature(object):
# class SentenceCollapsedCollinsPatternStringFeature(object):
# class WindowCollinsPatternStringFeature(object):
# class WindowCollapsedCollinsPatternStringFeature(object):
# class FormattingStringFeature(object):
# class WindowFormattingStringFeature(object):
# class SpanBoWFeature(object):
# class SpanHeadFeature(object):
# class SpanHeadWindowFeature(object):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def _stem(self, token):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def _stem(self, token):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def get_id(self):
#     def _stem(self, token):
#     def featurise(self, document, sentence, annotation):
# def _collins_pattern(char):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def _featurise(self, token):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):


from os.path import join as path_join
from os.path import basename, dirname, isfile
from sys import path as sys_path
from liblinear import LibLinearClassifier
from config import (SIMSTRING_DB_PATHS, FEATURES_MODULE_PATH,
        CLASSIFIERS_MODULE_PATH)
        from features import SIMSTRING_FEATURES
    from generate import simstring_features_module_template
from features import SIMSTRING_FEATURES
        from classifiers import SIMSTRING_CLASSIFIERS
    from generate import simstring_classifiers_module_template
from classifiers import SIMSTRING_CLASSIFIERS
        import features
    def featurise(self, document, sentence, annotation):
        for feature in self.features:
            for f_tup in feature.featurise(document, sentence, annotation):
                yield (f_tup[0] + '-(<' + feature.get_id() + '>)', f_tup[1])
'''

class SimStringGazetterEnsembleFeature(object):
    def __init__(self):
        self.features = [c() for c in SIMSTRING_FEATURES]

    def get_id(self):
        try:
            return self._id
        except AttributeError:      
        # The hash should uniquely identify a set of SimString features
            self._id = 'SimStringEnsembleFeature<0x{:x}>'.format(
                   hash(' '.join(sorted([f.get_id() for f in self.features]))))
        return self._id

    def featurise(self, document, sentence, annotation):
        for feature in self.features:
            for f_tup in feature.featurise(document, sentence, annotation):
                # Only yield direct hits
                if f_tup[0] == '1.0':
                    #print f_tup[0], type(f_tup[0])
                    #assert False
                    yield (f_tup[0] + '-(<' + feature.get_id() + '>)', f_tup[1])

class TsuruokaEnsembleFeature(object):
    def __init__(self):

# Path: features.py
# PICKLE_DIR = join_path(dirname(__file__), 'data/pickle')
# SIMSTRING_DBS_DIR = join_path(dirname(__file__), 'data/simstring')
# SIMSTRING_DBS = [join_path(SIMSTRING_DBS_DIR, p)
#         for p in listdir(SIMSTRING_DBS_DIR) if p.endswith('.db')]
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
#         NORMALISE = True
# DATE_REGEX = _compile(r'^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$')
# SIMPLE_SPAN_INTERNAL_CLASSES = set((
#         StringPorterStemFeature,
#         StringFeature,
#         LowerCaseStringFeature,
#         PrefixStringFeature,
#         SuffixStringFeature,
#         ))
# class AbstractFeature(object):
# class EnsembleFeature(AbstractFeature):
# class StringPorterStemFeature(object):
# class StringFeature(object):
# class LowerCaseStringFeature(object):
# class WindowStringFeature(object):
# class WindowLowerCaseStringFeature(object):
# class PrefixStringFeature(object):
# class WindowPrefixStringFeature(object):
# class SuffixStringFeature(object):
# class WindowSuffixStringFeature(object):
# class SentenceStringFeature(object):
# class SentenceLowerCaseStringFeature(object):
# class SentencePorterStemStringFeature(object):
# class WindowPorterStemStringFeature(object):
# class CollinsPatternStringFeature(object):
# class SentenceCollinsPatternStringFeature(object):
# class CollapsedCollinsPatternStringFeature(object):
# class SentenceCollapsedCollinsPatternStringFeature(object):
# class WindowCollinsPatternStringFeature(object):
# class WindowCollapsedCollinsPatternStringFeature(object):
# class FormattingStringFeature(object):
# class WindowFormattingStringFeature(object):
# class SpanBoWFeature(object):
# class SpanHeadFeature(object):
# class SpanHeadWindowFeature(object):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def _stem(self, token):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def _stem(self, token):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def get_id(self):
#     def _stem(self, token):
#     def featurise(self, document, sentence, annotation):
# def _collins_pattern(char):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def _featurise(self, token):
#     def featurise(self, document, sentence, annotation):
#     def __init__(self):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):
#     def get_id(self):
#     def featurise(self, document, sentence, annotation):


# Path: classifier/simstring/classifier.py
from os.path import join as path_join
from os.path import basename, dirname, isfile
from sys import path as sys_path
from liblinear import LibLinearClassifier
from config import (SIMSTRING_DB_PATHS, FEATURES_MODULE_PATH,
        CLASSIFIERS_MODULE_PATH)
        from features import SIMSTRING_FEATURES
    from generate import simstring_features_module_template
from features import SIMSTRING_FEATURES
        from classifiers import SIMSTRING_CLASSIFIERS
    from generate import simstring_classifiers_module_template
from classifiers import SIMSTRING_CLASSIFIERS
        import features

    def featurise(self, document, sentence, annotation):
        for feature in self.features:
            for f_tup in feature.featurise(document, sentence, annotation):
                yield (f_tup[0] + '-(<' + feature.get_id() + '>)', f_tup[1])
'''

class SimStringGazetterEnsembleFeature(object):
    def __init__(self):
        self.features = [c() for c in SIMSTRING_FEATURES]

    def get_id(self):
        try:
            return self._id
        except AttributeError:      
        # The hash should uniquely identify a set of SimString features
            self._id = 'SimStringEnsembleFeature<0x{:x}>'.format(
                   hash(' '.join(sorted([f.get_id() for f in self.features]))))
        return self._id

    def featurise(self, document, sentence, annotation):
        for feature in self.features:
            for f_tup in feature.featurise(document, sentence, annotation):
                # Only yield direct hits
                if f_tup[0] == '1.0':
                    #print f_tup[0], type(f_tup[0])
                    #assert False
                    yield (f_tup[0] + '-(<' + feature.get_id() + '>)', f_tup[1])

class TsuruokaEnsembleFeature(object):
    def __init__(self):

        self.features = [c() for c in SIMSTRING_FEATURES]