本文整理汇总了Java中edu.umass.cs.mallet.base.types.Sequence类的典型用法代码示例。如果您正苦于以下问题:Java Sequence类的具体用法?Java Sequence怎么用?Java Sequence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sequence类属于edu.umass.cs.mallet.base.types包,在下文中一共展示了Sequence类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: averageTokenAccuracy
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public double averageTokenAccuracy (InstanceList ilist, String fileName)
{
double accuracy = 0;
PrintWriter out;
File f = new File(fileName);
try {
out = new PrintWriter(new FileWriter(f));
}
catch (IOException e) {
out = null;
}
for (int i = 0; i < ilist.size(); i++) {
Instance instance = ilist.getInstance(i);
Sequence input = (Sequence) instance.getData();
Sequence output = (Sequence) instance.getTarget();
assert (input.size() == output.size());
double pathAccuracy = viterbiPath(input).tokenAccuracy(output, out);
accuracy += pathAccuracy;
logger.info ("Transducer path accuracy = "+pathAccuracy);
}
out.close();
return accuracy/ilist.size();
}
开发者ID:clulab,项目名称:reach-banner,代码行数:24,代码来源:Transducer.java
示例2: tokenAccuracy
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public double tokenAccuracy (Sequence referenceOutput, PrintWriter out)
{
int accuracy = 0;
String testString;
assert (referenceOutput.size() == output.size());
for (int i = 0; i < output.size(); i++) {
//logger.fine("tokenAccuracy: ref: "+referenceOutput.get(i)+" viterbi: "+output.get(i));
testString = output.get(i).toString();
if (out != null) {
out.println(testString);
}
if (referenceOutput.get(i).toString().equals (testString)) {
accuracy++;
}
}
logger.info ("Number correct: " + accuracy + " out of " + output.size());
return ((double)accuracy)/output.size();
}
开发者ID:clulab,项目名称:reach-banner,代码行数:19,代码来源:Transducer.java
示例3: ViterbiPath_NBest
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
protected ViterbiPath_NBest (Sequence inputSequence, Sequence outputSequence, int N)
{
this.input = inputSequence;
this.providedOutput = outputSequence;
this.latticeLength = input.size()+1;
this.numStates = numStates();
//forward Viterbi
nodes = new ViterbiNode_NBest[latticeLength][numStates];
finalNodePredecessor = new ViterbiNode_NBest[numStates];// list of predecessors ranked according to final cost
NBestForwardViterbi(nodes, finalNodePredecessor, N);
//backward A* search
outputNBest = NBestBackwardASearch(N);
//combine the N best results, and produce a final output
combineNBest();
}
开发者ID:clulab,项目名称:reach-banner,代码行数:20,代码来源:Transducer.java
示例4: test
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public void test (Transducer crf, InstanceList data, String description, PrintStream viterbiOutputStream)
{
int correct = 0;
for (int i = 0; i < data.size(); i++) {
Instance instance = data.getInstance(i);
Sequence input = (Sequence) instance.getData();
Sequence trueOutput = (Sequence) instance.getTarget();
assert (input.size() == trueOutput.size());
Sequence predOutput = crf.transduce (input);
assert (predOutput.size() == trueOutput.size());
if (sequencesMatch (trueOutput, predOutput))
correct++;
}
double acc = ((double)correct) / data.size();
logger.info (description+" Num instances = "+data.size()+" Num correct = "+correct);
logger.info (description+" Per-instance accuracy = "+acc);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:18,代码来源:InstanceAccuracyEvaluator.java
示例5: addSpansFromTags
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
private void addSpansFromTags (LabeledSpans labeled, Tokenization input, Sequence tags, LabelAlphabet dict,
Label backgroundTag)
{
int i = 0;
int docidx = 0;
while (i < tags.size()) {
Label thisTag = dict.lookupLabel (tags.get(i).toString());
int startTokenIdx = i;
while (i < tags.size()) {
Label nextTag = dict.lookupLabel (tags.get(i).toString ());
if (thisTag != nextTag) break;
i++;
}
int endTokenIdx = i;
Span span = input.subspan(startTokenIdx, endTokenIdx);
addBackgroundIfNecessary (labeled, (StringSpan) span, docidx, backgroundTag);
docidx = ((StringSpan) span).getEndIdx ();
labeled.add (new LabeledSpan (span, thisTag, thisTag == backgroundTag));
}
}
开发者ID:clulab,项目名称:reach-banner,代码行数:21,代码来源:DefaultTokenizationFilter.java
示例6: addSpansFromTags
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
private void addSpansFromTags (LabeledSpans labeled, Tokenization input, Sequence tags, LabelAlphabet dict,
Label backgroundTag)
{
int i = 0;
int docidx = 0;
while (i < tags.size ()) {
Label thisTag = dict.lookupLabel (tags.get (i).toString ());
int startTokenIdx = i;
while (++i < tags.size ()) {
Label nextTag = dict.lookupLabel (tags.get (i).toString ());
if (isBeginTag (nextTag) || !tagsMatch (thisTag, nextTag)) break;
}
int endTokenIdx = i;
Span span = createSpan (input, startTokenIdx, endTokenIdx);
addBackgroundIfNecessary (labeled, (StringSpan) span, docidx, backgroundTag);
docidx = ((StringSpan) span).getEndIdx ();
if (isBeginTag (thisTag) || isInsideTag (thisTag)) {
thisTag = trimTag (dict, thisTag);
}
labeled.add (new LabeledSpan (span, thisTag, thisTag == backgroundTag));
}
}
开发者ID:clulab,项目名称:reach-banner,代码行数:24,代码来源:BIOTokenizationFilter.java
示例7: getPositionsAndTypes
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
private void getPositionsAndTypes(Sentence sentence, TagPosition[] positions, MentionType[] types, boolean reverse)
{
Instance instance = new Instance(sentence.getTrainingText(format, reverse), null, sentence.getTag(), null, forwardCRF.getInputPipe());
Sequence tags = forwardCRF.viterbiPath((Sequence)instance.getData()).output();
if (positions.length != tags.size())
throw new IllegalArgumentException();
if (types.length != tags.size())
throw new IllegalArgumentException();
for (int i = 0; i < tags.size(); i++)
{
// The tag string is e.g. "O" or "B-GENE"
String[] split = tags.get(i).toString().split("-");
positions[i] = TagPosition.valueOf(split[0]);
// TODO Verify that the type stays the same
if (split.length == 2)
types[i] = MentionType.getType(split[1]);
}
if (reverse)
{
reverse(positions);
reverse(types);
}
}
开发者ID:leebird,项目名称:legonlp,代码行数:24,代码来源:CRFTagger.java
示例8: forwardBackward
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public Lattice forwardBackward (Sequence inputSequence, Sequence outputSequence, boolean increment,
boolean saveXis, LabelAlphabet outputAlphabet)
{
// xxx We don't do epsilon transitions for now
assert (outputSequence == null
|| inputSequence.size() == outputSequence.size());
return new Lattice (inputSequence, outputSequence, increment, saveXis, outputAlphabet);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:9,代码来源:Transducer.java
示例9: forwardBackwardBeam
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public BeamLattice forwardBackwardBeam (Sequence inputSequence, Sequence outputSequence, boolean increment,
boolean saveXis, LabelAlphabet outputAlphabet)
{
// xxx We don't do epsilon transitions for now
assert (outputSequence == null
|| inputSequence.size() == outputSequence.size());
return new BeamLattice (inputSequence, outputSequence, increment, saveXis, outputAlphabet);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:9,代码来源:Transducer.java
示例10: viterbiPath
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public ViterbiPath viterbiPath (Sequence inputSequence, Sequence outputSequence)
{
// xxx We don't do epsilon transitions for now
assert (outputSequence == null
|| inputSequence.size() == outputSequence.size());
return new ViterbiPath (inputSequence, outputSequence);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:8,代码来源:Transducer.java
示例11: viterbiPath_NBest
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public ViterbiPath_NBest viterbiPath_NBest (Sequence inputSequence, Sequence outputSequence, int N)
{
// xxx We don't do epsilon transitions for now
assert (outputSequence == null
|| inputSequence.size() == outputSequence.size());
assert(N > 0);
return new ViterbiPath_NBest (inputSequence, outputSequence, N);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:9,代码来源:Transducer.java
示例12: viterbiPathBeam
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public ViterbiPathBeam viterbiPathBeam (Sequence inputSequence, Sequence outputSequence, int Bwidth)
{
// xxx We don't do epsilon transitions for now
assert (outputSequence == null
|| inputSequence.size() == outputSequence.size());
return new ViterbiPathBeam (inputSequence, outputSequence, Bwidth);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:8,代码来源:Transducer.java
示例13: viterbiPathBeamKL
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public ViterbiPathBeamKL viterbiPathBeamKL (Sequence inputSequence, Sequence outputSequence, int Bwidth)
{
// xxx We don't do epsilon transitions for now
assert (outputSequence == null
|| inputSequence.size() == outputSequence.size());
return new ViterbiPathBeamKL (inputSequence, outputSequence, Bwidth);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:8,代码来源:Transducer.java
示例14: viterbiPathBeamB
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public ViterbiPathBeamB viterbiPathBeamB (Sequence inputSequence, Sequence outputSequence, int Bwidth)
{
// xxx We don't do epsilon transitions for now
assert (outputSequence == null
|| inputSequence.size() == outputSequence.size());
return new ViterbiPathBeamB (inputSequence, outputSequence, Bwidth);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:8,代码来源:Transducer.java
示例15: viterbiPathBeamFB
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public ViterbiPathBeamFB viterbiPathBeamFB (Sequence inputSequence, Sequence outputSequence, int Bwidth)
{
// xxx We don't do epsilon transitions for now
assert (outputSequence == null
|| inputSequence.size() == outputSequence.size());
return new ViterbiPathBeamFB (inputSequence, outputSequence, Bwidth);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:8,代码来源:Transducer.java
示例16: outputNBest
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public Sequence[] outputNBest(int n) {
int numFinal = 0;
for (int i = 0; i < numStates(); i++) {
if (lattice[latticeLength-1][i] != null && lattice[latticeLength-1][i].delta < INFINITE_COST)
numFinal++;
}
ViterbiNode[] finalNodes = new ViterbiNode[numFinal];
int f = 0;
for (int i = 0; i < numStates(); i++) {
if (lattice[latticeLength-1][i] != null && lattice[latticeLength-1][i].delta < INFINITE_COST)
finalNodes[f++] = lattice[latticeLength-1][i];
}
AStar search = new AStar(finalNodes, latticeLength * numStates());
List outputs = new ArrayList(n);
for (int i = 0; i < n && search.hasNext(); i++) {
SearchNode ans = (SearchNode)search.next();
Object[] seq = new Object[input.size()];
ans = ans.getParent(); // this corresponds to the Viterbi node after the first transition
for (int j = 0; j < input.size(); j++) {
ViterbiNode v = (ViterbiNode)ans.getState();
assert(v.inputPosition == j + 1);
seq[j] = v.output;
ans = ans.getParent();
}
outputs.add(new ArraySequence(seq, false));
}
return (Sequence [])outputs.toArray(new Sequence[] {});
}
开发者ID:clulab,项目名称:reach-banner,代码行数:29,代码来源:Transducer.java
示例17: sequencesMatch
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
private boolean sequencesMatch (Sequence trueOutput, Sequence predOutput)
{
for (int j = 0; j < trueOutput.size(); j++) {
Object tru = trueOutput.get(j);
Object pred = predOutput.get(j);
if (!tru.toString().equals (pred.toString())) {
return false;
}
}
return true;
}
开发者ID:clulab,项目名称:reach-banner,代码行数:12,代码来源:InstanceAccuracyEvaluator.java
示例18: transitionIterator
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public Transducer.TransitionIterator transitionIterator (Sequence input,
int inputPosition,
Sequence output,
int outputPosition)
{
if (inputPosition < 0 || outputPosition < 0 || output != null)
throw new UnsupportedOperationException ("Not yet implemented.");
if (input == null)
return transitionIterator ();
else
return transitionIterator (input, inputPosition);
}
开发者ID:clulab,项目名称:reach-banner,代码行数:13,代码来源:FeatureTransducer.java
示例19: ArraySequence
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
protected ArraySequence (Sequence s, boolean copy)
{
if (s instanceof ArraySequence) {
if (copy) {
data = new Object[s.size()];
System.arraycopy (((ArraySequence)s).data, 0, data, 0, data.length);
} else
data = ((ArraySequence)s).data;
} else {
data = new Object[s.size()];
for (int i = 0; i < s.size(); i++)
data[i] = s.get(i);
}
}
开发者ID:clulab,项目名称:reach-banner,代码行数:15,代码来源:ArraySequence.java
示例20: constructLabeledSpans
import edu.umass.cs.mallet.base.types.Sequence; //导入依赖的package包/类
public LabeledSpans constructLabeledSpans (LabelAlphabet dict, Object document, Label backgroundTag,
Tokenization input, Sequence seq)
{
LabeledSpans labeled = new LabeledSpans (document);
addSpansFromTags (labeled, input, seq, dict, backgroundTag);
return labeled;
}
开发者ID:clulab,项目名称:reach-banner,代码行数:8,代码来源:DefaultTokenizationFilter.java
注:本文中的edu.umass.cs.mallet.base.types.Sequence类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论