Search in sources :

Example 6 with IcedLong

use of water.util.IcedLong in project h2o-3 by h2oai.

the class WordCountTaskTest method testWordCountText8.

@Test
public void testWordCountText8() {
    String fName = "bigdata/laptop/text8.gz";
    // only run if text8 is present
    assumeThat("text8 data available", locateFile(fName), is(notNullValue()));
    Frame fr = parse_test_file(fName, "NA", 0, new byte[] { Vec.T_STR });
    try {
        Map<BufferedString, IcedLong> counts = new WordCountTask().doAll(fr.vec(0))._counts;
        assertEquals(253854, counts.size());
        assertEquals(303L, counts.get(new BufferedString("anarchism"))._val);
        assertEquals(316376L, counts.get(new BufferedString("to"))._val);
        assertNotNull(counts);
    } finally {
        fr.remove();
    }
}
Also used : Frame(water.fvec.Frame) IcedLong(water.util.IcedLong) BufferedString(water.parser.BufferedString) BufferedString(water.parser.BufferedString) Test(org.junit.Test)

Example 7 with IcedLong

use of water.util.IcedLong in project h2o-3 by h2oai.

the class WordCountTaskTest method testWordCount.

@Test
public void testWordCount() {
    String[] strData = new String[10000];
    for (int i = 0; i < strData.length; i++) {
        int b = i % 10;
        if (b < 3)
            strData[i] = "A";
        else if (b < 5)
            strData[i] = "B";
        else
            strData[i] = "C";
    }
    Frame fr = new TestFrameBuilder().withName("data").withColNames("Str").withVecTypes(Vec.T_STR).withDataForCol(0, strData).withChunkLayout(100, 900, 5000, 4000).build();
    try {
        Map<BufferedString, IcedLong> counts = new WordCountTask().doAll(fr.vec(0))._counts;
        assertEquals(3, counts.size());
        assertEquals(3000L, counts.get(new BufferedString("A"))._val);
        assertEquals(2000L, counts.get(new BufferedString("B"))._val);
        assertEquals(5000L, counts.get(new BufferedString("C"))._val);
        System.out.println(counts);
    } finally {
        fr.remove();
    }
}
Also used : Frame(water.fvec.Frame) TestFrameBuilder(water.fvec.TestFrameBuilder) IcedLong(water.util.IcedLong) BufferedString(water.parser.BufferedString) BufferedString(water.parser.BufferedString) Test(org.junit.Test)

Example 8 with IcedLong

use of water.util.IcedLong in project h2o-3 by h2oai.

the class CreateInteractions method mySort.

private static Map<Long, Long> mySort(Map<IcedLong, IcedLong> unsortMap) {
    List<Map.Entry<IcedLong, IcedLong>> list = new LinkedList<>(unsortMap.entrySet());
    // Sorting the list based on values
    Collections.sort(list, new Comparator<Map.Entry<IcedLong, IcedLong>>() {

        public int compare(Map.Entry<IcedLong, IcedLong> o1, Map.Entry<IcedLong, IcedLong> o2) {
            return ((Long) o2.getValue()._val).compareTo(o1.getValue()._val);
        }
    });
    // Maintaining insertion order with the help of LinkedList
    Map sortedMap = new LinkedHashMap<>();
    for (Map.Entry<IcedLong, IcedLong> entry : list) {
        sortedMap.put(entry.getKey()._val, entry.getValue()._val);
    }
    return sortedMap;
}
Also used : IcedLong(water.util.IcedLong) IcedHashMap(water.util.IcedHashMap)

Aggregations

IcedLong (water.util.IcedLong)8 BufferedString (water.parser.BufferedString)5 Test (org.junit.Test)3 Frame (water.fvec.Frame)2 IcedHashMap (water.util.IcedHashMap)2 Map (java.util.Map)1 TestFrameBuilder (water.fvec.TestFrameBuilder)1 IcedDouble (water.util.IcedDouble)1 IcedHashMapGeneric (water.util.IcedHashMapGeneric)1