⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicdatum.java

📁 Standord Classifier实现了一个基于Java的最大熵分类器。用于模式识别
💻 JAVA
字号:
package edu.stanford.nlp.dbm;import java.util.*;/** * Basic implementation of Datum interface that can be constructed with a  * Collection of features and one more more labels. The features must be * specified * at construction, but the labels can be set and/or changed later. * * @author Joseph Smarr (jsmarr@stanford.edu) */public class BasicDatum implements Datum{    /** features for this Datum */    private final Collection features;    /** labels for this Datum. Invariant: always non-null */    private final List labels = new ArrayList();        /**      * Constructs a new BasicDatum with the given features and labels.     */    public BasicDatum(Collection features,Collection labels)    {        this(features);        setLabels(labels);    }        /**     * Constructs a new BasicDatum with the given features and label.     */    public BasicDatum(Collection features,Object label)    {        this(features);        setLabel(label);    }        /**     * Constructs a new BasicDatum with the given features and no labels.     */    public BasicDatum(Collection features) { this.features=features; }        /**     * Constructs a new BasicDatum with no features or labels.     */    public BasicDatum() { this(null); }        /**      * Returns the collection that this BasicDatum was constructed with.     */    public Collection asFeatures() { return(features); }        /**      * Returns the first label for this Datum, or null if none have been set.     */    public Object label() { return((labels.size()>0)?(Object)labels.get(0):null); }        /**     * Returns the complete List of labels for this Datum, which may be empty.     */    public Collection labels() { return labels; }        /**     * Removes all currently assigned Labels for this Datum then adds the     * given Label.     * Calling <tt>setLabel(null)</tt> effectively clears all labels.     */    public void setLabel(Object label)    {        labels.clear();        addLabel(label);    }        /**     * Removes all currently assigned labels for this Datum then adds all      * of the given Labels.     */    public void setLabels(Collection labels)    {        this.labels.clear();        if(labels!=null) this.labels.addAll(labels);    }        /**     * Adds the given Label to the List of labels for this Datum if it is not     * null.     */    public void addLabel(Object label) { if(label!=null) labels.add(label); }        /** Returns a String representation of this BasicDatum (lists features and labels). */    public String toString() { return("BasicDatum[features="+asFeatures()+",labels="+labels()+"]"); }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -