TextFormatVectorizerUtils { public static Map<String, float[]> readEmbeddingFileTxt(File file, boolean hasHeader) throws IOException { LOG.info("Reading embeddings from file " + file); InputStream is = CompressionUtils .getInputStream(file.getAbsolutePath(), new FileInputStream(file)); return readEmbeddingFileTxt(is, hasHeader); }  static Map<String, float[]> readEmbeddingFileTxt(File file, boolean hasHeader); static Map<String, float[]> readEmbeddingFileTxt(InputStream inputStream,
            boolean hasHeader); static void convertMalletEmbeddingsToBinary(File malletEmbeddings, File targetFile); static void convertMalletEmbeddingsToBinary(File malletEmbeddings, boolean aCaseless,
            Locale aLocale, File targetFile);  }
@Test public void testReadEmbeddingFileTxt() throws IOException, URISyntaxException { File modelFile = new File("src/test/resources/dummy.vec"); int expectedSize = 699; int expectedDimensions = 50; boolean hasHeader = false; Map<String, float[]> embeddings = TextFormatVectorizerUtils .readEmbeddingFileTxt(modelFile, hasHeader); assertEquals(expectedSize, embeddings.size()); embeddings.values().forEach(vector -> assertEquals(expectedDimensions, vector.length)); }
@Test public void testReadEmbeddingFileTxtWithHeader() throws IOException, URISyntaxException { File modelFile = new File("src/test/resources/dummy_with_header.vec"); int expectedSize = 699; int expectedDimensions = 50; boolean hasHeader = true; Map<String, float[]> embeddings = TextFormatVectorizerUtils .readEmbeddingFileTxt(modelFile, hasHeader); assertEquals(expectedSize, embeddings.size()); embeddings.values().forEach(vector -> assertEquals(expectedDimensions, vector.length)); }
@Test public void testReadEmbeddingFileTxtCompressed() throws IOException, URISyntaxException { File modelFile = new File("src/test/resources/embeddings.gz"); int expectedSize = 699; int expectedDimensions = 50; boolean hasHeader = false; Map<String, float[]> embeddings = TextFormatVectorizerUtils .readEmbeddingFileTxt(modelFile, hasHeader); assertEquals(expectedSize, embeddings.size()); embeddings.values().forEach(vector -> assertEquals(expectedDimensions, vector.length)); }