Package edu.umd.cloud9.io.pair

Examples of edu.umd.cloud9.io.pair.PairOfLongFloat


                String term = m2.group(1);
                if ( !term.equals("NULL") ) {
                  float prob = Float.parseFloat(m2.group(2));
                  int engIndex = trgVocab.addOrGet(term);
                  logger.debug("Added: "+term+" with index: "+engIndex+" and prob:"+prob);
                  indexProbPairs.add(new PairOfIntFloat(engIndex, prob));
                  sumOfProbs += prob;
                }
              }
            }
            // if number of translations not set, we never cut-off, so all cases are long tails
View Full Code Here


                String term = m2.group(1);
                if (!term.equals("NULL")) {
                  float prob = Float.parseFloat(m2.group(2));
                  int engIndex = trgVocab.addOrGet(term);
                  logger.debug("Added: "+term+" with index: "+engIndex+" and prob:"+prob);
                  indexProbPairs.add(new PairOfIntFloat(engIndex, prob));
                  sumOfProbs+=prob;
                }
              }
            }
            if(sumOfProbs > probThreshold){
View Full Code Here

    @Override
    public void reduce(Text key, Iterable<PairOfIntLong> values, Context context)
        throws IOException, InterruptedException {
      String term = key.toString();
      Iterator<PairOfIntLong> iter = values.iterator();
      PairOfIntLong p = iter.next();
      int df = p.getLeftElement();
      long cf = p.getRightElement();
      WritableUtils.writeVInt(dfByTermOut, df);
      WritableUtils.writeVLong(cfByTermOut, cf);
      if (iter.hasNext()) {
        throw new RuntimeException("More than one record for term: " + term);
      }
View Full Code Here

      // map from the id back to text
      // sLogger.info("termid: " + key);
      String term = mTermIdMap.getTerm(key.get());
      // sLogger.info("term: " + term);
      PairOfIntLong pair = gs.getStats(term);

      if (pair == null) {
        p.setCf(-1);
        p.setDf(-1);
      } else {
        p.setCf(pair.getRightElement());
        p.setDf(pair.getLeftElement());
      }

      output.collect(key, p);
    }
View Full Code Here

public class PairOfLongFloatTest {

  @Test
  public void testBasic() throws IOException {
    PairOfLongFloat pair = new PairOfLongFloat(1L, 2.0f);

    assertEquals(1L, pair.getLeftElement());
    assertTrue(pair.getRightElement() == 2.0f);
  }
View Full Code Here

    assertTrue(pair.getRightElement() == 2.0f);
  }

  @Test
  public void testSerialize() throws IOException {
    PairOfLongFloat origPair = new PairOfLongFloat(1L, 2.0f);

    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    DataOutputStream dataOut = new DataOutputStream(bytesOut);

    origPair.write(dataOut);

    PairOfLongFloat pair = new PairOfLongFloat();

    pair.readFields(new DataInputStream(new ByteArrayInputStream(bytesOut.toByteArray())));

    assertEquals(1L, pair.getLeftElement());
    assertTrue(pair.getRightElement() == 2.0f);
  }
View Full Code Here

    assertTrue(pair.getRightElement() == 2.0f);
  }

  @Test
  public void testComparison1() throws IOException {
    PairOfLongFloat pair1 = new PairOfLongFloat(1L, 2.0f);
    PairOfLongFloat pair2 = new PairOfLongFloat(1L, 2.0f);
    PairOfLongFloat pair3 = new PairOfLongFloat(1L, 1.0f);
    PairOfLongFloat pair4 = new PairOfLongFloat(0L, 9.0f);
    PairOfLongFloat pair5 = new PairOfLongFloat(9L, 0.0f);

    assertTrue(pair1.equals(pair2));
    assertFalse(pair1.equals(pair3));

    assertTrue(pair1.compareTo(pair2) == 0);
View Full Code Here

  @Test
  public void testComparison2() throws IOException {
    WritableComparator comparator = new PairOfLongFloat.Comparator();

    PairOfLongFloat pair1 = new PairOfLongFloat(1L, 2.0f);
    PairOfLongFloat pair2 = new PairOfLongFloat(1L, 2.0f);
    PairOfLongFloat pair3 = new PairOfLongFloat(1L, 1.0f);
    PairOfLongFloat pair4 = new PairOfLongFloat(0L, 9.0f);
    PairOfLongFloat pair5 = new PairOfLongFloat(9L, 0.0f);

    assertTrue(WritableComparatorTestHarness.compare(comparator, pair1, pair2) == 0);
    assertTrue(WritableComparatorTestHarness.compare(comparator, pair1, pair3) > 0);
    assertTrue(WritableComparatorTestHarness.compare(comparator, pair1, pair4) > 0);
    assertTrue(WritableComparatorTestHarness.compare(comparator, pair1, pair5) < 0);
View Full Code Here

      float sumProb2 = 0;
      for (Entry<String> entry : probDist.entrySet()) {
        float pr = entry.getValue() / sumProb;
        if (pr > lexProbThreshold) {
          sumProb2 += pr;
          sortedFilteredProbDist.add(new PairOfStringFloat(entry.getKey(), pr));
        }
      }

      // re-normalize values after removal of low-prob entries
      float cumProb = 0;
      int cnt = 0;
      while (cnt < maxNumTrans && cumProb < cumProbThreshold && !sortedFilteredProbDist.isEmpty()) {
        PairOfStringFloat entry = sortedFilteredProbDist.pollLast();
        float pr = entry.getValue() / sumProb2;
        cumProb += pr;
        normProbDist.put(entry.getKey(), pr);
        cnt++;
      }

      probMap.put(sourceTerm, normProbDist);
    }
View Full Code Here

        String[] parts = rule.split("\\|\\|\\|");
        String[] lhs = parts[0].trim().split(" ");
        String[] rhs = parts[1].trim().split(" ");;
        for (String l : lhs) {
          for (String r : rhs) {
            pairsInSCFG.add(new PairOfStrings(l, r));
          }
        }
      }
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of edu.umd.cloud9.io.pair.PairOfLongFloat

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.