Package edu.umd.cloud9.io.map

Examples of edu.umd.cloud9.io.map.Int2IntOpenHashMapWritable


  public void testUpdate() {
    int size = 100000;
    Random r = new Random();
    int[] ints = new int[size];

    Int2IntMap map = new Int2IntOpenHashMapWritable();
    for (int i = 0; i < size; i++) {
      int k = r.nextInt(size);
      map.put(i, k);
      ints[i] = k;
    }

    assertEquals(size, map.size());

    for (int i = 0; i < size; i++) {
      map.put(i, ints[i] + 1);
    }

    assertEquals(size, map.size());

    for (int i = 0; i < size; i++) {
      assertEquals(ints[i] + 1, map.get(i));
      assertTrue(map.containsKey(i));
    }
  }
View Full Code Here


    }
  }

  @Test
  public void testPlus() throws IOException {
    Int2IntOpenHashMapWritable m1 = new Int2IntOpenHashMapWritable();

    m1.put(1, 5);
    m1.put(2, 22);

    Int2IntOpenHashMapWritable m2 = new Int2IntOpenHashMapWritable();

    m2.put(1, 4);
    m2.put(3, 5);

    m1.plus(m2);

    assertEquals(3, m1.size());
    assertEquals(9, m1.get(1));
View Full Code Here

    assertEquals(5, m1.get(3));
  }

  @Test
  public void testLazyPlus() throws IOException {
    Int2IntOpenHashMapWritable m1 = new Int2IntOpenHashMapWritable();

    m1.put(1, 5);
    m1.put(2, 22);

    Int2IntOpenHashMapWritable m2 = new Int2IntOpenHashMapWritable();

    m2.put(1, 4);
    m2.put(3, 5);

    Int2IntOpenHashMapWritable.setLazyDecodeFlag(true);
    Int2IntOpenHashMapWritable m3 = Int2IntOpenHashMapWritable.create(m2.serialize());

    assertEquals(0, m3.size());

    m1.lazyplus(m3);

    assertEquals(3, m1.size());
    assertEquals(9, m1.get(1));
View Full Code Here

    assertEquals(5, m1.get(3));
  }

  @Test
  public void testDot() throws IOException {
    Int2IntOpenHashMapWritable m1 = new Int2IntOpenHashMapWritable();

    m1.put(1, 2);
    m1.put(2, 1);
    m1.put(3, 3);

    Int2IntOpenHashMapWritable m2 = new Int2IntOpenHashMapWritable();

    m2.put(1, 1);
    m2.put(2, 4);
    m2.put(4, 5);

    int s = m1.dot(m2);

    assertEquals(6, s);
  }
View Full Code Here

    assertEquals(6, s);
  }

  @Test
  public void testSortedEntries1() {
    Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable();

    m.put(1, 5);
    m.put(2, 2);
    m.put(3, 3);
    m.put(4, 3);
    m.put(5, 1);

    Int2IntMap.Entry[] e = m.getEntriesSortedByValue();
    assertEquals(5, e.length);

    assertEquals(1, e[0].getIntKey());
    assertEquals(5, e[0].getIntValue());
View Full Code Here

    assertEquals(1, e[4].getIntValue());
  }

  @Test
  public void testSortedEntries2() {
    Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable();

    m.put(1, 5);
    m.put(2, 2);
    m.put(3, 3);
    m.put(4, 3);
    m.put(5, 1);

    Int2IntMap.Entry[] e = m.getEntriesSortedByValue(2);

    assertEquals(2, e.length);

    assertEquals(1, e[0].getIntKey());
    assertEquals(5, e[0].getIntValue());
View Full Code Here

    assertEquals(3, e[1].getIntValue());
  }

  @Test
  public void testSortedEntries3() {
    Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable();

    m.put(1, 5);
    m.put(2, 2);

    Int2IntMap.Entry[] e = m.getEntriesSortedByValue(5);

    assertEquals(2, e.length);

    assertEquals(1, e[0].getIntKey());
    assertEquals(5, e[0].getIntValue());
View Full Code Here

    assertEquals(2, e[1].getIntValue());
  }

  @Test
  public void testSortedEntries4() {
    Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable();

    Int2IntMap.Entry[] e = m.getEntriesSortedByValue();
    assertTrue(e == null);
  }
View Full Code Here

      return null;
    }
    PriorityQueue<PairOfFloatInt> eS = f2eProbs.get(f).getTranslationsWithProbs(lexProbThreshold);

    if (!eS.isEmpty()) {
      PairOfFloatInt entry = eS.poll();
      int e = entry.getRightElement();
      String eTerm = eVocab_f2e.get(e);
      return eTerm;
    }
    return token;
  }
View Full Code Here

    float sumProbEF = 0;
    int numTrans = 0;
    //tf(e) = sum_f{tf(f)*prob(e|f)}
    while (numTrans < numTransPerToken && !eS.isEmpty()) {
      PairOfFloatInt entry = eS.poll();
      float probEF = entry.getLeftElement();
      int e = entry.getRightElement();
      String eTerm = eVocab_f2e.get(e);

      //      LOG.info("Pr("+eTerm+"|"+token+")="+probEF);

      if (probEF > 0 && e > 0 && !docLangTokenizer.isStopWord(eTerm) && (translateOnly == null || !translateOnly.equals("indri") || indriPuncPattern.matcher(eTerm).matches()) && (pairsInSCFG == null || pairsInSCFG.contains(new PairOfStrings(token,eTerm)))) {     
View Full Code Here

TOP

Related Classes of edu.umd.cloud9.io.map.Int2IntOpenHashMapWritable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.