All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.nlp.util.HasInterval Maven / Gradle / Ivy

Go to download

Stanford Parser processes raw text in English, Chinese, German, Arabic, and French, and extracts constituency parse trees.

There is a newer version: 3.9.2
Show newest version
package edu.stanford.nlp.util;

import java.util.Comparator;

/**
 * HasInterval interface
 *
 * @author Angel Chang
 */
public interface HasInterval> {
  /**
   * Returns the interval
   * @return interval
   */
  public Interval getInterval();

  public final static Comparator> LENGTH_COMPARATOR =
      (e1, e2) -> {
        int len1 = e1.getInterval().getEnd() - e1.getInterval().getBegin();
        int len2 = e2.getInterval().getEnd() - e2.getInterval().getBegin();
        if (len1 == len2) {
          return 0;
        } else {
          return (len1 > len2)? -1:1;
        }
      };

  public final static Comparator ENDPOINTS_COMPARATOR =
      (e1, e2) -> (e1.getInterval().compareTo(e2.getInterval()));

  public final static Comparator NESTED_FIRST_ENDPOINTS_COMPARATOR =
      (e1, e2) -> {
        Interval.RelType rel = e1.getInterval().getRelation(e2.getInterval());
        if (rel.equals(Interval.RelType.CONTAIN)) {
          return 1;
        } else if (rel.equals(Interval.RelType.INSIDE)) {
          return -1;
        } else {
          return (e1.getInterval().compareTo(e2.getInterval()));
        }
      };

  public final static Comparator CONTAINS_FIRST_ENDPOINTS_COMPARATOR =
      (e1, e2) -> {
        Interval.RelType rel = e1.getInterval().getRelation(e2.getInterval());
        if (rel.equals(Interval.RelType.CONTAIN)) {
          return -1;
        } else if (rel.equals(Interval.RelType.INSIDE)) {
          return 1;
        } else {
          return (e1.getInterval().compareTo(e2.getInterval()));
        }
      };

  public final static Comparator> LENGTH_ENDPOINTS_COMPARATOR =
          Comparators.chain(HasInterval.LENGTH_COMPARATOR, HasInterval.ENDPOINTS_COMPARATOR);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy