Package edu.umd.cloud9.io.map

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


      sLogger = logger;
    }

    //sLogger.setLevel(Level.DEBUG);

    HMapSFW v = new HMapSFW();
    float normalization=0;
    for(int e : tfTable.keySet()){
      // retrieve term string, tf and df
      String eTerm = eVocab.get(e);
      float tf = tfTable.get(e);
      float df = dfTable.get(e);

      // compute score via scoring model
      float score = ((Bm25) scoringModel).computeDocumentWeight(tf, df, docLen);

      sLogger.debug(eTerm+" "+tf+" "+df+" "+score);
      if(score>0){
        v.put(eTerm, score);
        if(isNormalize){
          normalization+=Math.pow(score, 2);
        }   
      }
    }

    // length-normalize doc vector
    if(isNormalize){
      normalization = (float) Math.sqrt(normalization);
      for(Entry<String> e : v.entrySet()){
        v.put(e.getKey(), e.getValue()/normalization);
      }
    }
    return v;
  }
View Full Code Here


      sLogger = logger;
    }

    //sLogger.setLevel(Level.DEBUG);

    HMapSFW v = new HMapSFW();
    float normalization=0;
    for(int e : tfTable.keySet()){
      // retrieve term string, tf and df
      String eTerm = eVocab.get(e);
      float tf = tfTable.get(e);
      float df = dfTable.get(eTerm);

      // compute score via scoring model
      float score = ((Bm25) scoringModel).computeDocumentWeight(tf, df, docLen);

      sLogger.debug(eTerm+" "+tf+" "+df+" "+score);
      if(score>0){
        v.put(eTerm, score);
        if(isNormalize){
          normalization+=Math.pow(score, 2);
        }  
      }
    }

    // length-normalize doc vector
    if(isNormalize){
      normalization = (float) Math.sqrt(normalization);
      for(Entry<String> e : v.entrySet()){
        v.put(e.getKey(), e.getValue()/normalization);
      }
    }
    return v;
  }
View Full Code Here

    Map<String,HMapSFW> scfgDist = new HashMap<String,HMapSFW>();

    // phrase2count table is a set of (source_phrase --> X) maps, where X is a set of (phrase_trans --> count) maps
    HMapSFW phraseDist = new HMapSFW();

    HMapSIW srcTokenCnt = new HMapSIW();

    Set<String> bagOfTargetTokens = new HashSet<String>();

    try {
      FSDataInputStream fis = fs.open(new Path(grammarFile));
View Full Code Here

public class Int2IntOpenHashMapWritableTest {

  @Test
  public void testBasic() throws IOException {
    Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable();

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

    int value;

    assertEquals(2, m.size());

    value = m.get(2);
    assertEquals(5, value);

    value = m.remove(2);
    assertEquals(1, m.size());

    value = m.get(1);
    assertEquals(22, value);
  }
View Full Code Here

    assertEquals(22, value);
  }

  @Test
  public void testIncrement() throws IOException {
    Int2IntOpenHashMapWritable m = new Int2IntOpenHashMapWritable();

    m.put(2, 7);
    m.put(1, 29);

    assertEquals(7, m.get(2));
    assertEquals(29, m.get(1));

    m.increment(2);
    m.increment(1);
    m.increment(3);

    assertEquals(8, m.get(2));
    assertEquals(30, m.get(1));
    assertEquals(1, m.get(3));

    m.increment(1, 3);
    m.increment(3, 5);

    assertEquals(8, m.get(2));
    assertEquals(33, m.get(1));
    assertEquals(6, m.get(3));
  }
View Full Code Here

  }

  @Test
  public void testSerialize1() throws IOException {
    Int2IntOpenHashMapWritable.setLazyDecodeFlag(false);
    Int2IntOpenHashMapWritable m1 = new Int2IntOpenHashMapWritable();

    m1.put(3, 5);
    m1.put(4, 22);

    Int2IntOpenHashMapWritable n2 = Int2IntOpenHashMapWritable.create(m1.serialize());

    int value;

    assertEquals(2, n2.size());

    value = n2.get(3);
    assertEquals(5, value);

    value = n2.remove(3);
    assertEquals(1, n2.size());

    value = n2.get(4);
    assertEquals(22, value);
  }
View Full Code Here

  }

  @Test
  public void testSerializeLazy1() throws IOException {
    Int2IntOpenHashMapWritable.setLazyDecodeFlag(true);
    Int2IntOpenHashMapWritable m1 = new Int2IntOpenHashMapWritable();

    m1.put(3, 5);
    m1.put(4, 22);

    Int2IntOpenHashMapWritable m2 = Int2IntOpenHashMapWritable.create(m1.serialize());

    assertEquals(0, m2.size());
    assertFalse(m2.hasBeenDecoded());

    int[] keys = m2.getKeys();
    int[] values = m2.getValues();

    assertEquals(3, keys[0]);
    assertEquals(4, keys[1]);

    assertEquals(5, values[0]);
    assertEquals(22, values[1]);

    m2.decode();
    assertTrue(m2.hasBeenDecoded());

    int value;
    assertEquals(2, m2.size());

    value = m2.get(3);
    assertEquals(5, value);

    value = m2.remove(3);
    assertEquals(1, m2.size());

    value = m2.get(4);
    assertEquals(22, value);
  }
View Full Code Here

  }

  @Test
  public void testSerializeLazy2() throws IOException {
    Int2IntOpenHashMapWritable.setLazyDecodeFlag(true);
    Int2IntOpenHashMapWritable m1 = new Int2IntOpenHashMapWritable();

    m1.put(3, 5);
    m1.put(4, 22);

    // Object m2 should not have been decoded, size lazy decode flag is
    // true.
    Int2IntOpenHashMapWritable m2 = Int2IntOpenHashMapWritable.create(m1.serialize());

    // Even though m2 hasn't be decoded, we should be able to properly
    // serialize it.
    Int2IntOpenHashMapWritable m3 = Int2IntOpenHashMapWritable.create(m2.serialize());

    assertEquals(0, m3.size());
    assertFalse(m3.hasBeenDecoded());

    int[] keys = m3.getKeys();
    int[] values = m3.getValues();

    assertEquals(3, keys[0]);
    assertEquals(4, keys[1]);

    assertEquals(5, values[0]);
    assertEquals(22, values[1]);

    m3.decode();
    assertTrue(m3.hasBeenDecoded());

    int value;
    assertEquals(2, m3.size());

    value = m3.get(3);
    assertEquals(5, value);

    value = m3.remove(3);
    assertEquals(1, m3.size());

    value = m3.get(4);
    assertEquals(22, value);
  }
View Full Code Here

    assertEquals(22, value);
  }

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

    // make sure this does nothing
    m1.decode();

    assertEquals(0, m1.size());

    Int2IntMap m2 = Int2IntOpenHashMapWritable.create(m1.serialize());

    assertEquals(0, m2.size());
  }
View Full Code Here

  public void testBasic1() {
    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;
    }

    for (int i = 0; i < size; i++) {
      assertEquals(ints[i], map.get(i));
      assertTrue(map.containsKey(i));
    }
  }
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.