当前位置: 首页>>代码示例>>Java>>正文


Java FeatureFactory类代码示例

本文整理汇总了Java中edu.stanford.nlp.sequences.FeatureFactory的典型用法代码示例。如果您正苦于以下问题:Java FeatureFactory类的具体用法?Java FeatureFactory怎么用?Java FeatureFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FeatureFactory类属于edu.stanford.nlp.sequences包,在下文中一共展示了FeatureFactory类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadClassifier

import edu.stanford.nlp.sequences.FeatureFactory; //导入依赖的package包/类
/** Load a classifier from the given Stream.
 *  <i>Implementation note: </i> This method <i>does not</i> close the
 *  Stream that it reads from.
 *
 *  @param ois The ObjectInputStream to load the serialized classifier from
 *
 *  @throws IOException If there are problems accessing the input stream
 *  @throws ClassCastException If there are problems interpreting the serialized data
 *  @throws ClassNotFoundException If there are problems interpreting the serialized data

 *  */
@SuppressWarnings("unchecked")
@Override
public void loadClassifier(ObjectInputStream ois, Properties props) throws ClassCastException, IOException, ClassNotFoundException {
  classifier = (LinearClassifier<String, String>) ois.readObject();
  flags = (SeqClassifierFlags) ois.readObject();
  featureFactory = (FeatureFactory) ois.readObject();

  if (props != null) {
    flags.setProperties(props);
  }
  reinit();

  classIndex = (Index<String>) ois.readObject();
  answerArrays = (Set<List<String>>) ois.readObject();

  knownLCWords = (Set<String>) ois.readObject();
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:29,代码来源:CMMClassifier.java

示例2: makeDatum

import edu.stanford.nlp.sequences.FeatureFactory; //导入依赖的package包/类
@Override
public CRFDatum<List<String>, CRFLabel> makeDatum(List<IN> info, int loc, FeatureFactory<IN> featureFactory) {

  pad.set(CoreAnnotations.AnswerAnnotation.class, flags.backgroundSymbol);
  PaddedList<IN> pInfo = new PaddedList<IN>(info, pad);

  List<List<String>> features = new ArrayList<List<String>>();
  Collection<Clique> done = Generics.newHashSet();
  for (int i = 0; i < windowSize; i++) {
    List<String> featuresC = new ArrayList<String>();
    List<Clique> windowCliques = featureFactory.getCliques(i, 0);
    windowCliques.removeAll(done);
    done.addAll(windowCliques);
    for (Clique c : windowCliques) {
      featuresC.addAll(featureFactory.getCliqueFeatures(pInfo, loc, c));
      if(testTime && i==0)
        // this feature is only present at test time and only appears
        // in cliques of size 1 (i.e., cliques with window=0)
        featuresC.add(BIAS);
    }
    features.add(featuresC);
  }

  int[] labels = new int[windowSize];
  for (int i = 0; i < windowSize; i++) {
    String answer = pInfo.get(loc + i - windowSize + 1).get(CoreAnnotations.AnswerAnnotation.class);
    labels[i] = classIndex.indexOf(answer);
  }

  return new CRFDatum<List<String>, CRFLabel>(features, new CRFLabel(labels), null);
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:32,代码来源:CRFBiasedClassifier.java

示例3: addOtherClasses

import edu.stanford.nlp.sequences.FeatureFactory; //导入依赖的package包/类
/** This adds to the feature name the name of classes that are other than
 *  the current class that are involved in the clique.  In the CMM, these
 *  other classes become part of the conditioning feature, and only the
 *  class of the current position is being predicted.
 *
 *  @return A collection of features with extra class information put
 *          into the feature name.
 */
private static Collection<String> addOtherClasses(Collection<String> feats, List<? extends CoreLabel> info,
                                   int loc, Clique c) {
  String addend = null;
  String pAnswer = info.get(loc - 1).get(CoreAnnotations.AnswerAnnotation.class);
  String p2Answer = info.get(loc - 2).get(CoreAnnotations.AnswerAnnotation.class);
  String p3Answer = info.get(loc - 3).get(CoreAnnotations.AnswerAnnotation.class);
  String p4Answer = info.get(loc - 4).get(CoreAnnotations.AnswerAnnotation.class);
  String p5Answer = info.get(loc - 5).get(CoreAnnotations.AnswerAnnotation.class);
  String nAnswer = info.get(loc + 1).get(CoreAnnotations.AnswerAnnotation.class);
  // cdm 2009: Is this really right? Do we not need to differentiate names that would collide???
  if (c == FeatureFactory.cliqueCpC) {
    addend = '|' + pAnswer;
  } else if (c == FeatureFactory.cliqueCp2C) {
    addend = '|' + p2Answer;
  } else if (c == FeatureFactory.cliqueCp3C) {
    addend = '|' + p3Answer;
  } else if (c == FeatureFactory.cliqueCp4C) {
    addend = '|' + p4Answer;
  } else if (c == FeatureFactory.cliqueCp5C) {
    addend = '|' + p5Answer;
  } else if (c == FeatureFactory.cliqueCpCp2C) {
    addend = '|' + pAnswer + '-' + p2Answer;
  } else if (c == FeatureFactory.cliqueCpCp2Cp3C) {
    addend = '|' + pAnswer + '-' + p2Answer + '-' + p3Answer;
  } else if (c == FeatureFactory.cliqueCpCp2Cp3Cp4C) {
    addend = '|' + pAnswer + '-' + p2Answer + '-' + p3Answer + '-' + p4Answer;
  } else if (c == FeatureFactory.cliqueCpCp2Cp3Cp4Cp5C) {
    addend = '|' + pAnswer + '-' + p2Answer + '-' + p3Answer + '-' + p4Answer + '-' + p5Answer;
  } else if (c == FeatureFactory.cliqueCnC) {
    addend = '|' + nAnswer;
  } else if (c == FeatureFactory.cliqueCpCnC) {
    addend = '|' + pAnswer + '-' + nAnswer;
  }
  if (addend == null) {
    return feats;
  }
  Collection<String> newFeats = Generics.newHashSet();
  for (String feat : feats) {
    String newFeat = feat + addend;
    newFeats.add(newFeat);
  }
  return newFeats;
}
 
开发者ID:paulirwin,项目名称:Stanford.NER.Net,代码行数:52,代码来源:CMMClassifier.java


注:本文中的edu.stanford.nlp.sequences.FeatureFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。