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

edu.stanford.nlp.ling.tokensregex.matcher.MultiMatch 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.HasInterval;
import edu.stanford.nlp.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Represent multimatches
 *
 * @author Angel Chang
 */
public class MultiMatch extends Match {
  List> multimatches;

  public MultiMatch() {}

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

  public List> getMultimatches() {
    return multimatches;
  }

  public List> getMultimatched() {
    if (multimatches == null) return null;
    List> multimatched = new ArrayList<>(multimatches.size());
    for (Match m:multimatches) {
      multimatched.add(m.getMatched());
    }
    return multimatched;
  }

  public List getMultivalues() {
    if (multimatches == null) return null;
    List multivalues = new ArrayList<>(multimatches.size());
    for (Match m:multimatches) {
      multivalues.add(m.getValue());
    }
    return multivalues;
  }

  // Offsets in the original string to which each multimatch is aligned to
  public List> getMultioffsets() {
    if (multimatches == null) return null;
    List> multioffsets = new ArrayList<>(multimatches.size());
    for (Match m:multimatches) {
      multioffsets.add(m.getInterval());
    }
    return multioffsets;
  }

  @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;

    MultiMatch that = (MultiMatch) o;

    if (multimatches != null ? !multimatches.equals(that.multimatches) : that.multimatches != null) return false;

    return true;
  }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy