# Path: dsenser/constants.py
# ARG1 = "Arg1"
# 
# ARG2 = "Arg2"
# 
# CHAR_SPAN = "CharacterSpanList"
# 
# CONNECTIVE = "Connective"
# 
# ENCODING = "utf-8"
# 
# RAW_TEXT = "RawText"
# 
# SENSE = "Sense"
# 
# TOK_LIST = "TokenList"
# 
# TOK_OFFS_IDX = 2
# 
# TYPE = "Type"
# 
# DFLT_MODEL_PATH = os.path.join(MODEL_DIR, "pdtb.sense.model")
# 
# DFLT_MODEL_TYPE = WANG
# 
# DFLT_ECONN_PATH = os.path.join(ECONN_DIR, "ExpConn.txt")
# 
# ALT_LEX = "AltLex"
# 
# EXPLICIT = "Explicit"
# 
# IMPLICIT = "Implicit"
# 
# SVD = 1
# 
# LSTM = 2
# 
# MJR = 4
# 
# WANG = 8
# 
# XGBOOST = 16
# 
# PARSE_TREE = "parsetree"
# 
# DEPS = "dependencies"
# 
# WORDS = "words"
# 
# SENTENCES = "sentences"
# 
# SHORT2FULL = {"Expansion": "Expansion.Conjunction",
#               "Comparison": "Comparison.Contrast",
#               "Comparison.COntrast": "Comparison.Contrast"}
# 
# Path: dsenser/utils.py
# class timeit(object):
#     """Decorator class for measuring time performance.
# 
#     Attributes:
#       msg (str): message to be printed on method invocation
# 
#     """
# 
#     def __init__(self, a_msg):
#         """Class constructor.
# 
#         Args:
#           a_msg (str): debug message to print
# 
#         """
#         self.msg = a_msg
# 
#     def __call__(self, a_func):
#         """Decorator function.
# 
#         Args:
#           a_func (method): decorated method
# 
#         Returns:
#           method: wrapped method
# 
#         """
#         def _wrapper(*args, **kwargs):
#             print(self.msg + " started", file=sys.stderr)
#             start_time = datetime.utcnow()
#             a_func(*args, **kwargs)
#             end_time = datetime.utcnow()
#             time_delta = (end_time - start_time).total_seconds()
#             print(self.msg + " finished ({:.2f} sec)".format(time_delta),
#                   file=sys.stderr)
#         return wraps(a_func)(_wrapper)


from dsenser.constants import ARG1, ARG2, CHAR_SPAN, CONNECTIVE, ENCODING, \
    RAW_TEXT, SENSE, TOK_LIST, TOK_OFFS_IDX, TYPE, DFLT_MODEL_PATH, \
    DFLT_MODEL_TYPE, DFLT_ECONN_PATH, ALT_LEX, EXPLICIT, IMPLICIT, SVD, \
    LSTM, MJR, WANG, XGBOOST, PARSE_TREE, DEPS, WORDS, SENTENCES, SHORT2FULL
from dsenser.utils import timeit
from collections import Iterable
from cPickle import dump, load
from itertools import chain
            from dsenser.major import MajorSenser
            from dsenser.wang import WangSenser
            from dsenser.xgboost import XGBoostSenser
            from dsenser.svd import SVDSenser
            from dsenser.lstm import LSTMSenser
                from dsenser.svd import SVDSenser
                from dsenser.lstm import LSTMSenser
import codecs
import gc
import numpy as np
import os
import sys
            self.models.append(XGBoostSenser(a_grid_search=a_grid_search))
        # NN models have to go last, since we are pruning the parses for them
        # to free some memory
        nn_used = False
        if a_type & SVD:
            # since we cannot differentiate SVD yet, we can only use word2vec
            # embeddings
            if not a_w2v or a_lstsq:
                print("SVD senser does not support task-specific embeddings "
                      "and least squares yet.", file=sys.stderr)
            self.models.append(SVDSenser(a_w2v=True, a_lstsq=False,
                                         a_max_iters=256))
            nn_used = True
        if a_type & LSTM:
            self.models.append(LSTMSenser(a_w2v, a_lstsq))
            nn_used = True
        # remember all possible senses
        n_senses = 0
        for irel in chain(a_train_data[0], a_dev_data[0]
                          if a_dev_data is not None else []):
            for isense in irel[SENSE]:
                isense = SHORT2FULL.get(isense, isense)
                if isense not in self.cls2idx:
                    n_senses = len(self.cls2idx)
                    self.cls2idx[isense] = n_senses
                    self.idx2cls[n_senses] = isense
            if irel[TYPE] == EXPLICIT:
                self.econn.add(self._normalize_conn(
                    irel[CONNECTIVE][RAW_TEXT]))
            else:

