# Path: dsenser/svd/svd.py
# class SVDSenser(BaseSenser):
#     """Class using LSTM classification for disambiguating connectives.
# 
#     Attributes:
#       explicit (:class:`dsenser.svd.explicit.SVDExplicitSenser`):
#         classifier for implicit discourse relations
#       implicit (:class:`dsenser.svd.implicit.SVDExplicitSenser`):
#         classifier for explicit discourse relations
#       n_y (int): number of distinct classes
# 
#     """
# 
#     def __init__(self, *args, **kwargs):
#         """
#         Class constructor.
# 
#         Args:
#           args (list): list of arguments
#           kwargs (dict): dictionary of keyword arguments
# 
#         """
#         self.explicit = SVDExplicitSenser(*args, **kwargs)
#         self.implicit = SVDImplicitSenser(*args, **kwargs)
#         self.n_y = -1
# 
# Path: dsenser/svd/svdbase.py
# class SVDBaseSenser(NNBaseSenser):
#     """Abstract class for disambiguating relation senses.
# 
#     Attributes:
#       n_y (int): number of distinct classes
# 
#     """
# 
#     def _init_nn(self):
#         """Initialize neural network.
# 
#         """
#         self.intm_dim = max(MIN_DIM, self.ndim - (self.ndim - self.n_y) / 2)
#         # indices of word embeddings
#         self.W_INDICES_ARG1 = TT.ivector(name="W_INDICES_ARG1")
#         self.W_INDICES_ARG2 = TT.ivector(name="W_INDICES_ARG2")
#         # connective's index
#         self.CONN_INDEX = TT.iscalar(name="CONN_INDEX")
#         # initialize the matrix of word embeddings
#         self.init_w_emb()
#         # word embeddings of the arguments
#         self.EMB_ARG1 = self.W_EMB[self.W_INDICES_ARG1]
#         self.EMB_ARG2 = self.W_EMB[self.W_INDICES_ARG2]
#         # connective's embedding
#         self._init_conn_emb()
#         self.EMB_CONN = self.CONN_EMB[self.CONN_INDEX]
#         # perform matrix decomposition
#         _, _, self.ARG1 = TT.nlinalg.svd(self.EMB_ARG1,
#                                          full_matrices=True)
#         _, _, self.ARG2 = TT.nlinalg.svd(self.EMB_ARG2,
#                                          full_matrices=True)
#         self.ARG_DIFF = self.ARG1 - self.ARG2
#         # map decomposed matrices to the intermediate level
#         self.ARG_DIFF2I = theano.shared(value=HE_UNIFORM((self.ndim, 1)),
#                                         name="ARG_DIFF2I")
#         self.arg_diff_bias = theano.shared(value=HE_UNIFORM((1, self.ndim)),
#                                            name="arg_diff_bias")
#         self._params.extend([self.ARG_DIFF2I, self.arg_diff_bias])
#         self.ARGS = (TT.dot(self.ARG_DIFF, self.ARG_DIFF2I).T +
#                      self.arg_diff_bias).flatten()
#         # define final units
#         self.I = TT.concatenate((self.ARGS, self.EMB_CONN))
#         self.I2Y = theano.shared(value=HE_UNIFORM((self.n_y,
#                                                    self.ndim + self.intm_dim)),
#                                  name="I2Y")
#         self.y_bias = theano.shared(value=HE_UNIFORM((1, self.n_y)),
#                                     name="y_bias")
#         self._params.extend([self.I2Y, self.y_bias])
#         self.Y_pred = TT.nnet.softmax(TT.dot(self.I2Y, self.I).T + self.y_bias)
#         # initialize cost and optimization functions
#         self.Y_gold = TT.vector(name="Y_gold")
#         self._cost = TT.sum((self.Y_pred - self.Y_gold) ** 2)
#         self._dev_cost = TT.sum((self.Y_pred - self.Y_gold) ** 2)
#         self._pred_class = TT.argmax(self.Y_pred)
#         grads = TT.grad(self._cost, wrt=self._params)
#         self._init_funcs(grads)


from dsenser.svd import SVDSenser
from dsenser.svd.svdbase import SVDBaseSenser
from mock import patch, MagicMock
from unittest import TestCase
import dsenser
#!/usr/bin/env python
# -*- coding: utf-8; mode: python; -*-

##################################################################
# Imports
from __future__ import absolute_import



##################################################################
# Constants


##################################################################
# Test Classes
class TestSVDSenser(TestCase):
    def test_init(self):
        with patch.object(dsenser.nnbase, "Word2Vec",
                          MagicMock(ndim=300)):
            svd = SVDSenser()
            assert isinstance(svd.explicit, SVDBaseSenser)

