예제 #1
0
 /** Get cash on hand, divide it by the number of outlinks and apply. */
 @Override
 public void distributeScoreToOutlinks(
     String fromUrl, WebPage row, Collection<ScoreDatum> scoreData, int allCount) {
   ByteBuffer cashRaw = row.getMetadata().get(CASH_KEY);
   if (cashRaw == null) {
     return;
   }
   float cash = Bytes.toFloat(cashRaw.array(), cashRaw.arrayOffset() + cashRaw.position());
   if (cash == 0) {
     return;
   }
   // TODO: count filtered vs. all count for outlinks
   float scoreUnit = cash / allCount;
   // internal and external score factor
   float internalScore = scoreUnit * internalScoreFactor;
   float externalScore = scoreUnit * externalScoreFactor;
   for (ScoreDatum scoreDatum : scoreData) {
     try {
       String toHost = new URL(scoreDatum.getUrl()).getHost();
       String fromHost = new URL(fromUrl.toString()).getHost();
       if (toHost.equalsIgnoreCase(fromHost)) {
         scoreDatum.setScore(internalScore);
       } else {
         scoreDatum.setScore(externalScore);
       }
     } catch (MalformedURLException e) {
       LOG.error("Failed with the following MalformedURLException: ", e);
       scoreDatum.setScore(externalScore);
     }
   }
   // reset cash to zero
   row.getMetadata().put(CASH_KEY, ByteBuffer.wrap(Bytes.toBytes(0.0f)));
 }
예제 #2
0
  /** Increase the score by a sum of inlinked scores. */
  @Override
  public void updateScore(String url, WebPage page, List<ScoreDatum> inlinkedScoreData) {
    float score = page.getScore();
    for (ScoreDatum scoreDatum : inlinkedScoreData) {
      LOG.trace("adding <" + scoreDatum.getUrl() + ", " + scoreDatum.getScore() + ">");
      score += scoreDatum.getScore();
    }
    LOG.trace(url + ": " + score + " (" + page.getScore() + ")");
    page.setScore(score);

    ByteBuffer cashRaw = page.getMetadata().get(CASH_KEY);
    float cash = 1.0f;
    if (cashRaw != null) {
      cash = Bytes.toFloat(cashRaw.array(), cashRaw.arrayOffset() + cashRaw.position());
    }
    page.getMetadata().put(CASH_KEY, ByteBuffer.wrap(Bytes.toBytes(cash + score)));
  }
예제 #3
0
 /**
  * Set to 1.0f. The initial value should equal the injected value, and it should (obviously) be
  * non-zero.
  */
 @Override
 public void initialScore(String url, WebPage row) throws ScoringFilterException {
   row.setScore(1.0f);
   row.getMetadata().put(CASH_KEY, ByteBuffer.wrap(Bytes.toBytes(1.0f)));
 }
예제 #4
0
 @Override
 public void injectedScore(String url, WebPage row) throws ScoringFilterException {
   float score = row.getScore();
   row.getMetadata().put(CASH_KEY, ByteBuffer.wrap(Bytes.toBytes(score)));
 }