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