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

edu.stanford.nlp.ling.tokensregex.matcher.ApproxMatch Maven / Gradle / Ivy

Go to download

Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.

There is a newer version: 4.5.7
Show newest version
package edu.stanford.nlp.ling.tokensregex.matcher;

import edu.stanford.nlp.util.Interval;
import edu.stanford.nlp.util.StringUtils;

import java.util.List;

/**
* Represents an approximate match with a cost
*
* @author Angel Chang
*/
public class ApproxMatch extends MultiMatch {
  double cost;
  Interval[] alignments;  // Tracks alignments from original sequence to matched sequence (null indicates not aligned)

  public ApproxMatch() {
  }

  public ApproxMatch(List matched, V value, int begin, int end, double cost) {
    this.matched = matched;
    this.value = value;
    this.begin = begin;
    this.end = end;
    this.cost = cost;
  }

  public ApproxMatch(List matched, V value, int begin, int end, List> multimatches, double cost) {
    this.matched = matched;
    this.value = value;
    this.begin = begin;
    this.end = end;
    this.multimatches = multimatches;
    this.cost = cost;
  }

  public ApproxMatch(List matched, V value, int begin, int end, List> multimatches, double cost, Interval[] alignments) {
    this.matched = matched;
    this.value = value;
    this.begin = begin;
    this.end = end;
    this.multimatches = multimatches;
    this.cost = cost;
    this.alignments = alignments;
  }

  public double getCost() {
    return cost;
  }

  public Interval[] getAlignments() {
    return alignments;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    if (!super.equals(o)) return false;

    ApproxMatch that = (ApproxMatch) o;

    if (Double.compare(that.cost, cost) != 0) return false;

    return true;
  }

  @Override
  public int hashCode() {
    int result = super.hashCode();
    long temp;
    temp = Double.doubleToLongBits(cost);
    result = 31 * result + (int) (temp ^ (temp >>> 32));
    return result;
  }

  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("(");
    sb.append(super.toString());
    sb.append(",").append(cost);
    if (alignments != null) {
      sb.append(", [").append(StringUtils.join(alignments, ", ")).append("]");
    }
    sb.append(")");
    return sb.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy