Esempio n. 1
0
  @Override
  protected FeatureValue calcFeatureValue(Decorable di) {
    // Feature applicable only to edges
    if (!(di instanceof Edge)) {
      throw new UnsupportedTypeException(
          "Feature only defined for edges: " + di.getClass().getCanonicalName());
    }

    // Feature applicable only to binary edges
    Edge e = (Edge) di;
    if (e.numNodes() != 2) {
      throw new UnsupportedTypeException("Feature only defined for binary edges: " + e.numNodes());
    }

    Iterator<Node> itr = e.getAllNodes();
    Node n1 = itr.next();
    Node n2 = itr.next();

    FeatureValue fv1 = n1.getFeatureValue(fid);
    FeatureValue fv2 = n2.getFeatureValue(fid);

    if (fv1.equals(FeatureValue.UNKNOWN_VALUE) || fv2.equals(FeatureValue.UNKNOWN_VALUE)) {
      return val0;
    }

    // If sparse value is specified and at least one value is not the sparse
    // value, return 0.
    if (commonvalue != null && fv1.equals(commonvalue)) {
      return val0;
    }

    return fv1.getStringValue().equals(fv2.getStringValue()) ? val1 : val0;
  }