# Path: dsenser/svd/svd.py
# class SVDSenser(BaseSenser):
#     """Class using LSTM classification for disambiguating connectives.
# 
#     Attributes:
#       explicit (:class:`dsenser.svd.explicit.SVDExplicitSenser`):
#         classifier for implicit discourse relations
#       implicit (:class:`dsenser.svd.implicit.SVDExplicitSenser`):
#         classifier for explicit discourse relations
#       n_y (int): number of distinct classes
# 
#     """
# 
#     def __init__(self, *args, **kwargs):
#         """
#         Class constructor.
# 
#         Args:
#           args (list): list of arguments
#           kwargs (dict): dictionary of keyword arguments
# 
#         """
#         self.explicit = SVDExplicitSenser(*args, **kwargs)
#         self.implicit = SVDImplicitSenser(*args, **kwargs)
#         self.n_y = -1
# 
# Path: dsenser/svd/svdbase.py
# class SVDBaseSenser(NNBaseSenser):
#     """Abstract class for disambiguating relation senses.
# 
#     Attributes:
#       n_y (int): number of distinct classes
# 
#     """
# 
#     def _init_nn(self):
#         """Initialize neural network.
# 
#         """
#         self.intm_dim = max(MIN_DIM, self.ndim - (self.ndim - self.n_y) / 2)
#         # indices of word embeddings
#         self.W_INDICES_ARG1 = TT.ivector(name="W_INDICES_ARG1")
#         self.W_INDICES_ARG2 = TT.ivector(name="W_INDICES_ARG2")
#         # connective's index
#         self.CONN_INDEX = TT.iscalar(name="CONN_INDEX")
#         # initialize the matrix of word embeddings
#         self.init_w_emb()
#         # word embeddings of the arguments
#         self.EMB_ARG1 = self.W_EMB[self.W_INDICES_ARG1]
#         self.EMB_ARG2 = self.W_EMB[self.W_INDICES_ARG2]
#         # connective's embedding
#         self._init_conn_emb()
#         self.EMB_CONN = self.CONN_EMB[self.CONN_INDEX]
#         # perform matrix decomposition
#         _, _, self.ARG1 = TT.nlinalg.svd(self.EMB_ARG1,
#                                          full_matrices=True)
#         _, _, self.ARG2 = TT.nlinalg.svd(self.EMB_ARG2,
#                                          full_matrices=True)
#         self.ARG_DIFF = self.ARG1 - self.ARG2
#         # map decomposed matrices to the intermediate level
#         self.ARG_DIFF2I = theano.shared(value=HE_UNIFORM((self.ndim, 1)),
#                                         name="ARG_DIFF2I")
#         self.arg_diff_bias = theano.shared(value=HE_UNIFORM((1, self.ndim)),
#                                            name="arg_diff_bias")
#         self._params.extend([self.ARG_DIFF2I, self.arg_diff_bias])
#         self.ARGS = (TT.dot(self.ARG_DIFF, self.ARG_DIFF2I).T +
#                      self.arg_diff_bias).flatten()
#         # define final units
#         self.I = TT.concatenate((self.ARGS, self.EMB_CONN))
#         self.I2Y = theano.shared(value=HE_UNIFORM((self.n_y,
#                                                    self.ndim + self.intm_dim)),
#                                  name="I2Y")
#         self.y_bias = theano.shared(value=HE_UNIFORM((1, self.n_y)),
#                                     name="y_bias")
#         self._params.extend([self.I2Y, self.y_bias])
#         self.Y_pred = TT.nnet.softmax(TT.dot(self.I2Y, self.I).T + self.y_bias)
#         # initialize cost and optimization functions
#         self.Y_gold = TT.vector(name="Y_gold")
#         self._cost = TT.sum((self.Y_pred - self.Y_gold) ** 2)
#         self._dev_cost = TT.sum((self.Y_pred - self.Y_gold) ** 2)
#         self._pred_class = TT.argmax(self.Y_pred)
#         grads = TT.grad(self._cost, wrt=self._params)
#         self._init_funcs(grads)


# Path: tests/svd/test_svd.py
from dsenser.svd import SVDSenser
from dsenser.svd.svdbase import SVDBaseSenser
from mock import patch, MagicMock
from unittest import TestCase
import dsenser

#!/usr/bin/env python
# -*- coding: utf-8; mode: python; -*-

##################################################################
# Imports
from __future__ import absolute_import



##################################################################
# Constants


##################################################################
# Test Classes
class TestSVDSenser(TestCase):
    def test_init(self):
        with patch.object(dsenser.nnbase, "Word2Vec",
                          MagicMock(ndim=300)):
            svd = SVDSenser()
            assert isinstance(svd.explicit, SVDBaseSenser)

            assert isinstance(svd.implicit, SVDBaseSenser)