Esempio n. 1
0
  @Override
  public void scoreSearchToNode(
      Score score, Direction d, IConstraintMap c, IAttributeMap<? extends IAttribute> scoreAttrs) {
    Attribute attr = (Attribute) scoreAttrs.findAttr(scorerAttrId);
    if (attr == null) {
      return; // If we do not have the scorer attr present in the search direction, we do not score
              // - it wasn't 'wanted'
    }
    IBooleanValue bAttr = (IBooleanValue) attr;
    IAttributeConstraint na = c.findAttr(otherAttrId);

    // If there is no Node Data then we only score null
    if (na == null) { // || !na.hasValue()) {
      score.addNull(this, d);
      return;
    }

    float result = 0.0f;

    if (na.isIncludesNotSpecified()) {
      if (isScoreNull()) {
        result = getScoreOnNull();
      }
    }
    assert (na instanceof BooleanConstraint);
    result = Math.max(result, calcScore((BooleanConstraint) na, bAttr));
    score.add(this, result, d);
  }
 // FIXME Extract relevant bits from score()
 @Override
 public void scoreNodeToSearch(
     Score score,
     Score.Direction d,
     IAttributeMap<IAttributeConstraint> c,
     IAttributeMap<IAttribute> searchAttrs) {
   assert (d == Direction.reverse); // Always the case
   IAttributeConstraint na = c.findAttr(scorerAttrId);
   if (na == null) {
     return; // If we do not have the scorer attr present in the search direction, we do not score
             // - it wasn't 'wanted'
   }
   if (!na.isIncludesNotSpecified()) {
     score(score, d, na, c, searchAttrs);
   }
 }
  /* (non-Javadoc)
   * @see likemynds.db.indextree.Scorer#score(com.wwm.db.core.whirlwind.internal.IAttribute, likemynds.db.indextree.NodeAttributeContainer)
   */
  public void score(Score score, Score.Direction d, IAttribute wantAttr, IConstraintMap c) {

    IAttributeConstraint na = c.findAttr(otherAttrId);

    if (na == null) {
      return;
    }
    if (na
        .isIncludesNotSpecified()) { // na.hasValue() && // FIXME: Double check the logic this is
                                     // sometimes !includesNotSpecified()
      score.add(this, 1.0f, d);
      return;
    }
    //		if (!na.hasValue()) {
    //			return;
    //		}

    assert (wantAttr.getAttrId() == scorerAttrId);
    // score against bounding box
    EcefVector want = (EcefVector) wantAttr;
    DimensionsRangeConstraint lbv = (DimensionsRangeConstraint) na;
    if (lbv != null) {
      // if location is in box, there could be an exact match, so return 1.0f
      if (lbv.consistent(want)) {
        score.add(this, 1.0f, d);
        return;
      }

      // Else score based on distance from closest point of box, to the centre of this
      // RangePreference
      float distance = lbv.getDistance(want); // dist from

      // Find out how far inside or outside the preferred range location is
      // 1 down to 0 is within range, and negative is outside
      float scoreFactor = 1f - (distance / range);

      // If preferClose is false, score any value within range as 1
      if (!preferClose && scoreFactor >= 0f) {
        scoreFactor = 1f;
      }

      float convertedScore = scoreMapper.getScore(scoreFactor);

      score.add(this, convertedScore, d);
      return;
    }
  }
Esempio n. 4
0
  @Override
  public void scoreNodeToSearch(
      Score score,
      Direction d,
      IAttributeMap<IAttributeConstraint> c,
      IAttributeMap<IAttribute> searchAttrs) {
    IAttributeConstraint na = c.findAttr(scorerAttrId);
    if (na == null) {
      return; // If we do not have the scorer attr present in the search direction, we do not score
              // - it wasn't 'wanted'
    }
    IAttributeConstraint bNa = na;
    IBooleanValue otherAttr = (IBooleanValue) searchAttrs.findAttr(otherAttrId);

    // If some nulls under this node then Score 1 so
    // as not to push this node down in score
    if (bNa.isIncludesNotSpecified()) {
      score.add(this, maxScore, d);
      return;
    }

    //        // This should never happen
    //        if (!bNa.hasValue()) {
    //            assert(false);
    //            return;
    //        }

    // If there is no Attr Data then we only score null
    if (otherAttr == null) {
      score.addNull(this, d);
      return;
    }

    float result = calcScore((BooleanConstraint) bNa, otherAttr);
    score.add(this, result, d);
  }