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


Java LabelSequence.add方法代码示例

本文整理汇总了Java中cc.mallet.types.LabelSequence.add方法的典型用法代码示例。如果您正苦于以下问题:Java LabelSequence.add方法的具体用法?Java LabelSequence.add怎么用?Java LabelSequence.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cc.mallet.types.LabelSequence的用法示例。


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

示例1: pipe

import cc.mallet.types.LabelSequence; //导入方法依赖的package包/类
public Instance pipe(Instance carrier)
{
  StringTokenization ts =  (StringTokenization) carrier.getData();
  StringTokenization newTs = new StringTokenization((CharSequence) ts.getDocument ());
   final LabelAlphabet dict = (LabelAlphabet) getTargetAlphabet();
   LabelSequence labelSeq = new LabelSequence(dict);
   Label start = dict.lookupLabel ("start");
   Label notstart = dict.lookupLabel ("notstart");

  boolean lastWasSpace = true;
  StringBuffer sb = new StringBuffer();
  for (int i = 0; i < ts.size(); i++) {
    StringSpan t = (StringSpan) ts.getSpan(i);
    if (t.getText().equals(" "))
      lastWasSpace = true;
    else {
      sb.append(t.getText());
      newTs.add(t);
      labelSeq.add(lastWasSpace ? "start" : "notstart");
      lastWasSpace = false;
    }
  }
  if (isTargetProcessing())
    carrier.setTarget(labelSeq);
  carrier.setData(newTs);
  carrier.setSource(sb.toString());
  return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:29,代码来源:TestMEMM.java

示例2: pipe

import cc.mallet.types.LabelSequence; //导入方法依赖的package包/类
@Override
public Instance pipe(Instance carrier) {
	String line = (String) carrier.getData();
	LabelAlphabet labels = (LabelAlphabet) getTargetAlphabet();
	TokenSequence ts = new TokenSequence();
	String[] tokens = line.split(" ");
	LabelSequence target = new LabelSequence(labels, tokens.length - 1);
	assert (tokens.length > 1);
	String prevTag = null;
	for (int i = 1; i < tokens.length; i++) {
		Matcher matcher = tokenPattern.matcher(tokens[i]);
		matcher.matches();
		String word = matcher.group(1);
		String tag = matcher.group(2);
		Token tok = new Token(word);
		tok.setFeatureValue(word, 1.0);
		ts.add(tok);
		String tmp = tag;
		if (targets.contains(tag)) {
			if (tag.equals(prevTag)) {
				tag = "I-GENE";
			} else {
				tag = "B-GENE";
			}
		} else {
			tag = "O";
		}
		target.add(tag);
		prevTag = tmp;
	}
	carrier.setData(ts);
	carrier.setTarget(target);
	return carrier;
}
 
开发者ID:siqil,项目名称:udaner,代码行数:35,代码来源:GenetagLine2TokenSequence.java

示例3: getStatistics

import cc.mallet.types.LabelSequence; //导入方法依赖的package包/类
private void getStatistics(CRF crf, Instance inst,
		Map<Instance, Double> entropyMap, Map<Instance, Double> probMap,
		boolean setTarget) {
	FeatureVectorSequence input = (FeatureVectorSequence) inst.getData();
	MaxLatticeDefault maxLattice = new MaxLatticeDefault(crf, input);
	Sequence output = maxLattice.bestOutputSequence();
	double labeled = new SumLatticeDefault(crf, input, output)
			.getTotalWeight();
	SumLattice lattice = new SumLatticeDefault(crf, input, true);
	double unlabeled = lattice.getTotalWeight();
	EntropyLattice entropyLattice = new EntropyLattice(input,
			lattice.getGammas(), lattice.getXis(), crf, null, 1);
	double entropy = -entropyLattice.getEntropy();
	double prob = Math.exp(labeled - unlabeled);
	entropyMap.put(inst, entropy);
	probMap.put(inst, prob);
	if (setTarget) {
		inst.unLock();
		int n = output.size();
		LabelSequence seq = new LabelSequence(
				(LabelAlphabet) crf.getOutputAlphabet(), n);
		for (int i = 0; i < output.size(); i++) {
			seq.add(output.get(i));
		}
		inst.setTarget(seq);
		inst.lock();
	}
}
 
开发者ID:siqil,项目名称:udaner,代码行数:29,代码来源:CRFTrainerByBootstrapping.java

示例4: TextInstance

import cc.mallet.types.LabelSequence; //导入方法依赖的package包/类
public TextInstance(TextSentence textSentence, Alphabet targetAlphabet) {
	super(new TokenSequence(), new LabelSequence(targetAlphabet), textSentence.getId(), textSentence);

	TokenSequence tokenSequence = (TokenSequence) getData();
	LabelSequence labelSequence = (LabelSequence) getTarget();

	for (TextToken textToken : textSentence) {
		String text = textToken.getText();
		String label = textToken.getTag();
		tokenSequence.add(new Token(text));
		labelSequence.add(label);
	}
}
 
开发者ID:jdmp,项目名称:java-data-mining-package,代码行数:14,代码来源:TextInstance.java


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