diff --git a/test/contextual-vectors-specs.js b/test/contextual-vectors-specs.js index cacd732..1581ba3 100644 --- a/test/contextual-vectors-specs.js +++ b/test/contextual-vectors-specs.js @@ -60,6 +60,16 @@ describe( 'contextual vectors', function () { const json2a = '{"precision":8,"l2NormIndex":100,"wordIndex":101,"dimensions":100,"unkVector":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1],"size":7,"words":["the",",",".","one","lastly","itzz","ItZZ"],"vectors":{"itzz":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5],"the":[-0.038194,-0.24487,0.72812,-0.39961,0.083172,0.043953,-0.39141,0.3344,-0.57545,0.087459,0.28787,-0.06731,0.30906,-0.26384,-0.13231,-0.20757,0.33395,-0.33848,-0.31743,-0.48336,0.1464,-0.37304,0.34577,0.052041,0.44946,-0.46971,0.02628,-0.54155,-0.15518,-0.14107,-0.039722,0.28277,0.14393,0.23464,-0.31021,0.086173,0.20397,0.52624,0.17164,-0.082378,-0.71787,-0.41531,0.20335,-0.12763,0.41367,0.55187,0.57908,-0.33477,-0.36559,-0.54857,-0.062892,0.26584,0.30205,0.99775,-0.80481,-3.0243,0.01254,-0.36942,2.2167,0.72201,-0.24978,0.92136,0.034514,0.46745,1.1079,-0.19358,-0.074575,0.23353,-0.052062,-0.22044,0.057162,-0.15806,-0.30798,-0.41625,0.37972,0.15006,-0.53212,-0.2055,-1.2526,0.071624,0.70565,0.49744,-0.42063,0.26148,-1.538,-0.30223,-0.073438,-0.28312,0.37104,-0.25217,0.016215,-0.017099,-0.38984,0.87424,-0.72569,-0.51058,-0.52028,-0.1459,0.8278,0.27062,5.821154,0],"ItZZ":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6],"lastly":[-0.31914,0.14873,0.058321,0.069012,-0.03982,0.16459,-0.14299,0.20658,0.59777,0.06121,0.18177,-0.22946,0.080205,-0.081114,0.48642,-0.37647,-0.12512,0.27307,-0.30226,0.090638,-0.37042,-0.26611,0.077783,0.1546,0.082182,0.19086,0.0056976,-0.17299,0.17975,-0.32015,-0.21278,0.31478,-0.19037,-0.11547,-0.082077,0.30275,0.0058198,0.042987,0.025284,-0.4098,0.21951,0.20954,-0.10778,-0.088181,-0.256,-0.092912,0.34733,-0.21431,-0.30153,0.028669,-0.20696,0.093091,-0.12626,0.27863,-0.24892,0.10383,0.24438,-0.42254,-0.43662,0.089009,-0.46733,0.26044,-0.022262,0.1317,0.50867,-0.16419,-0.15378,-0.08092,0.58693,-0.02218,0.053947,-0.014776,0.43776,0.0026166,-0.010212,-0.00869,0.00027581,-0.14649,0.069146,-0.38431,-0.21902,-0.090417,-0.24623,0.3754,-0.22321,-0.089054,0.033319,-0.32897,-0.062051,-0.12475,-0.25357,-0.44094,0.036394,0.27727,0.066178,0.026955,0.012135,0.019036,-0.18568,0.15744,2.33216406,4],"one":[-0.22557,0.49418,0.4861,-0.4332,0.13738,0.50617,0.26058,0.30103,-0.091486,0.10876,0.3058,0.051028,0.22303,0.054236,0.068838,-0.24701,0.32689,-0.082203,-0.28866,0.3734,0.73804,-0.040969,0.040201,0.11384,0.69987,-0.49745,-0.06755,-0.42599,-0.10725,-0.010697,-0.01479,0.55976,0.3064,0.053053,0.058034,0.32756,-0.37233,0.46513,0.14285,-0.085003,-0.45476,0.19773,0.6383,-0.31148,0.10858,0.31557,0.36682,-0.35135,-0.48414,-0.33235,-0.33816,-0.39678,0.1908,1.3513,-0.39044,-2.8795,-0.14276,-0.087754,1.7713,0.99332,-0.14129,0.94389,0.050897,0.47373,0.86387,-0.16162,0.67199,0.52344,0.14438,-0.055194,-0.34669,-0.20742,0.18907,-0.19845,0.34862,0.10121,-0.092119,-0.66258,-1.0582,-0.11803,0.70171,0.077776,-0.50546,0.032243,-1.6176,-0.29302,-0.061748,-0.32473,0.3439,-0.44698,0.085689,0.13295,-0.1807,-0.11854,-0.82985,0.13784,-0.34359,-0.45744,0.49646,0.34906,5.50354886,3],",":[-0.10767,0.11053,0.59812,-0.54361,0.67396,0.10663,0.038867,0.35481,0.06351,-0.094189,0.15786,-0.81665,0.14172,0.21939,0.58505,-0.52158,0.22783,-0.16642,-0.68228,0.3587,0.42568,0.19021,0.91963,0.57555,0.46185,0.42363,-0.095399,-0.42749,-0.16567,-0.056842,-0.29595,0.26037,-0.26606,-0.070404,-0.27662,0.15821,0.69825,0.43081,0.27952,-0.45437,-0.33801,-0.58184,0.22364,-0.5778,-0.26862,-0.20425,0.56394,-0.58524,-0.14365,-0.64218,0.0054697,-0.35248,0.16162,1.1796,-0.47674,-2.7553,-0.1321,-0.047729,1.0655,1.1034,-0.2208,0.18669,0.13177,0.15117,0.7131,-0.35215,0.91348,0.61783,0.70992,0.23955,-0.14571,-0.37859,-0.045959,-0.47368,0.2385,0.20536,-0.18996,0.32507,-1.1112,-0.36341,0.98679,-0.084776,-0.54008,0.11726,-1.0194,-0.24424,0.12771,0.013884,0.080374,-0.35414,0.34951,-0.7226,0.37549,0.4441,-0.99059,0.61214,-0.35111,-0.83155,0.45293,0.082577,5.553375,1],".":[-0.33979,0.20941,0.46348,-0.64792,-0.38377,0.038034,0.17127,0.15978,0.46619,-0.019169,0.41479,-0.34349,0.26872,0.04464,0.42131,-0.41032,0.15459,0.022239,-0.64653,0.25256,0.043136,-0.19445,0.46516,0.45651,0.68588,0.091295,0.21875,-0.70351,0.16785,-0.35079,-0.12634,0.66384,-0.2582,0.036542,-0.13605,0.40253,0.14289,0.38132,-0.12283,-0.45886,-0.25282,-0.30432,-0.11215,-0.26182,-0.22482,-0.44554,0.2991,-0.85612,-0.14503,-0.49086,0.0082973,-0.17491,0.27524,1.4401,-0.21239,-2.8435,-0.27958,-0.45722,1.6386,0.78808,-0.55262,0.65,0.086426,0.39012,1.0632,-0.35379,0.48328,0.346,0.84174,0.098707,-0.24213,-0.27053,0.045287,-0.40147,0.11395,0.0062226,0.036673,0.018518,-1.0213,-0.20806,0.64072,-0.068763,-0.58635,0.33476,-1.1432,-0.1148,-0.25091,-0.45907,-0.096819,-0.17946,-0.063351,-0.67412,-0.068895,0.53604,-0.87773,0.31802,-0.39242,-0.23394,0.47298,-0.028803,5.4601503,2]}}'; const json2b = '{"precision":8,"l2NormIndex":100,"wordIndex":101,"dimensions":100,"unkVector":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1],"size":7,"words":["the",",",".","of","to","itzz","ItZZ"],"vectors":{"itzz":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5],"the":[-0.038194,-0.24487,0.72812,-0.39961,0.083172,0.043953,-0.39141,0.3344,-0.57545,0.087459,0.28787,-0.06731,0.30906,-0.26384,-0.13231,-0.20757,0.33395,-0.33848,-0.31743,-0.48336,0.1464,-0.37304,0.34577,0.052041,0.44946,-0.46971,0.02628,-0.54155,-0.15518,-0.14107,-0.039722,0.28277,0.14393,0.23464,-0.31021,0.086173,0.20397,0.52624,0.17164,-0.082378,-0.71787,-0.41531,0.20335,-0.12763,0.41367,0.55187,0.57908,-0.33477,-0.36559,-0.54857,-0.062892,0.26584,0.30205,0.99775,-0.80481,-3.0243,0.01254,-0.36942,2.2167,0.72201,-0.24978,0.92136,0.034514,0.46745,1.1079,-0.19358,-0.074575,0.23353,-0.052062,-0.22044,0.057162,-0.15806,-0.30798,-0.41625,0.37972,0.15006,-0.53212,-0.2055,-1.2526,0.071624,0.70565,0.49744,-0.42063,0.26148,-1.538,-0.30223,-0.073438,-0.28312,0.37104,-0.25217,0.016215,-0.017099,-0.38984,0.87424,-0.72569,-0.51058,-0.52028,-0.1459,0.8278,0.27062,5.821154,0],"ItZZ":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6],",":[-0.10767,0.11053,0.59812,-0.54361,0.67396,0.10663,0.038867,0.35481,0.06351,-0.094189,0.15786,-0.81665,0.14172,0.21939,0.58505,-0.52158,0.22783,-0.16642,-0.68228,0.3587,0.42568,0.19021,0.91963,0.57555,0.46185,0.42363,-0.095399,-0.42749,-0.16567,-0.056842,-0.29595,0.26037,-0.26606,-0.070404,-0.27662,0.15821,0.69825,0.43081,0.27952,-0.45437,-0.33801,-0.58184,0.22364,-0.5778,-0.26862,-0.20425,0.56394,-0.58524,-0.14365,-0.64218,0.0054697,-0.35248,0.16162,1.1796,-0.47674,-2.7553,-0.1321,-0.047729,1.0655,1.1034,-0.2208,0.18669,0.13177,0.15117,0.7131,-0.35215,0.91348,0.61783,0.70992,0.23955,-0.14571,-0.37859,-0.045959,-0.47368,0.2385,0.20536,-0.18996,0.32507,-1.1112,-0.36341,0.98679,-0.084776,-0.54008,0.11726,-1.0194,-0.24424,0.12771,0.013884,0.080374,-0.35414,0.34951,-0.7226,0.37549,0.4441,-0.99059,0.61214,-0.35111,-0.83155,0.45293,0.082577,5.553375,1],".":[-0.33979,0.20941,0.46348,-0.64792,-0.38377,0.038034,0.17127,0.15978,0.46619,-0.019169,0.41479,-0.34349,0.26872,0.04464,0.42131,-0.41032,0.15459,0.022239,-0.64653,0.25256,0.043136,-0.19445,0.46516,0.45651,0.68588,0.091295,0.21875,-0.70351,0.16785,-0.35079,-0.12634,0.66384,-0.2582,0.036542,-0.13605,0.40253,0.14289,0.38132,-0.12283,-0.45886,-0.25282,-0.30432,-0.11215,-0.26182,-0.22482,-0.44554,0.2991,-0.85612,-0.14503,-0.49086,0.0082973,-0.17491,0.27524,1.4401,-0.21239,-2.8435,-0.27958,-0.45722,1.6386,0.78808,-0.55262,0.65,0.086426,0.39012,1.0632,-0.35379,0.48328,0.346,0.84174,0.098707,-0.24213,-0.27053,0.045287,-0.40147,0.11395,0.0062226,0.036673,0.018518,-1.0213,-0.20806,0.64072,-0.068763,-0.58635,0.33476,-1.1432,-0.1148,-0.25091,-0.45907,-0.096819,-0.17946,-0.063351,-0.67412,-0.068895,0.53604,-0.87773,0.31802,-0.39242,-0.23394,0.47298,-0.028803,5.4601503,2],"of":[-0.1529,-0.24279,0.89837,0.16996,0.53516,0.48784,-0.58826,-0.17982,-1.3581,0.42541,0.15377,0.24215,0.13474,0.41193,0.67043,-0.56418,0.42985,-0.012183,-0.11677,0.31781,0.054177,-0.054273,0.35516,-0.30241,0.31434,-0.33846,0.71715,-0.26855,-0.15837,-0.47467,0.051581,-0.33252,0.15003,-0.1299,-0.54617,-0.37843,0.64261,0.82187,-0.080006,0.078479,-0.96976,-0.57741,0.56491,-0.39873,-0.057099,0.19743,0.065706,-0.48092,-0.20125,-0.40834,0.39456,-0.02642,-0.11838,1.012,-0.53171,-2.7474,-0.042981,-0.74849,1.7574,0.59085,0.04885,0.78267,0.38497,0.42097,0.67882,0.10337,0.6328,-0.026595,0.58647,-0.44332,0.33057,-0.12022,-0.55645,0.073611,0.20915,0.43395,-0.012761,0.089874,-1.7991,0.084808,0.77112,0.63105,-0.90685,0.60326,-1.7515,0.18596,-0.50687,-0.70203,0.66578,-0.81304,0.18712,-0.018488,-0.26757,0.727,-0.59363,-0.34839,-0.56094,-0.591,1.0039,0.20664,6.2968688,3],"to":[-0.1897,0.050024,0.19084,-0.049184,-0.089737,0.21006,-0.54952,0.098377,-0.20135,0.34241,-0.092677,0.161,-0.13268,-0.2816,0.18737,-0.42959,0.96039,0.13972,-1.0781,0.40518,0.50539,-0.55064,0.4844,0.38044,-0.0029055,-0.34942,-0.099696,-0.78368,1.0363,-0.2314,-0.47121,0.57126,-0.21454,0.35958,-0.48319,1.0875,0.28524,0.12447,-0.039248,-0.076732,-0.76343,-0.32409,-0.5749,-1.0893,-0.41811,0.4512,0.12112,-0.51367,-0.13349,-1.1378,-0.28768,0.16774,0.55804,1.5387,0.018859,-2.9721,-0.24216,-0.92495,2.1992,0.28234,-0.3478,0.51621,-0.43387,0.36852,0.74573,0.072102,0.27931,0.92569,-0.050336,-0.85856,-0.1358,-0.92551,-0.33991,-1.0394,-0.067203,-0.21379,-0.4769,0.21377,-0.84008,0.052536,0.59298,0.29604,-0.67644,0.13916,-1.5504,-0.20765,0.7222,0.52056,-0.076221,-0.15194,-0.13134,0.058617,-0.31869,-0.61419,-0.62393,-0.41548,-0.038175,-0.39804,0.47647,-0.15983,6.4506511,4]}}'; + it( 'vectors generated from this function should correcly load in winkNLP\'s new instance ', function () { + const jsonFromCV = doc1.contextualVectors(); + const obj = JSON.parse( jsonFromCV ); + expect( obj ).to.deep.equal( JSON.parse( jsonWithDefault ) ); + expect( obj.size ).equal( 3 ); + + const jsonAfterLoadingEarlierJSON = winkNLP( model, undefined, obj ).readDoc( text1 ).contextualVectors(); + expect( JSON.parse( jsonAfterLoadingEarlierJSON ) ).to.deep.equal( JSON.parse( jsonWithDefault ) ); + } ); + it( 'with default parameters, size should be 3 & json should be correct', function () { const json = doc1.contextualVectors(); const obj = JSON.parse( json );