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


Java FeatureSequence.add方法代码示例

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


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

示例1: pipe

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
public Instance pipe(Instance carrier) {
	TokenSequence ts = (TokenSequence) carrier.getData();
	TokenSequence newTs = new TokenSequence();
	FeatureSequence labelSeq = new FeatureSequence(getTargetAlphabet());
	boolean lastWasSpace = true;
	StringBuffer sb = new StringBuffer();
	for (int i = 0; i < ts.size(); i++) {
		Token t = ts.get(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,代码行数:24,代码来源:TestCRF.java

示例2: testNewPutSizeFreeze

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
public void testNewPutSizeFreeze ()
{
	Alphabet dict = new Alphabet ();
	FeatureSequence fs = new FeatureSequence (dict, 10);
	fs.add (dict.lookupIndex ("apple"));
	fs.add (dict.lookupIndex ("bear"));
	fs.add (dict.lookupIndex ("car"));
	fs.add (dict.lookupIndex ("door"));
	assertTrue (fs.size() == 4);
	double[] weights = new double[4];
	fs.addFeatureWeightsTo (weights);
	assertTrue (weights[1] == 1.0);

	fs.add (dict.lookupIndex ("bear"));
	int[] feats = fs.toFeatureIndexSequence();
	assertTrue (feats[0] == 0);
	assertTrue (feats[1] == 1);
	assertTrue (feats[2] == 2);
	assertTrue (feats[3] == 3);
	assertTrue (feats[4] == 1);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:22,代码来源:TestFeatureSequence.java

示例3: setUp

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
protected void setUp ()
{
	dict = new Alphabet ();
	fs = new FeatureSequence (dict, 2);
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("n"));
	fs.add (dict.lookupIndex ("d"));
	fs.add (dict.lookupIndex ("r"));
	fs.add (dict.lookupIndex ("e"));
	fs.add (dict.lookupIndex ("w"));
	fs.add (dict.lookupIndex ("m"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("u"));
	fs.add (dict.lookupIndex ("m"));
	//System.out.println (fs.toString());
	fv = new FeatureVector (fs);
	//System.out.println (fs.toString());
	//System.out.println (fv.toString());
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:24,代码来源:TestFeatureVector.java

示例4: pipe

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier) {

		long start = System.nanoTime();

		try {
			ArrayList<String> tokens = (ArrayList<String>) carrier.getData();
			FeatureSequence featureSequence =
				new FeatureSequence ((Alphabet) getDataAlphabet(), tokens.size());
			for (int i = 0; i < tokens.size(); i++) {
				featureSequence.add (tokens.get(i));
			}
			carrier.setData(featureSequence);
			
			totalNanos += System.nanoTime() - start;
		} catch (ClassCastException cce) {
			System.err.println("Expecting ArrayList<String>, found " + carrier.getData().getClass());
		}

		return carrier;
	}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:21,代码来源:StringList2FeatureSequence.java

示例5: setUp

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
protected void setUp ()
{
	dict = new Alphabet ();
	fs = new FeatureSequence (dict, 2);
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("n"));
	fs.add (dict.lookupIndex ("d"));
	fs.add (dict.lookupIndex ("r"));
	fs.add (dict.lookupIndex ("e"));
	fs.add (dict.lookupIndex ("w"));
	fs.add (dict.lookupIndex ("m"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("u"));
	fs.add (dict.lookupIndex ("m"));
	fv = new FeatureVector (fs);
}
 
开发者ID:mimno,项目名称:Mallet,代码行数:21,代码来源:TestFeatureVector.java

示例6: randomFeatureSequence

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
public FeatureSequence randomFeatureSequence (Randoms r, int length)
{
	if (! (dictionary instanceof Alphabet))
		throw new UnsupportedOperationException
			("Multinomial's dictionary must be a Alphabet");
	FeatureSequence fs = new FeatureSequence ((Alphabet)dictionary, length);
	while (length-- > 0)
		fs.add (randomIndex (r));
	return fs;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:11,代码来源:Multinomial.java

示例7: testEstimating

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
public void testEstimating ()
{
	Alphabet dict = new Alphabet ();
	Multinomial.Estimator e = new Multinomial.LaplaceEstimator (dict);
	FeatureSequence fs = new FeatureSequence (dict);
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("n"));
	fs.add (dict.lookupIndex ("d"));
	fs.add (dict.lookupIndex ("r"));
	fs.add (dict.lookupIndex ("e"));
	fs.add (dict.lookupIndex ("w"));
	fs.add (dict.lookupIndex ("m"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("u"));
	fs.add (dict.lookupIndex ("m"));
	//System.out.println (fs.toString());
	e.increment (fs);
	assertTrue (e.size() == 10);

	Multinomial m = e.estimate ();
	assertTrue (m.size() == 10);
	assertTrue (m.probability (dict.lookupIndex ("a")) == (2.0+1)/(14.0+10));
	assertTrue (m.probability ("w") == (1.0+1)/(14.0+10));
	Multinomial.Logged ml = new Multinomial.Logged (m);
	assertTrue (m.logProbability ("w") == ml.logProbability ("w"));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:31,代码来源:TestMultinomial.java

示例8: convolution

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
/**
 * construct word co-occurrence features from the original sequence
 * do combinatoric,  n choose 2, can be extended to n choose 3
 
public void convolution() {
	int fi = -1;
	int pre = -1;
	int i,j;
	int curLen = length;
	for(i = 0; i < curLen-1; i++) {
		for(j = i + 1; j < curLen; j++) {
			pre = features[i];
			fi = features[j];
			Object preO = dictionary.lookupObject(pre);
			Object curO = dictionary.lookupObject(fi);
			Object coO = preO.toString() + "_" + curO.toString();
			add(coO);
		}
	}
}*/

public Instance pipe (Instance carrier)
{
	FeatureSequence fseq = (FeatureSequence) carrier.getData();
	FeatureSequence ret =
		new FeatureSequence ((Alphabet)getDataAlphabet());
	int i,j, curLen;
	curLen=fseq.getLength();
	//first add fseq to ret
	for(i = 0; i < curLen; i++) {
		ret.add(fseq.getObjectAtPosition(i));
	}
	//second word co-occurrence
	int pre, cur;
	Object coO;
	for(i = 0; i < curLen-1; i++) {
		for(j = i + 1; j < curLen; j++) {
			pre = fseq.getIndexAtPosition(i);
			cur = fseq.getIndexAtPosition(j);
			coO = pre + "_" + cur;
			ret.add(coO);
		}
	}
	if(carrier.isLocked()) {
		carrier.unLock();
	}
	carrier.setData(ret);
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:50,代码来源:FeatureSequenceConvolution.java

示例9: pipe

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
public Instance pipe (Instance carrier)
{
	TokenSequence ts = (TokenSequence) carrier.getData();
	FeatureSequence ret =
		new FeatureSequence ((Alphabet)getDataAlphabet(), ts.size());
	for (int i = 0; i < ts.size(); i++) {
		ret.add (ts.get(i).getText());
	}
	carrier.setData(ret);
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:TokenSequence2FeatureSequence.java

示例10: testEstimating

import cc.mallet.types.FeatureSequence; //导入方法依赖的package包/类
public void testEstimating ()
{
	Alphabet dict = new Alphabet ();
	Multinomial.Estimator e = new Multinomial.LaplaceEstimator (dict);
	FeatureSequence fs = new FeatureSequence (dict);
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("n"));
	fs.add (dict.lookupIndex ("d"));
	fs.add (dict.lookupIndex ("r"));
	fs.add (dict.lookupIndex ("e"));
	fs.add (dict.lookupIndex ("w"));
	fs.add (dict.lookupIndex ("m"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("c"));
	fs.add (dict.lookupIndex ("a"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("l"));
	fs.add (dict.lookupIndex ("u"));
	fs.add (dict.lookupIndex ("m"));
	e.increment (fs);
	assertTrue (e.size() == 10);

	Multinomial m = e.estimate ();
	assertTrue (m.size() == 10);
	assertTrue (m.probability (dict.lookupIndex ("a")) == (2.0+1)/(14.0+10));
	assertTrue (m.probability ("w") == (1.0+1)/(14.0+10));
	Multinomial.Logged ml = new Multinomial.Logged (m);
	assertTrue (m.logProbability ("w") == ml.logProbability ("w"));
}
 
开发者ID:mimno,项目名称:Mallet,代码行数:30,代码来源:TestMultinomial.java


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