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

edu.stanford.nlp.semgraph.semgrex.Env 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.semgraph.semgrex;

import edu.stanford.nlp.ling.AnnotationLookup;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author sonalg
 * @version 11/3/14.
 */
public class Env implements Serializable {

  private static final long serialVersionUID = -4168610545399833956L;

  /**
   * Mapping of variable names to their values.
   */
  private final Map variables;

  public Env() {
    variables = new HashMap<>();
  }

  public Env(Map variables) {
    this.variables = variables;
  }

  public void bind(String name, Object obj) {
    if (obj != null) {
      variables.put(name, obj);
    } else {
      variables.remove(name);
    }
  }

  public void unbind(String name) {
    bind(name, null);
  }

  public Object get(String name){
    return variables.get(name);
  }

  public static Class lookupAnnotationKey(Env env, String name){
    if (env != null) {
      Object obj = env.get(name);
      if (obj != null) {
        if (obj instanceof Class) {
          return (Class) obj;
        }
//        else if (obj instanceof Value) {
//          obj = ((Value) obj).get();
//          if (obj instanceof Class) {
//            return (Class) obj;
//          }
//        }
      }
    }
    Class coreKeyClass = AnnotationLookup.toCoreKey(name);
    if (coreKeyClass != null) {
      return coreKeyClass;
    } else {
      try {
        Class clazz = Class.forName(name);
        return clazz;
      } catch (ClassNotFoundException ex) {
        return null;
      }
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy