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

edu.stanford.nlp.parser.lexparser.IntDependency 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.parser.lexparser;

import java.io.Serializable;

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


/** Maintains a dependency between head and dependent where they are each an IntTaggedWord.
 *
 *  @author Christopher Manning
 */
public class IntDependency implements Serializable {

  public static final String LEFT = "left";
  public static final String RIGHT = "right";
  public static final int ANY_DISTANCE_INT = -1;

  public final IntTaggedWord head;
  public final IntTaggedWord arg;
  public final boolean leftHeaded;
  public final short distance;

  @Override
  public int hashCode() {
    return head.hashCode() ^ (arg.hashCode() << 8) ^ ((leftHeaded ? 1 : 0) << 15) ^ (distance << 16);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o instanceof IntDependency) {
      IntDependency d = (IntDependency) o;
      return (head.equals(d.head) && arg.equals(d.arg) && distance == d.distance && leftHeaded == d.leftHeaded);
    } else {
      return false;
    }
  }

  private static final char[] charsToEscape = {'\"'};

  @Override
  public String toString() {
    return "\"" + StringUtils.escapeString(head.toString(), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(arg.toString(), charsToEscape, '\\') + "\" " + (leftHeaded ? LEFT : RIGHT) + " " + distance;
  }

  public String toString(Index wordIndex, Index tagIndex) {
    return "\"" + StringUtils.escapeString(head.toString(wordIndex, tagIndex), charsToEscape, '\\') + "\" -> \"" + StringUtils.escapeString(arg.toString(wordIndex, tagIndex), charsToEscape, '\\') + "\" " + (leftHeaded ? LEFT : RIGHT) + " " + distance;
  }

  public IntDependency(IntTaggedWord head, IntTaggedWord arg, boolean leftHeaded, int distance) {
    this.head = head;
    this.arg = arg;
    this.distance = (short) distance;
    this.leftHeaded = leftHeaded;
  }

  public IntDependency(int headWord, int headTag, int argWord, int argTag, boolean leftHeaded, int distance) {
    this.head = new IntTaggedWord(headWord, headTag);
    this.arg = new IntTaggedWord(argWord, argTag);
    this.distance = (short) distance;
    this.leftHeaded = leftHeaded;
  }

  private static final long serialVersionUID = 1L;

} // end class IntDependency




© 2015 - 2024 Weber Informatics LLC | Privacy Policy