private int[] objectArrayToIntArray(E[] os) { int[] is = new int[os.length]; for (int i = 0; i < os.length; i++) { is[i] = classIndex.indexOf(os[i]); } return is; }
public boolean rootTW(IntTaggedWord rTW) { // System.out.println("rootTW: checking if " + rTW.toString("verbose") + // " == " + Lexicon.BOUNDARY_TAG + "[" + // tagIndex.indexOf(Lexicon.BOUNDARY_TAG) + "]" + ": " + // (rTW.tag == tagIndex.indexOf(Lexicon.BOUNDARY_TAG))); return rTW.tag == tagIndex.indexOf(Lexicon.BOUNDARY_TAG); }
/** * Get the allowed label set for an observation. * * @param observation * @return The allowed label set, or null if the observation is unconstrained. */ public int[] getConstrainedSet(String observation) { int i = observationIndex.indexOf(observation); return i >= 0 ? labelDictionary[i] : null; }
public double scoreOf(Collection<F> features) { double sum = 0; for (F feature : features) { int f = featureIndex.indexOf(feature); if (f >= 0) { sum += weights[f]; } } return sum; }
/** * * @param tag field name (i.e. workshopdate, workshoplocation) * @return the reference of that field in the underlying {@link edu.stanford.nlp.util.Index} */ public static int getFieldIndex(String tag) { return (fieldIndices.indexOf(tag)); }
public static <T> int[] indicesOf(Collection<T> input, Index<T> index) { int[] result = new int[input.size()]; int count = 0; for (T element : input) result[count++] = index.indexOf(element); return result; }
/** * Sets each value of double[] target to be * target[idx.indexOf(k)]+a.getCount(k) for all keys k in arg */ public static <E> void addInPlace(double[] target, Counter<E> arg, Index<E> idx) { for (Map.Entry<E, Double> entry : arg.entrySet()) { target[idx.indexOf(entry.getKey())] += entry.getValue(); } }
/** * Sets each value of double[] target to be * target[idx.indexOf(k)]-a.getCount(k) for all keys k in arg */ public static <E> void subtractInPlace(double[] target, Counter<E> arg, Index<E> idx) { for (Map.Entry<E, Double> entry : arg.entrySet()) { target[idx.indexOf(entry.getKey())] -= entry.getValue(); } }
public UniformPrior(String backgroundSymbol, Index<String> classIndex, List<IN> doc) { this.classIndex = classIndex; this.backgroundSymbol = classIndex.indexOf(backgroundSymbol); this.numClasses = classIndex.size(); this.possibleValues = new int[numClasses]; for (int i=0; i<numClasses; i++) { possibleValues[i] = i; } this.doc = doc; }
public EmpiricalNERPriorBIO(String backgroundSymbol, Index<String> classIndex, Index<String> tagIndex, List<IN> doc, Pair<double[][], double[][]> matrices, SeqClassifierFlags flags) { super(backgroundSymbol, classIndex, tagIndex, doc); entityMatrix = matrices.first(); subEntityMatrix = matrices.second(); this.flags = flags; ORGIndex = tagIndex.indexOf("ORG"); LOCIndex = tagIndex.indexOf("LOC"); }
public EntityCachingAbstractSequencePrior(String backgroundSymbol, Index<String> classIndex, List<IN> doc) { this.classIndex = classIndex; this.backgroundSymbol = classIndex.indexOf(backgroundSymbol); this.numClasses = classIndex.size(); this.possibleValues = new int[numClasses]; for (int i=0; i<numClasses; i++) { possibleValues[i] = i; } this.doc = doc; }
/** Returns the score of the RVFDatum for the specified label. * Ignores the true label of the RVFDatum. */ private double scoreOfRVFDatum(Counter<Integer> features, L label) { int iLabel = labelIndex.indexOf(label); double score = 0.0; for (Map.Entry<Integer, Double> entry : features.entrySet()) { score += weight(entry.getKey(), iLabel) * entry.getValue(); } return score + thresholds[iLabel]; }
public void writeSVMLightFormat(PrintWriter writer) { for (RVFDatum<L, F> datum : this) { writer.print(this.labelIndex.indexOf(datum.label())); Counter<F> features = datum.asFeaturesCounter(); for (F feature : features.keySet()) { double count = features.getCount(feature); writer.format(Locale.ENGLISH, " %s:%f", this.featureIndex.indexOf(feature), count); } writer.println(); } }
public double scoreOf(Counter<F> features) { double sum = 0; for (F feature : features.keySet()) { int f = featureIndex.indexOf(feature); if (f >= 0) { sum += weights[f]*features.getCount(feature); } } return sum; } /*
public void changeLabelIndex(Index<L> newLabelIndex) { labels = trimToSize(labels); for (int i = 0; i < labels.length; i++) { labels[i] = newLabelIndex.indexOf(labelIndex.get(labels[i])); } labelIndex = newLabelIndex; }
public Counter<L> scoresOf(Datum<L, F> example, Collection<L> possibleLabels) { Counter<L> scores = new ClassicCounter<>(); for (L l : possibleLabels) { if (labelIndex.indexOf(l) == -1) { continue; } double score = scoreOf(example, l); scores.setCount(l, score); } return scores; }