From e823fa9ca768f8b9b9d08fdc77213e4a48b7eff7 Mon Sep 17 00:00:00 2001 From: "nikit91@gmail.com" Date: Wed, 10 Oct 2018 12:55:55 +0200 Subject: [PATCH] testing with words --- .../NrmlzdThetaMdlPrfmncTester.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/aksw/word2vecrestful/NrmlzdThetaMdlPrfmncTester.java b/src/test/java/org/aksw/word2vecrestful/NrmlzdThetaMdlPrfmncTester.java index f6d4e32..270aa69 100644 --- a/src/test/java/org/aksw/word2vecrestful/NrmlzdThetaMdlPrfmncTester.java +++ b/src/test/java/org/aksw/word2vecrestful/NrmlzdThetaMdlPrfmncTester.java @@ -20,7 +20,13 @@ public class NrmlzdThetaMdlPrfmncTester { PropertyConfigurator.configure(Cfg.LOG_FILE); } public static Logger LOG = LogManager.getLogger(NrmlzdThetaMdlPrfmncTester.class); - + public static final float[][] TEST_CENTROIDS = { TestConst.CENT1, TestConst.CENT2, TestConst.CENT3, TestConst.CENT4, + TestConst.CENT5, TestConst.CENT6, TestConst.CENT7, TestConst.CENT8, TestConst.CENT9, TestConst.CENT10, + TestConst.CENT11, TestConst.CENT12, TestConst.CENT13, TestConst.CENT14, TestConst.CENT15, TestConst.CENT16, + TestConst.CENT17, TestConst.CENT18, TestConst.CENT19, TestConst.CENT20 }; + public static final String[] TEST_WORDS = { "cat", "dog", "airplane", "road", "kennedy", "rome", "human", "disney", + "machine", "intelligence", "palaeontology", "surgeon", "amazon", "jesus", "gold", "atlantis", "ronaldo", + "pele", "scissors", "lizard" }; /* * @Test public void testNbmTime() { long startTime, diff; long totTime = 0; * LOG.info("Starting InMemory Theta Model test!"); Word2VecModel nbm = @@ -56,10 +62,8 @@ public void testNbmTime() throws IOException { long totTime = 0; LOG.info("Starting InMemory Theta Model test!"); Word2VecModel nbm = Word2VecFactory.getNormalBinModel(); - float[][] centroids = { TestConst.CENT1, TestConst.CENT2, TestConst.CENT3, TestConst.CENT4, TestConst.CENT5, - TestConst.CENT6, TestConst.CENT7, TestConst.CENT8, TestConst.CENT9, TestConst.CENT10, TestConst.CENT11, - TestConst.CENT12, TestConst.CENT13, TestConst.CENT14, TestConst.CENT15, TestConst.CENT16, - TestConst.CENT17, TestConst.CENT18, TestConst.CENT19, TestConst.CENT20 }; + // float[][] centroids = TEST_CENTROIDS; + float[][] centroids = fetchWordsVec(TEST_WORDS, nbm); LOG.info("Starting BruteForce-Model Test"); List correctWords = NrmlzdMdlPrfmncTester.getCorrectWords(centroids, nbm); LOG.info("Correct Words are :" + correctWords); @@ -77,10 +81,19 @@ public void testNbmTime() throws IOException { totTime += diff; LOG.info("Query time recorded for Centroid " + (i + 1) + " is " + diff + " milliseconds."); } - LOG.info("Average query time for W2VNrmlMemModelBinSrch is : " + (totTime / centroids.length) + " milliseconds"); + LOG.info( + "Average query time for W2VNrmlMemModelBinSrch is : " + (totTime / centroids.length) + " milliseconds"); LOG.info("Predicted Words are :" + lrModelWords); float percVal = NrmlzdMdlPrfmncTester.calcPercScore(correctWords, lrModelWords); LOG.info("Score for Test is : " + percVal + "%"); lrModelWords.clear(); } + + private static float[][] fetchWordsVec(String[] words, Word2VecModel nbm) { + float[][] resVec = new float[words.length][300]; + for (int i = 0; i < words.length; i++) { + resVec[i] = nbm.word2vec.get(words[i]); + } + return resVec; + } }