home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (FileLabelAwareIteratorTest.java)

This example Java source code file (FileLabelAwareIteratorTest.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

before, classpathresource, exception, filelabelawareiterator, filelabelawareiteratortest, labelleddocument, test

The FileLabelAwareIteratorTest.java Java example source code

package org.deeplearning4j.text.documentiterator;

import org.canova.api.util.ClassPathResource;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;

/**
 * Created by raver119 on 03.01.16.
 */
public class FileLabelAwareIteratorTest {


    @Before
    public void setUp() throws Exception {

    }

    @Test
    public void testExtractLabelFromPath1() throws Exception {
        ClassPathResource resource = new ClassPathResource("/labeled");

        FileLabelAwareIterator iterator = new FileLabelAwareIterator.Builder()
                .addSourceFolder(resource.getFile())
                .build();

        int cnt = 0;
        while (iterator.hasNextDocument()) {
            LabelledDocument document = iterator.nextDocument();
            assertNotEquals(null, document);
            assertNotEquals(null, document.getContent());
            assertNotEquals(null, document.getLabel());
            cnt++;
        }

        assertEquals(3, cnt);


        assertEquals(3, iterator.getLabelsSource().getNumberOfLabelsUsed());

        assertTrue(iterator.getLabelsSource().getLabels().contains("positive"));
        assertTrue(iterator.getLabelsSource().getLabels().contains("negative"));
        assertTrue(iterator.getLabelsSource().getLabels().contains("neutral"));
    }


    @Test
    public void testExtractLabelFromPath2() throws Exception {
        ClassPathResource resource = new ClassPathResource("/labeled");
        ClassPathResource resource2= new ClassPathResource("/rootdir");

        FileLabelAwareIterator iterator = new FileLabelAwareIterator.Builder()
                .addSourceFolder(resource.getFile())
                .addSourceFolder(resource2.getFile())
                .build();

        int cnt = 0;
        while (iterator.hasNextDocument()) {
            LabelledDocument document = iterator.nextDocument();
            assertNotEquals(null, document);
            assertNotEquals(null, document.getContent());
            assertNotEquals(null, document.getLabel());
            cnt++;
        }

        assertEquals(5, cnt);


        assertEquals(5, iterator.getLabelsSource().getNumberOfLabelsUsed());

        assertTrue(iterator.getLabelsSource().getLabels().contains("positive"));
        assertTrue(iterator.getLabelsSource().getLabels().contains("negative"));
        assertTrue(iterator.getLabelsSource().getLabels().contains("neutral"));
        assertTrue(iterator.getLabelsSource().getLabels().contains("label1"));
        assertTrue(iterator.getLabelsSource().getLabels().contains("label2"));
    }
}

Other Java examples (source code examples)

Here is a short list of links related to this Java FileLabelAwareIteratorTest.java source code file:



my book on functional programming

 

new blog posts

 

Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.