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

edu.stanford.nlp.parser.shiftreduce.FinalizeTransition 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.shiftreduce;

import java.util.List;
import java.util.Set;
import edu.stanford.nlp.parser.common.ParserConstraint;

/**
 * Transition that finishes the processing of a state
 */
public class FinalizeTransition implements Transition {
  private final Set rootStates;

  public FinalizeTransition(Set rootStates) {
    this.rootStates = rootStates;
  }

  @Override
  public boolean isLegal(State state, List constraints) {
    boolean legal = !state.finished && state.tokenPosition >= state.sentence.size() && state.stack.size() == 1 && rootStates.contains(state.stack.peek().value());
    if (!legal || constraints == null) {
      return legal;
    }

    for (ParserConstraint constraint : constraints) {
      if (constraint.start != 0 || constraint.end != state.sentence.size()) {
        continue;
      }
      if (!ShiftReduceUtils.constraintMatchesTreeTop(state.stack.peek(), constraint)) {
        return false;
      }
    }

    return true;
  }

  @Override
  public State apply(State state) {
    return apply(state, 0.0);
  }

  @Override
  public State apply(State state, double scoreDelta) {
    return new State(state.stack, state.transitions.push(this), state.separators, state.sentence, state.tokenPosition, state.score + scoreDelta, true);
  }

  @Override
  public boolean equals(Object o) {
    if (o == this) {
      return true;
    }
    if (o instanceof FinalizeTransition) {
      return true;
    }
    return false;
  }

  @Override
  public int hashCode() {
    return 593744340; // a random int
  }


  @Override
  public String toString() {
    return "Finalize";
  }

  private static final long serialVersionUID = 1;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy