Example usage for edu.stanford.nlp.util Index size

List of usage examples for edu.stanford.nlp.util Index size

Introduction

In this page you can find the example usage for edu.stanford.nlp.util Index size.

Prototype

int size();

Source Link

Document

Returns the number of indexed objects.

Usage

From source file:conditionalCFG.ConditionalCFGParser.java

License:Open Source License

public ConditionalCFGParser(BinaryGrammar bg, UnaryGrammar ug, ConditionalLexicon lex, Options op,
        Index<String> stateIndex, Index<String> wordIndex, Index<String> tagIndex) {
    //    System.out.println("ExhaustivePCFGParser constructor called.");
    this.bg = bg;
    this.ug = ug;
    this.lex = lex;
    this.op = op;
    this.tlp = op.langpack();
    goalStr = tlp.startSymbol();//  w w  w  .  j  a  v a 2s. c om
    this.stateIndex = stateIndex;
    this.wordIndex = wordIndex;
    this.tagIndex = tagIndex;
    tf = new LabeledScoredTreeFactory();

    numStates = stateIndex.size();
    isTag = new boolean[numStates];
    // tag index is smaller, so we fill by iterating over the tag index
    // rather than over the state index
    for (String tag : tagIndex.objectsList()) {
        int state = stateIndex.indexOf(tag);
        if (state < 0) {
            continue;
        }
        isTag[state] = true;
    }
}

From source file:gr.aueb.cs.nlp.wordtagger.classifier.SVMWindows64Factory.java

License:Open Source License

/**
 * Converts the svm_struct weight Counter (in which the weight for a feature/label pair
 * correspondes to ((labelIndex * numFeatures)+(featureIndex+1))) into a weight Counter
 * using the actual features and labels.
 *//*from w  w w .j av a 2s  .  c o m*/
private ClassicCounter<Pair<F, L>> convertSVMStructWeights(ClassicCounter<Integer> weights,
        Index<F> featureIndex, Index<L> labelIndex) {
    // int numLabels = labelIndex.size();
    int numFeatures = featureIndex.size();
    ClassicCounter<Pair<F, L>> newWeights = new ClassicCounter<Pair<F, L>>();
    for (int i : weights.keySet()) {
        L l = labelIndex.get((i - 1) / numFeatures); // integer division on purpose
        F f = featureIndex.get((i - 1) % numFeatures);
        double w = weights.getCount(i);
        newWeights.incrementCount(new Pair<F, L>(f, l), w);
    }

    return newWeights;
}