Package edu.umd.cloud9.io.pair

Examples of edu.umd.cloud9.io.pair.PairOfStringLong$Comparator


                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

      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

public class PairOfStringLongTest {

  @Test
  public void testBasic() throws IOException {
    PairOfStringLong pair = new PairOfStringLong("hi", 1L);

    assertEquals("hi", pair.getLeftElement());
    assertEquals(1L, pair.getRightElement());
  }
View Full Code Here

    assertEquals(1L, pair.getRightElement());
  }

  @Test
  public void testSerialize() throws IOException {
    PairOfStringLong origPair = new PairOfStringLong("hi", 2L);

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

    origPair.write(dataOut);

    PairOfStringLong pair = new PairOfStringLong();

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

    assertEquals("hi", pair.getLeftElement());
    assertEquals(2L, pair.getRightElement());
  }
View Full Code Here

    assertEquals(2L, pair.getRightElement());
  }

  @Test
  public void testComparison1() throws IOException {
    PairOfStringLong pair1 = new PairOfStringLong("hi", 1L);
    PairOfStringLong pair2 = new PairOfStringLong("hi", 1L);
    PairOfStringLong pair3 = new PairOfStringLong("hi", 0L);
    PairOfStringLong pair4 = new PairOfStringLong("a", 0L);
    PairOfStringLong pair5 = new PairOfStringLong("hi", 2L);

    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 PairOfStringLong.Comparator();

    PairOfStringLong pair1 = new PairOfStringLong("hi", 1L);
    PairOfStringLong pair2 = new PairOfStringLong("hi", 1L);
    PairOfStringLong pair3 = new PairOfStringLong("hi", 0L);
    PairOfStringLong pair4 = new PairOfStringLong("a", 0L);
    PairOfStringLong pair5 = new PairOfStringLong("hi", 2L);

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

    assertTrue(WritableComparatorTestHarness.compare(comparator, pair1, pair2) == 0);
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.PairOfStringLong$Comparator

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.