001package org.maltparser.core.feature; 002 003import java.io.Serializable; 004import java.util.ArrayList; 005 006import org.maltparser.core.exception.MaltChainedException; 007import org.maltparser.core.feature.function.FeatureFunction; 008import org.maltparser.core.feature.spec.SpecificationSubModel; 009import org.maltparser.core.feature.value.FeatureValue; 010 011/** 012* 013* 014* @author Johan Hall 015*/ 016public class FeatureVector extends ArrayList<FeatureFunction> implements Serializable { 017 public final static long serialVersionUID = 3256444702936019250L; 018 private final SpecificationSubModel specSubModel; 019 private final FeatureModel featureModel; 020 021 /** 022 * Constructs a feature vector 023 * 024 * @param _featureModel the parent feature model 025 * @param _specSubModel the subspecifiction-model 026 * @throws MaltChainedException 027 */ 028 public FeatureVector(FeatureModel _featureModel, SpecificationSubModel _specSubModel) throws MaltChainedException { 029 this.specSubModel = _specSubModel; 030 this.featureModel = _featureModel; 031 for (String spec : specSubModel) { 032 add(featureModel.identifyFeature(spec)); 033 } 034 } 035 036 /** 037 * Returns the subspecifiction-model. 038 * 039 * @return the subspecifiction-model 040 */ 041 public SpecificationSubModel getSpecSubModel() { 042 return specSubModel; 043 } 044 045 /** 046 * Returns the feature model that the feature vector belongs to. 047 * 048 * @return the feature model that the feature vector belongs to 049 */ 050 public FeatureModel getFeatureModel() { 051 return featureModel; 052 } 053 054 public FeatureValue getFeatureValue(int index) { 055 return get(index).getFeatureValue(); 056 } 057 058 /* (non-Javadoc) 059 * @see java.util.AbstractCollection#toString() 060 */ 061 public String toString() { 062 final StringBuilder sb = new StringBuilder(); 063 for (FeatureFunction function : this) { 064 if (function != null) { 065 sb.append(function.getFeatureValue().toString()); 066 sb.append('\n'); 067 } 068 } 069 return sb.toString(); 070 } 071}