# pylint: disable=no-self-use,invalid-name

import numpy as np

from allennlp.common.testing import AllenNlpTestCase
from allennlp.common.util import ensure_list

from classifiers.dataset_readers import WordVectorDatasetReader


class TestDatasetReader(AllenNlpTestCase):

    def test_read_from_file(self):
        reader = WordVectorDatasetReader()
        instances = ensure_list(reader.read('/Users/claravania/Documents/project/subwordeval/dataset/test_data'))

        embedding1 = np.array(
            [0.038285240531, -0.142458200455, 0.023042364046, -0.0232889614999, 0.0291798170656, 0.177426487207,
             0.0011190896621, 0.148406639695, -0.314995259047, -0.0548755861819, -0.0655175149441, 0.0112710446119,
             0.098191216588, 0.349393635988, -0.0127612277865, -0.117935247719, -0.043617784977, 0.0416336432099,
             -0.0955908372998, 0.0160503033549, 0.0823771506548, 0.202426254749, -0.133416995406, -0.000387724605389,
             0.238621070981, -0.259547770023, 0.0763178244233, -0.15162666142, 0.0210201162845, 0.00731925014406,
             0.0850933566689, 0.0181059129536, -0.015884321183, 0.647453904152, -0.400311768055, 0.197876259685,
             -0.0132941678166, -0.190755322576, 0.0039595682174, -0.106700003147, -0.0163167715073, -0.00578643474728,
             -0.00535708991811, -0.0313748382032, -0.1666482687, -0.168328642845, 0.012437758036, -0.071413308382,
             -0.00545749114826, -0.188859716058, 0.238764598966, 0.0553113222122, -0.00422523869202, -0.212509825826,
             0.0506122745574, -0.277833759785, -0.0400135144591, -0.575879752636, 0.134799405932, -0.0484699830413,
             -0.118156254292, -0.0220698248595, 0.00278095155954, -0.202642008662, 0.146434992552, 0.179117590189,
             -0.0213271304965, 0.0423932336271, -0.214381322265, 0.301037669182, 0.00289777340367, 0.0236865524203,
             0.190468221903, 0.0282144993544, 0.00176326441579, 0.00867959205061, -0.0389777012169, 0.332108646631,
             0.463738411665, 0.27818068862, 0.0887532606721, -0.0282106436789, 0.421519875526, 0.353071957827,
             -0.0120432721451, -0.00192482990678, -0.00941472314298, -0.0557900778949, 0.0760995596647, -0.019597325474,
             0.00381170446053, 0.0456312261522, 0.0223854985088, 0.0765709131956, -0.0406940281391, -0.0356641635299,
             0.0195479709655, 0.0858363881707, -0.0552276596427, 0.0661923959851, 0.00533084198833, 0.00358504522592,
             0.014324455522, -0.0234944652766, 0.196569353342, 0.0344110392034, 0.129467919469, -0.0774961933494,
             0.3776037395, 0.279495596886, 0.69577896595, 0.503871977329, -0.188576504588, -0.0724921897054,
             -0.0925940200686, -0.00204938836396, -0.000906226632651, -0.0172906275839, 0.0448079518974,
             0.0769151896238, 0.142069548368, -0.145108968019, -0.185883998871, 0.195960924029, -0.0120510552078,
             0.0333361327648, -0.267295449972, 0.0105544682592, -0.0154021382332, -0.0476268492639, -0.0704609677196,
             -0.0107039250433, 0.506041705608, -0.039399150759, 0.139287546277, -0.00765452347696, -0.213545665145,
             0.00646166596562, 0.00274491496384, 0.139693498611, 0.45852380991, 0.0360598862171, -0.258264392614,
             -0.18438321352, 0.0406838767231, 0.109418436885, -0.147262170911, -0.105576679111, 0.000308029644657,
             0.496560424566, 0.00280835805461, 0.695666611195, -0.560440838337, 0.549584269524, -0.132525786757,
             0.0153756178916, 0.000421107804868, 0.0570801720023, -0.0771156102419, 0.0105002485216, 3.10533978336e-05,
             -0.00433479016647, -0.00385649898089, 0.0286928862333, -0.0091460403055, -0.885007321835, 0.0280595831573,
             -0.0255169402808, 0.125107109547, -0.127376511693, 0.0245555024594, 0.00443543260917, 0.348387956619,
             0.00155181868467, 0.00148439162876, 0.0918176621199, 0.073775947094, -0.317379623652, 0.10932186991,
             -0.00877366960049, -0.0644190758467, -0.562983810902, -0.00064700411167, -0.00112291774713,
             -0.232532203197, -0.668997347355, 0.107446782291, -0.0145578598604, 0.111676409841, -0.0453936606646,
             0.218361288309, 0.0301664732397, 0.00971835106611, 0.033622097224, 0.0753599181771, 0.0297489948571,
             -0.205077379942, 0.331324964762, 0.325598120689, 0.11348824203, -0.000746133155189, -0.0640609487891,
             0.153452321887, -0.00173819530755, 0.119318597019, -0.274150729179, -0.0352536402643, -0.433538466692,
             -0.00132403173484, -0.110821947455, 0.0315447077155, 0.0597917847335, -0.0527766980231, -0.370681643486,
             0.109297312796, 0.113064810634, 0.000355507421773, 0.125633627176, -0.0223868377507, -0.00835651624948,
             0.846208393574, 0.00114641839173, -0.00681167654693, -0.0366320759058, 0.0190202109516, -0.513547480106,
             0.255973547697, 0.00283685186878, -0.264026284218, 0.159413322806, 0.0330330505967, -0.00978938117623,
             0.113281361759, -0.247498363256, 0.00148333481047, 0.00306136510335, 0.0140367485583, 0.0174542237073,
             -0.072840847075, -0.0414967909455, 0.0687447935343, -0.181334763765, 0.0198378525674, 0.0202576033771,
             0.057719245553, 0.298087477684, 0.00022488180548, 0.812824308872, 0.315741449594, -0.110861323774])

        embedding2 = np.array(
            [-0.00195298076142, 0.267228603363, 0.0329353585839, -0.291632264853, -0.147681042552, 0.421947568655,
             -0.00183792528696, -0.346264392138, 0.346155166626, 0.0243926290423, 0.0557523854077, 0.146574854851,
             -0.555029273033, 0.0658875778317, -0.0514862202108, -0.125339835882, -0.339534431696, -0.350073009729,
             -0.223752334714, 0.503056585789, 0.0119535783306, 0.596675693989, -0.169017449021, -0.00126389611978,
             0.294094204903, -0.0683524161577, 0.0262032430619, -0.0516117997468, -0.0119964731857, 0.0277850963175,
             0.0823462232947, 0.17264059186, -0.0551739819348, 0.912860572338, -0.611767590046, -0.0134632633999,
             0.182350292802, -0.0926892608404, 0.0276615414768, 0.00412745820358, 0.366482287645, -0.049621950835,
             -0.106750197709, -0.00979777052999, 0.0279042236507, -0.0699052810669, 0.557047963142, -0.11383985728,
             -0.00237923348323, 0.708197772503, -0.0886335372925, 0.0756172090769, -0.00812592636794, -0.151411175728,
             0.123660072684, -0.227064996958, -0.00975628290325, -0.0182457249612, 0.262197166681, -0.079926662147,
             0.128588289022, -0.0133580463007, 0.00248380866833, -0.329646974802, -0.032416049391, 0.208042174578,
             -0.0309939235449, 0.0226393006742, 0.0723651945591, 0.374619454145, 0.00521122617647, 0.0179987885058,
             0.225631937385, 0.0347581990063, 0.00928442087024, -0.017403492704, -0.0264546517283, 0.500661671162,
             0.479670792818, -0.0367298573256, -0.128663673997, 0.00293981516734, 0.0513413511217, 0.669508218765,
             -0.0572288632393, 0.000853251258377, -0.0196080189198, -0.105899527669, 0.0982661470771, -0.223385170102,
             -0.0115348016843, 0.207029312849, -0.0484630092978, 0.141839265823, -0.0155104408041, -0.579707860947,
             -0.00160453398712, 0.00410840660334, 0.451751589775, -0.192297652364, 0.542487621307, -0.0153704546392,
             0.0875394493341, 0.0190527271479, 0.213660418987, 0.00471948320046, 0.340456902981, -0.437233328819,
             0.121420241892, 0.219415828586, -0.0266935545951, 0.109474897385, -0.259265005589, -0.026895320043,
             0.00667011272162, 0.0724212676287, 0.0119383577257, -0.000355357129592, 0.529302120209, 0.062242500484,
             0.176528856158, -0.747560441494, -0.229403749108, 0.588028371334, -0.00992595031857, 0.0576401688159,
             -0.41273239255, 0.194457620382, -0.0213177073747, -0.00495409779251, -0.000612475036178, -0.00801828410476,
             0.28924459219, -0.00641712220386, 0.193933591247, -0.0104533582926, -0.454423338175, -0.0308107752353,
             -0.00024470264907, 0.210474401712, 0.334615319967, -0.0297358334064, -0.250918656588, -0.0588837042451,
             -0.00295730633661, 0.066340751946, 0.258175373077, 0.0588127560914, -0.0014633674873, 0.145845726132,
             0.00236973259598, 0.133327871561, 0.00407991139218, 0.0203059352934, -0.0228335317224, 0.0488637760282,
             0.00700087100267, 0.00627645710483, -0.0659555718303, 0.0194790977985, 0.000590125157032,
             -0.00383089180104, 7.92155406089e-05, 0.0505033954978, -0.0430446863174, -0.281189799309, 0.023077044636,
             0.000604434520938, -0.00196355464868, 0.153451859951, 0.141523808241, 0.000171429972397, 0.256645590067,
             -7.5450494478e-05, -0.00539320195094, 0.0771070197225, 0.181752696633, 0.0752027705312, 0.023418109864,
             -0.00125948304776, -0.0504026077688, -0.0159585941583, -0.0217128638178, -0.0761014297605, -0.8254109025,
             -0.10993655771, -0.0695543512702, 0.0400328338146, -0.294453948736, 0.00056880840566, 0.317432671785,
             0.277691721916, -0.000127813298604, -0.0893524289131, 0.0258553624153, 0.00745483813807, 0.0175764169544,
             0.425070822239, 0.00229570106603, 0.257463872433, -0.00821263436228, -0.261177778244, -0.0265448726714,
             -0.145599246025, 0.0655639842153, -0.00248255440965, -0.034676309675, -0.00599922053516, -0.016951084137,
             -0.30042001605, 0.0279399566352, -0.188746228814, -0.0241331513971, -0.0208239536732, 0.0117377173156,
             -0.00219343579374, -0.000184224132681, 0.000618271762505, -0.48254737258, -0.0273129940033, 0.469492316246,
             0.000469418097055, -0.0325634777546, 0.070454634726, 0.330149590969, -0.217116013169, -0.0220340434462,
             0.21529263258, -0.219546243548, 0.0661436840892, 0.551860809326, 0.0142479389906, 0.0449351817369,
             -0.0987800881267, 6.17096593487e-05, 0.00379198556766, 0.00638306466863, 0.0106460014358, 0.00654794601724,
             0.615790963173, 0.0915045961738, -0.183501824737, 0.0325885638595, 0.211281254888, 0.0194542892277,
             0.256556600332, 0.00135316082742, 0.474624305964, 0.267278343439, -0.482668757439])

        instance1 = {"embedding": embedding1,
                     "label": 'NUM'}

        instance2 = {"embedding": embedding2,
                     "label": 'ADJ'}

        assert len(instances) == 5
        fields = instances[0].fields
        assert fields["label"].label == instance1["label"]
        fields = instances[1].fields
        assert fields["label"].label == instance2["label"]
