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

edu.stanford.nlp.util.ReflectionLoading 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.util;

/**
 * The goal of this class is to make it easier to load stuff by
 * reflection.  You can hide all of the ugly exception catching, etc
 * by using the static methods in this class.
 *
 * @author John Bauer
 * @author Gabor Angeli (changed)
 */

public class ReflectionLoading {

  // static methods only
  private ReflectionLoading() {}

  /**
   * You can use this as follows:
   * 
* String s = * ReflectionLoading.loadByReflection("java.lang.String", "foo"); *
* String s = * ReflectionLoading.loadByReflection("java.lang.String"); *
* Note that this uses generics for convenience, but this does * nothing for compile-time error checking. You can do *
* Integer i = * ReflectionLoading.loadByReflection("java.lang.String"); *
* and it will compile just fine, but will result in a ClassCastException. */ @SuppressWarnings("unchecked") public static T loadByReflection(String className, Object ... arguments) { try{ return (T) new MetaClass(className).createInstance(arguments); } catch (Exception e) { throw new ReflectionLoadingException("Error creating " + className, e); } } /** * This class encapsulates all of the exceptions that can be thrown * when loading something by reflection. */ public static class ReflectionLoadingException extends RuntimeException { private static final long serialVersionUID = -3324911744277952585L; public ReflectionLoadingException(String message, Throwable reason) { super(message, reason); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy