edu.stanford.nlp.util.Interner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stanford-parser Show documentation
Show all versions of stanford-parser Show documentation
Stanford Parser processes raw text in English, Chinese, German, Arabic, and French, and extracts constituency parse trees.
The newest version!
package edu.stanford.nlp.util;
import edu.stanford.nlp.util.logging.Redwood;
import java.lang.ref.WeakReference;
import java.util.Map;
import java.util.Set;
/**
* For interning (canonicalizing) things.
*
* It maps any object to a unique interned version which .equals the
* presented object. If presented with a new object which has no
* previous interned version, the presented object becomes the
* interned version. You can tell if your object has been chosen as
* the new unique representative by checking whether o == intern(o).
* The interners use WeakHashMap, meaning that if the only pointers
* to an interned item are the interners' backing maps, that item can
* still be garbage collected. Since the gc thread can silently
* remove things from the backing map, there's no public way to get
* the backing map, but feel free to add one at your own risk.
*
* Note that in general it is just as good or better to use the
* static Interner.globalIntern() method rather than making an
* instance of Interner and using the instance-level intern().
*
* Author: Dan Klein
* Date: 9/28/03
*
* @author Dan Klein
*/
public class Interner {
/** A logger for this class */
private static Redwood.RedwoodChannels log = Redwood.channels(Interner.class);
protected static Interner