本文整理汇总了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;
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
示例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"));
}
示例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;
}
示例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;
}
示例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"));
}