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


Java ClassLabel类代码示例

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


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

示例1: createExample

import edu.cmu.minorthird.classify.ClassLabel; //导入依赖的package包/类
/**
 * Creates an edu.cmu.minorthird.classify.Example object from one line
 * of a dataset file using {@link #createInstance(String, String)}.
 * 
 * @param datasetLine the line from the dataset file from which to create
 * the Example 
 * @return the Example created
 * @throws Exception
 */
public Example[] createExample(String datasetLine) throws Exception {
    Matcher m=datasetExamplePattern.matcher(datasetLine);

    if (!m.matches()) 
        throw new Exception("Malformed dataset line:\n"+datasetLine);

    String[] aTypes = null;

    aTypes = m.group(labelPosition)
                .replaceAll(",$", "")   
                .replaceAll(",", ".")
                .split("\\|");
    String question = m.group(questionPosition);
    String sentParse = null;
    if (parsePosition > -1) sentParse = m.group(parsePosition);

    Instance instance = createInstance(question,sentParse);

    Example[] result = new Example[aTypes.length];

    //create example(s) and add it to list
    for(int i=0;i<aTypes.length;i++){
        String newATypeName=HierarchicalClassifier.getHierarchicalClassName(aTypes[i],classLevels,useClassLevels);
        result[i] = new Example(instance,new ClassLabel(newATypeName));
    }
    return result;
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:37,代码来源:FeatureExtractor.java

示例2: classification

import edu.cmu.minorthird.classify.ClassLabel; //导入依赖的package包/类
public ClassLabel classification(Instance instance){
	String labelName="";
	double weight=1;
	for(int i=0;i<classLevels;i++){
		Classifier currentClassifier=(Classifier)classifiers.get(labelName);
		ClassLabel currentLabel=currentClassifier.classification(instance);
		labelName=getNewLabelName(labelName,currentLabel.bestClassName(),i);
		weight*=currentLabel.bestWeight();
	}
	return new ClassLabel(labelName,weight);
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:12,代码来源:HierarchicalClassifier.java

示例3: explain

import edu.cmu.minorthird.classify.ClassLabel; //导入依赖的package包/类
public String explain(Instance instance){
	String labelName="";
	String explanation="";
	for(int i=0;i<classLevels;i++){
		Classifier currentClassifier=(Classifier)classifiers.get(labelName);
		ClassLabel currentLabel=currentClassifier.classification(instance);
		labelName=getNewLabelName(labelName,currentLabel.bestClassName(),i);
		explanation+=currentClassifier.explain(instance);
	}
	return explanation;
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:12,代码来源:HierarchicalClassifier.java

示例4: addExample

import edu.cmu.minorthird.classify.ClassLabel; //导入依赖的package包/类
public void addExample(Example example){
	for(int i=0;i<prototypes.length;i++){
		String labelName=example.getLabel().bestClassName();
		String prefix=getLabelPrefix(labelName,i);
		String sublabel=getSublabel(labelName,i);
		Example subExample=new Example(example.asInstance(),new ClassLabel(sublabel));
		ClassifierLearner subLearner=classifierLearners.get(prefix);
		subLearner.addExample(subExample);
	}
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:11,代码来源:HierarchicalClassifierLearner.java

示例5: classify

import edu.cmu.minorthird.classify.ClassLabel; //导入依赖的package包/类
public List<AnswerType> classify(Instance instance) {
    List<AnswerType> res = new ArrayList<AnswerType>();
    ClassLabel label = null;
    synchronized (classifier) {
        label = classifier.classification(instance);
    }
    String labelStr = label.bestClassName().replaceAll("-",".");
    AnswerType atype = AnswerType.constructFromString(labelStr);
    double weight = label.bestWeight();
    if (weight > 1.0) weight = (1 - (1 / weight));
    atype.setConfidence(weight);
    res.add(atype);
    return res;
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:15,代码来源:TrainedQuestionClassifier.java

示例6: createExample

import edu.cmu.minorthird.classify.ClassLabel; //导入依赖的package包/类
/**
 * Creates a training/evaluation example from a judged answer candidate.
 * 
 * @param features selected features
 * @param result judged answer candidate
 * @param results all answers to the question
 * @param qid question ID
 * @return training/evaluation example
 */
private static Example createExample(String[] features, Result result,
		Result[] results, String qid) {
	// create instance with selected features
	Instance instance = createInstance(features, result, results, qid);
	
	// create example from the instance and its class label
	String label = result.isCorrect()
			? ExampleSchema.POS_CLASS_NAME
			: ExampleSchema.NEG_CLASS_NAME;
	Example example = new Example(instance, new ClassLabel(label));
	
	return example;
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:23,代码来源:ScoreNormalizationFilter.java

示例7: apply

import edu.cmu.minorthird.classify.ClassLabel; //导入依赖的package包/类
/**
	 * Normalizes the scores of the factoid answers, using the features
	 * specified in <code>SELECTED_FEATURES</code> and the classifier specified
	 * in <code>classifier</code>.
	 * 
	 * @param results array of <code>Result</code> objects
	 * @return array of <code>Result</code> objects with normalized scores
	 */
	public Result[] apply(Result[] results) {
		if (classifier == null) return results;  // classifier not loaded
		
		for (Result result : results) {
			// only factoid answers with 1 extraction technique
			if (result.getScore() <= 0 ||
					result.getScore() == Float.POSITIVE_INFINITY ||
					result.getExtractionTechniques() == null ||
					result.getExtractionTechniques().length != 1)
				continue;
			
			// create instance with selected features
	        Instance instance = createInstance(SELECTED_FEATURES, result,
	        		results);
	        // classify instance
	        ClassLabel label = classifier.classification(instance);
	        // get weight of positive class as result score
	        double weight = label.posProbability();
	        result.setNormScore((float) weight);
		}
		
		// preserve original order of results
//		results = preserveOrderResorting(results);
//		results = preserveOrderAveraging(results);
		results = preserveOrderTop(results);
		
//		for (Result result : results) result.setScore(result.getNormScore());
		
		return results;
	}
 
开发者ID:claritylab,项目名称:lucida,代码行数:39,代码来源:ScoreNormalizationFilter.java

示例8: parse

import edu.cmu.minorthird.classify.ClassLabel; //导入依赖的package包/类
/**
   * extract the entities, and put them into the tweet. return them also.
   */
  public List<LocEntityAnnotation> parse(Tweet tweet) {
    tweetSentence = tweet.getSentence();
    EuroLangTwokenizer.tokenize(tweetSentence);
    examples = new Example[tweet.getSentence().tokenLength()];

    List<Feature[]> feature_instances;
    if (fg instanceof FineFeatureGenerator )
    {
      feature_instances = ((FineFeatureGenerator)fg).extractFeature(tweetSentence);
      examples = new Example[feature_instances.size()];

    }
    else{
      
      feature_instances = fg.extractFeature(tweetSentence);

    }    
    if (feature_instances ==null || feature_instances.size()==0)
      return null;

    for (int i = 0; i < examples.length; i++) {

      ClassLabel label = new ClassLabel("NA");
      MutableInstance instance = new MutableInstance("0", Integer.toString(i));
      Feature[] features = feature_instances.get(i);

      for (int j = 0; j < features.length; j++) {
        instance.addBinary(features[j]);
      }
      examples[i] = new Example(instance, label);
      // System.out.println(examples[i].toString());
    }
    ClassLabel[] resultlabels = model.classification(examples);
    /*
     * for (int i = 0; i < resultlabels.length; i++) {
     * System.out.print(resultlabels[i].bestClassName() + " "); }
     */
    List<LocEntityAnnotation> locs = new ArrayList<LocEntityAnnotation>();

    /**
     * rewrite the loc-entity generation, to support positions.
     */
    int startpos = -1, endpos = -1;
    String current = "O", previous = "O";
    for (int k = 0; k < resultlabels.length; k++) {
      if (k > 0)
        previous = current;
      current = resultlabels[k].bestClassName();
      if (current.equals("O"))
        if (previous.equals("O"))
          continue;
        else {
          endpos = k - 1;
//          System.out.println(startpos + " " + endpos + " " + previous);
          Token[] t = new Token[endpos - startpos + 1];
          for (int i = startpos; i <= endpos; i++) {
            t[i - startpos] = tweet.getSentence().getTokens()[i].setNE(previous);
          }
          LocEntityAnnotation le = new LocEntityAnnotation(startpos, endpos, previous, t);
          
          // set the probability of the NE type
          // This may be changed later.
          le.setNETypeProb(0.95);
          
          locs.add(le);
        }
      else if (previous.equals("O"))
        startpos = k;
      else
        endpos = k;

    }
    return locs;
  }
 
开发者ID:weizh,项目名称:geolocator-3.0,代码行数:78,代码来源:MTNERParser.java

示例9: classification

import edu.cmu.minorthird.classify.ClassLabel; //导入依赖的package包/类
public ClassLabel classification(Instance instance){
	return new ClassLabel(soleLabelName);
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:4,代码来源:DummyClassifier.java


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