Exemple #1
0
  /**
   * Computes the difference between two attributes using the given distance metric. This function
   * takes care of things like dynamic attributes and null values. This one allows reclamation of a
   * difference object.
   *
   * @param alpha the target attribute
   * @param alphaSpan the target attribute's span
   * @param beta the candidate attribute
   * @param betaSpan the candidate attribute's framespan
   * @param blackout the blackout data
   * @param blackoutSpan when the blackout is defined
   * @param ignore the don't-care data
   * @param ignoreSpan the don't-care framespan
   * @param frame the frame to compare
   * @param cfd information about the media
   * @param old cached difference object
   * @return the new difference object, or the same one, changed
   * @throws IgnoredValueException if the whole of the data on the frame was ignored
   */
  public static Measurable.Difference helpGetDiff(
      Attribute alpha,
      FrameSpan alphaSpan,
      Attribute beta,
      FrameSpan betaSpan,
      Attribute blackout,
      FrameSpan blackoutSpan,
      Attribute ignore,
      FrameSpan ignoreSpan,
      int frame,
      CanonicalFileDescriptor cfd,
      Measurable.Difference old)
      throws IgnoredValueException {
    if (alpha == null || alpha.getValue(alphaSpan, frame) == null) {
      return new Distances.DefaultDifference(
          null,
          (beta != null) ? beta.getValue(betaSpan, frame) : null,
          (blackout != null) ? blackout.getValue(blackoutSpan, frame) : null,
          (ignore != null) ? ignore.getValue(ignoreSpan, frame) : null,
          cfd);

    } else {
      Measurable a = alpha.getValue(alphaSpan, frame);
      return a.getDifference(
          (beta != null) ? beta.getValue(betaSpan, frame) : null,
          (blackout != null) ? blackout.getValue(blackoutSpan, frame) : null,
          (ignore != null) ? ignore.getValue(ignoreSpan, frame) : null,
          cfd,
          old);
    }
  }
Exemple #2
0
 /**
  * Tests to see if the specified metric name is known for the given attribute data type.
  *
  * @param type the attribute type
  * @param s the name of the distance metric to look for
  * @return true if <code>s</code> is the name of a known metric for the type
  * @throws UnknownDistanceException if the type is unknown. XXX: shouldn't this be the other way
  *     around?
  */
 public static final boolean isDistanceFor(Measurable type, String s)
     throws UnknownDistanceException {
   Map<String, Distance> values = distanceMap.get(type.getType());
   if (values != null) {
     return values.containsKey(s.toLowerCase());
   } else {
     throw new UnknownDistanceException(type, s);
   }
 }
Exemple #3
0
 /**
  * Computes the difference between two attributes using the given distance metric. This must
  * operate on the attribute values directly
  *
  * @param alpha the target attribute
  * @param beta the candidate attribute
  * @param blackout the blackout data
  * @param ignore the don't-care data
  * @param cfd information about the media
  * @param old cached difference object
  * @return the difference
  * @throws IgnoredValueException if the whole of the data on the frame was ignored
  */
 public static Measurable.Difference helpGetDiff(
     Measurable alpha,
     Measurable beta,
     Measurable blackout,
     Measurable ignore,
     CanonicalFileDescriptor cfd,
     Measurable.Difference old)
     throws IgnoredValueException {
   if (alpha == null) {
     return new Distances.DefaultDifference(null, beta, blackout, ignore, cfd);
   } else {
     return alpha.getDifference(beta, blackout, ignore, cfd, old);
   }
 }
Exemple #4
0
 /**
  * Gets the distance functor for the given type.
  *
  * @param type the attribute data type
  * @param metric the metric name
  * @return the metric
  * @throws UnknownDistanceException if the metric isn't found
  */
 public static final Distance getDistanceFunctor(Measurable type, String metric)
     throws UnknownDistanceException {
   return Distances.getDistanceFunctor(type.getType(), metric);
 }