public EntityConfidence(double conf, boolean corr, Sequence input, int start, int end) {
   this.confidence = conf;
   this.correct = corr;
   StringBuffer buff = new StringBuffer();
   if (input != null) {
     for (int j = start; j <= end; j++) {
       FeatureVector fv = (FeatureVector) input.get(j);
       for (int k = 0; k < fv.numLocations(); k++) {
         String featureName = fv.getAlphabet().lookupObject(fv.indexAtLocation(k)).toString();
         if (featureName.startsWith("W=") && featureName.indexOf("@") == -1) {
           buff.append(featureName.substring(featureName.indexOf('=') + 1) + " ");
         }
       }
     }
   }
   this.entity = buff.toString();
 }
예제 #2
0
  /**
   * Classifies an instance using Winnow's weights
   *
   * @param instance an instance to be classified
   * @return an object containing the classifier's guess
   */
  public Classification classify(Instance instance) {
    int numClasses = getLabelAlphabet().size();
    double[] scores = new double[numClasses];
    FeatureVector fv = (FeatureVector) instance.getData(this.instancePipe);
    // Make sure the feature vector's feature dictionary matches
    // what we are expecting from our data pipe (and thus our notion
    // of feature probabilities.
    assert (instancePipe == null || fv.getAlphabet() == this.instancePipe.getDataAlphabet());
    int fvisize = fv.numLocations();

    // Set the scores by summing wi*xi
    for (int fvi = 0; fvi < fvisize; fvi++) {
      int fi = fv.indexAtLocation(fvi);
      for (int ci = 0; ci < numClasses; ci++) scores[ci] += this.weights[ci][fi];
    }

    // Create and return a Classification object
    return new Classification(instance, this, new LabelVector(getLabelAlphabet(), scores));
  }