# Path: dsenser/constants.py
# ARG1 = "Arg1"
# 
# ARG2 = "Arg2"
# 
# CHAR_SPAN = "CharacterSpanList"
# 
# CONNECTIVE = "Connective"
# 
# ENCODING = "utf-8"
# 
# RAW_TEXT = "RawText"
# 
# SENSE = "Sense"
# 
# TOK_LIST = "TokenList"
# 
# TOK_OFFS_IDX = 2
# 
# TYPE = "Type"
# 
# DFLT_MODEL_PATH = os.path.join(MODEL_DIR, "pdtb.sense.model")
# 
# DFLT_MODEL_TYPE = WANG
# 
# DFLT_ECONN_PATH = os.path.join(ECONN_DIR, "ExpConn.txt")
# 
# ALT_LEX = "AltLex"
# 
# EXPLICIT = "Explicit"
# 
# IMPLICIT = "Implicit"
# 
# SVD = 1
# 
# LSTM = 2
# 
# MJR = 4
# 
# WANG = 8
# 
# XGBOOST = 16
# 
# PARSE_TREE = "parsetree"
# 
# DEPS = "dependencies"
# 
# WORDS = "words"
# 
# SENTENCES = "sentences"
# 
# SHORT2FULL = {"Expansion": "Expansion.Conjunction",
#               "Comparison": "Comparison.Contrast",
#               "Comparison.COntrast": "Comparison.Contrast"}
# 
# Path: dsenser/utils.py
# class timeit(object):
#     """Decorator class for measuring time performance.
# 
#     Attributes:
#       msg (str): message to be printed on method invocation
# 
#     """
# 
#     def __init__(self, a_msg):
#         """Class constructor.
# 
#         Args:
#           a_msg (str): debug message to print
# 
#         """
#         self.msg = a_msg
# 
#     def __call__(self, a_func):
#         """Decorator function.
# 
#         Args:
#           a_func (method): decorated method
# 
#         Returns:
#           method: wrapped method
# 
#         """
#         def _wrapper(*args, **kwargs):
#             print(self.msg + " started", file=sys.stderr)
#             start_time = datetime.utcnow()
#             a_func(*args, **kwargs)
#             end_time = datetime.utcnow()
#             time_delta = (end_time - start_time).total_seconds()
#             print(self.msg + " finished ({:.2f} sec)".format(time_delta),
#                   file=sys.stderr)
#         return wraps(a_func)(_wrapper)


# Path: dsenser/dsenser.py
from dsenser.constants import ARG1, ARG2, CHAR_SPAN, CONNECTIVE, ENCODING, \
    RAW_TEXT, SENSE, TOK_LIST, TOK_OFFS_IDX, TYPE, DFLT_MODEL_PATH, \
    DFLT_MODEL_TYPE, DFLT_ECONN_PATH, ALT_LEX, EXPLICIT, IMPLICIT, SVD, \
    LSTM, MJR, WANG, XGBOOST, PARSE_TREE, DEPS, WORDS, SENTENCES, SHORT2FULL
from dsenser.utils import timeit
from collections import Iterable
from cPickle import dump, load
from itertools import chain
            from dsenser.major import MajorSenser
            from dsenser.wang import WangSenser
            from dsenser.xgboost import XGBoostSenser
            from dsenser.svd import SVDSenser
            from dsenser.lstm import LSTMSenser
                from dsenser.svd import SVDSenser
                from dsenser.lstm import LSTMSenser
import codecs
import gc
import numpy as np
import os
import sys

            self.models.append(XGBoostSenser(a_grid_search=a_grid_search))
        # NN models have to go last, since we are pruning the parses for them
        # to free some memory
        nn_used = False
        if a_type & SVD:
            # since we cannot differentiate SVD yet, we can only use word2vec
            # embeddings
            if not a_w2v or a_lstsq:
                print("SVD senser does not support task-specific embeddings "
                      "and least squares yet.", file=sys.stderr)
            self.models.append(SVDSenser(a_w2v=True, a_lstsq=False,
                                         a_max_iters=256))
            nn_used = True
        if a_type & LSTM:
            self.models.append(LSTMSenser(a_w2v, a_lstsq))
            nn_used = True
        # remember all possible senses
        n_senses = 0
        for irel in chain(a_train_data[0], a_dev_data[0]
                          if a_dev_data is not None else []):
            for isense in irel[SENSE]:
                isense = SHORT2FULL.get(isense, isense)
                if isense not in self.cls2idx:
                    n_senses = len(self.cls2idx)
                    self.cls2idx[isense] = n_senses
                    self.idx2cls[n_senses] = isense
            if irel[TYPE] == EXPLICIT:
                self.econn.add(self._normalize_conn(
                    irel[CONNECTIVE][RAW_TEXT]))
            else:

                irel[CONNECTIVE][RAW_TEXT] = ""