edu.illinois.cs.cogcomp.lbjava.classify.Feature类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中edu.illinois.cs.cogcomp.lbjava.classify.Feature类的一些代码示例,展示了Feature类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Feature类的具体详情如下:
包路径:edu.illinois.cs.cogcomp.lbjava.classify.Feature
类名称:Feature

Feature介绍

[英]Objects of this class represent the value of a Classifier's decision.
[中]此类的对象表示Classifier决策的值。

代码示例

代码示例来源:origin: CogComp/cogcomp-nlp

public String discreteValue(Object __example) {
  if (!(__example instanceof Token)) {
    String type = __example == null ? "null" : __example.getClass().getName();
    System.err
        .println("Classifier 'labelOneAfter(Token)' defined on line 108 of POSKnown.lbj received '"
            + type + "' as input.");
    new Exception().printStackTrace();
    System.exit(1);
  }
  return cachedFeatureValue(__example).getStringValue();
}

代码示例来源:origin: CogComp/cogcomp-nlp

public Feature featureValue(Object __example) {
  if (!(__example instanceof Token)) {
    String type = __example == null ? "null" : __example.getClass().getName();
    System.err
        .println("Classifier 'L1bL1a(Token)' defined on line 139 of POSKnown.lbj received '"
            + type + "' as input.");
    new Exception().printStackTrace();
    System.exit(1);
  }
  Feature __result;
  __result = left.featureValue(__example).conjunction(right.featureValue(__example), this);
  return __result;
}

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

/**
 * Two conjunctions are equivalent when their arguments are equivalent.
 *
 * @return <code>true</code> iff the argument is an equivalent <code>Feature</code>.
 **/
public boolean equals(Object o) {
  if (!super.equals(o))
    return false;
  RealConjunctiveFeature c = (RealConjunctiveFeature) o;
  return (left == c.left || left.equals(c.left))
      && (right == c.right || right.equals(c.right));
}

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

/**
 * A helper method for {@link #getFeatureKey(Lexicon,boolean,int)}, this method computes the
 * feature keys corresponding to the arguments of the conjunction. Here, we lookup the arguments
 * to the conjunction in the lexicon so that their counts are never less than the conjunction's,
 * and we return the actual feature object that's already a key in the lexicon.
 *
 * @param f The argument feature for which a key will be computed.
 * @param lexicon The lexicon into which this feature will be indexed.
 * @param training Whether or not the learner is currently training.
 * @param label The label of the example containing this feature, or -1 if we aren't doing per
 *        class feature counting.
 * @return A feature object appropriate for use as the key of a map.
 **/
