Esempio n. 1
0
  private float adjustByTag(Element elem, float sum) {
    final HTMLTag tag = htmlTag(elem);

    // FIXME: Just examples.
    if (tag == HTML.A) {
      CharSequence href = elem.attribute(HTML.ATTR_HREF);
      if ((href != null) && href.length() > 0) {
        sum *= 0.25f;
      }
    } else if (tag == HTML.H1) {
      sum *= 2.0f;
    } else if (tag == HTML.H2) {
      sum *= 1.8f;
    } else if (tag == HTML.H3) {
      sum *= 1.6f;
    }

    return sum;
  }
Esempio n. 2
0
  @Override
  public Action filter(Node node) {
    final Element elem = node.asElement();
    if (elem != null) {
      float inlineSum = 0.0f;
      float blockSum = 0.0f;

      for (Node child : elem.children()) {
        final Integer cwords = child.get(WORD_COUNT);
        if (cwords != null) {
          Element celm = child.asElement();
          if (celm != null) {
            final Float cwordy = celm.get(WORDINESS);
            if (isInline(celm)) {
              inlineSum += cwordy;
            } else {
              blockSum += (cwordy * cwords);
            }
          } else {
            inlineSum += cwords;
          }
        }
      }

      float sum = inlineSum;

      int ewc = elem.get(WORD_COUNT);
      if (ewc > 0) sum += (blockSum / ewc);

      // FIXME: Really just additive in inline plus block case?

      sum = adjustByTag(elem, sum);

      elem.set(WORDINESS, sum);
    }

    return Action.CONTINUE;
  }