protected Feature getArgumentKey(Feature f, Lexicon lexicon, boolean training, int label) {
  if (f.isDiscrete()) {
    if (!training)
      return f;
    if (!f.isPrimitive())
      f = f.getFeatureKey(lexicon, true, label);
  } else {
    f = f.getFeatureKey(lexicon, training, label);
    if (!training)
      return f;
  }
  return lexicon.getChildFeature(f, label);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

/**
 * A helper method for {@link #getFeatureKey(Lexicon,boolean,int)}, this method computes the
 * feature keys corresponding to the arguments of the conjunction. Here, we lookup the arguments
 * to the conjunction in the lexicon so that their counts are never less than the conjunction's,
 * and we return the actual feature object that's already a key in the lexicon.
 *
 * @param f The argument feature for which a key will be computed.
 * @param lexicon The lexicon into which this feature will be indexed.
 * @param label The label of the example containing this feature, or -1 if we aren't doing per
 *        class feature counting.
 * @return A feature object appropriate for use as the key of a map.
 **/
protected DiscreteFeature getArgumentKey(Feature f, Lexicon lexicon, int label) {
  if (!f.isPrimitive())
    f = f.getFeatureKey(lexicon, true, label);
  return (DiscreteFeature) lexicon.getChildFeature(f, label);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/saul

if (!(att.name().equals(f.toString()))) {
  System.err.println("WekaWrapper: Error - makeInstance encountered a misaligned "
      + "attribute-feature pair.");
  System.err.println("  " + att.name() + " and " + f.toString()
      + " should have been identical.");
  new Exception().printStackTrace();
  System.exit(1);
if (f.isDiscrete())
  inst.setValue(attIndex, "1"); // this feature is used in this example so we set it to "1"
else
if (!(label.getGeneratingClassifier().equals(((Attribute) attributeInfo.elementAt(0))
    .name()))) {
  System.err.println("WekaWrapper: Error - makeInstance found the wrong label name.");
if (!label.isDiscrete())
  inst.setValue(0, instance.labelValues[0]);
else
  inst.setValue(0, label.getStringValue());

代码示例来源:origin: CogComp/cogcomp-nlp

public FeatureVector classify(Object __example)
{
 if (!(__example instanceof Relation))
 {
  String type = __example == null ? "null" : __example.getClass().getName();
  System.err.println("Classifier 'combinedFeatures$$0(Relation)' defined on line 237 of extent.lbj received '" + type + "' as input.");
  new Exception().printStackTrace();
  System.exit(1);
 }
 FeatureVector __result;
 __result = new FeatureVector();
 FeatureVector leftVector = left.classify(__example);
 int N = leftVector.featuresSize();
 FeatureVector rightVector = right.classify(__example);
 int M = rightVector.featuresSize();
 for (int i = 0; i < N; ++i)
 {
  Feature lf = leftVector.getFeature(i);
  for (int j = 0; j < M; ++j)
  {
   Feature rf = rightVector.getFeature(j);
   if (lf.equals(rf)) continue;
   __result.addFeature(lf.conjunction(rf, this));
  }
 }
 __result.sort();
 return __result;
}

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

/** Returns a text representation of this lexicon (for debugging). */
public String toString() {
  StringBuffer result = new StringBuffer();
  for (int i = 0; i < lexiconInv.size(); ++i) {
    result.append(", ");
    result.append(i);
    result.append(": ");
    result.append(lexiconInv.get(i).toString());
  }
  if (lexiconInv.size() > 0)
    return result.substring(2);
  return result.toString();
}

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

Feature f = inverse.get(indexes[i]);
 previousClassName =
    f.lexWrite(out, this, previousClassName, previousPackage, previousClassifier,
        previousSIdentifier, previousBSIdentifier);
previousPackage = f.getPackage();
previousClassifier = f.getGeneratingClassifier();
if (f.hasStringIdentifier())
  previousSIdentifier = f.getStringIdentifier();
else if (f.hasByteStringIdentifier())
  previousBSIdentifier = f.getByteStringIdentifier();

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

for (int i = 0; i < N; ++i) {
  Feature f =
      Feature.lexReadFeature(in, this, previousClass, previousPackage,
          previousClassifier, previousSIdentifier, previousBSIdentifier);
  int index = in.readInt();
  lexiconInv.set(index, f);
  previousClass = f.getClass();
  previousPackage = f.getPackage();
  previousClassifier = f.getGeneratingClassifier();
  if (f.hasStringIdentifier())
    previousSIdentifier = f.getStringIdentifier();
  else if (f.hasByteStringIdentifier())
    previousBSIdentifier = f.getByteStringIdentifier();

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

/**
 * Take the dot product of two feature vectors.
 *
 * @param vector The feature vector to take the dot product with.
 * @return The dot product of this feature vector and <code>vector</code>.
 **/
public double dot(FeatureVector vector) {
  if (features.size() == 0 || vector.features.size() == 0)
    return 0;
  FVector v1 = (FVector) features.clone();
  FVector v2 = (FVector) vector.features.clone();
  v1.sort();
  v2.sort();
  double res = 0;
  int i = 0, j = 0;
  Feature f1 = v1.get(0);
  Feature f2 = v2.get(0);
  while (f1 != null && f2 != null) {
    if (f1.equals(f2)) {
      res += f1.getStrength() * f2.getStrength();
      f1 = v1.get(++i);
      f2 = v2.get(++j);
    } else if (f1.compareTo(f2) < 0)
      f1 = v1.get(++i);
    else
      f2 = v2.get(++j);
  }
  return res;
}

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

data[i][1] = featureCounts.get(i);
rowLabels[i] =
    p ? lexiconInv.get(i).toString() : lexiconInv.get(i).toStringNoPackage();
  data[i][j + 1] = perClassFeatureCounts.get(j, i);
rowLabels[i] =
    p ? lexiconInv.get(i).toString() : lexiconInv.get(i).toStringNoPackage();
data[i][0] = i;
rowLabels[i] =
    p ? lexiconInv.get(i).toString() : lexiconInv.get(i).toStringNoPackage();

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

if (label.isDiscrete())
    labelArray[f] = labelLexicon.lookup(label, true);
  else
    labelArray[f] = labelLexicon.lookup(label.getFeatureKey(labelLexicon), true);
  labelValues[f] += label.getStrength();
  createPrediction(labelArray[f]);
Feature feature = featureVector.getFeature(f);
exampleArrayFeatures[f] =
    lexicon.lookup(feature.getFeatureKey(lexicon, training, labelIndex), training,
        labelIndex);
exampleArrayValues[f] += feature.getStrength();

代码示例来源:origin: edu.illinois.cs.cogcomp/LBJava

/**
 * Return the feature that should be used to index this feature into a lexicon. This method
 * simply calls <code>getFeatureKey(lexicon, true,
 * -1)</code>.
 *
 * @see #getFeatureKey(Lexicon,boolean,int)
 * @param lexicon The lexicon into which this feature will be indexed.
 * @return A feature object appropriate for use as the key of a map.
 **/
public Feature getFeatureKey(Lexicon lexicon) {
  return getFeatureKey(lexicon, true, -1);
}

代码示例来源:origin: edu.illinois.cs.cogcomp/saul

} else {
  Feature label = labelLexicon.lookupKey(0);
  if (!label.isDiscrete()) {
    Attribute a = new Attribute(label.getStringIdentifier());
    attributeInfo.addElement(a);
  } else {
    FastVector valueVector = new FastVector(labelLexicon.size());
    for (int v = 0; v < labelLexicon.size(); v++)
      valueVector.addElement(labelLexicon.lookupKey(v).getStringValue());
    Attribute a = new Attribute(label.getGeneratingClassifier(), valueVector);
    attributeInfo.addElement(a);
for (int featureIndex = 0; featureIndex < lexicon.size(); ++featureIndex) {
  Feature f = lexicon.lookupKey(featureIndex);
  Attribute a = f.isDiscrete() ?
      new Attribute(f.toString(), binaryValues) :
      new Attribute(f.toString());

代码示例来源:origin: CogComp/cogcomp-nlp

public FeatureVector classify(Object __example)
{
 if (!(__example instanceof NEWord))
 {
  String type = __example == null ? "null" : __example.getClass().getName();
  System.err.println("Classifier 'FeaturesLevel2$$5(NEWord)' defined on line 521 of LbjTagger.lbj received '" + type + "' as input.");
  new Exception().printStackTrace();
  System.exit(1);
 }
 FeatureVector __result;
 __result = new FeatureVector();
 FeatureVector leftVector = left.classify(__example);
 int N = leftVector.featuresSize();
 FeatureVector rightVector = right.classify(__example);
 int M = rightVector.featuresSize();
 for (int i = 0; i < N; ++i)
 {
  Feature lf = leftVector.getFeature(i);
  for (int j = 0; j < M; ++j)
  {
   Feature rf = rightVector.getFeature(j);
   if (lf.equals(rf)) continue;
   __result.addFeature(lf.conjunction(rf, this));
  }
 }
 __result.sort();
 return __result;
}

代码示例来源:origin: CogComp/cogcomp-nlp

FeatureVector fv2 = features2.classify(w);
for (int k = 0; k < fv1.size(); k++) {
  String s = fv1.getFeature(k).toString();
  out.print(" " + s.substring(s.indexOf(':') + 1, s.length()));
  String s = fv2.getFeature(k).toString();
  out.print(" " + s.substring(s.indexOf(':') + 1, s.length()));

代码示例来源:origin: CogComp/cogcomp-nlp

f = f.getFeatureKey(lexicon, trainingMode, -1);

代码示例来源:origin: CogComp/cogcomp-nlp

public String discreteValue(Object __example) {
  if (!(__example instanceof Token)) {
    String type = __example == null ? "null" : __example.getClass().getName();
    System.err
        .println("Classifier 'labelTwoAfterU(Token)' defined on line 95 of POSUnknown.lbj received '"
            + type + "' as input.");
    new Exception().printStackTrace();
    System.exit(1);
  }
  return cachedFeatureValue(__example).getStringValue();
}

代码示例来源:origin: CogComp/cogcomp-nlp

public FeatureVector classify(Object __example)
{
 if (!(__example instanceof NEWord))
 {
  String type = __example == null ? "null" : __example.getClass().getName();
  System.err.println("Classifier 'FeaturesLevel1Only$$4(NEWord)' defined on line 370 of LbjTagger.lbj received '" + type + "' as input.");
  new Exception().printStackTrace();
  System.exit(1);
 }
 FeatureVector __result;
 __result = new FeatureVector();
 FeatureVector leftVector = left.classify(__example);
 int N = leftVector.featuresSize();
 FeatureVector rightVector = right.classify(__example);
 int M = rightVector.featuresSize();
 for (int i = 0; i < N; ++i)
 {
  Feature lf = leftVector.getFeature(i);
  for (int j = 0; j < M; ++j)
  {
   Feature rf = rightVector.getFeature(j);
   if (lf.equals(rf)) continue;
   __result.addFeature(lf.conjunction(rf, this));
  }
 }
 __result.sort();
 return __result;
}

相关文章