本文整理汇总了Java中cc.mallet.types.Label类的典型用法代码示例。如果您正苦于以下问题:Java Label类的具体用法?Java Label怎么用?Java Label使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Label类属于cc.mallet.types包,在下文中一共展示了Label类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupLabel2Var
import cc.mallet.types.Label; //导入依赖的package包/类
private void setupLabel2Var ()
{
idx2var = new Variable [lblseq.size ()][];
var2label = new THashMap ();
for (int t = 0; t < lblseq.size (); t++) {
Labels lbls = lblseq.getLabels (t);
idx2var[t] = new Variable [lbls.size ()];
for (int j = 0; j < lbls.size (); j++) {
Label lbl = lbls.get (j);
Variable var = new Variable (lbl.getLabelAlphabet ());
var.setLabel ("I"+id+"_VAR[f=" + j + "][tm=" + t + "]");
idx2var[t][j] = var;
var2label.put (var, lbl);
}
}
}
示例2: toLabelsSequence
import cc.mallet.types.Label; //导入依赖的package包/类
public LabelsSequence toLabelsSequence (Assignment assn)
{
int numFactors = numSlices ();
int maxTime = maxTime ();
Labels[] lbls = new Labels [maxTime];
for (int t = 0; t < maxTime; t++) {
Label[] theseLabels = new Label [numFactors];
for (int i = 0; i < numFactors; i++) {
Variable var = varOfIndex (t, i);
int maxidx;
if (var != null) {
maxidx = assn.get (var);
} else {
maxidx = 0;
}
LabelAlphabet dict = labelOfVar (var).getLabelAlphabet ();
theseLabels[i] = dict.lookupLabel (maxidx);
}
lbls[t] = new Labels (theseLabels);
}
return new LabelsSequence (lbls);
}
示例3: serializeObject
import cc.mallet.types.Label; //导入依赖的package包/类
/** Serializes a single object without metadata
* @param out
* @param object
* @throws IOException
*/
private void serializeObject (ObjectOutputStream out, Object obj)
throws IOException {
if (obj instanceof FeatureVector) {
FeatureVector features = (FeatureVector) obj;
out.writeChar (TYPE_FEATURE_VECTOR);
out.writeObject (features.getIndices ());
out.writeObject (features.getValues ());
}
else if (obj instanceof Label) {
out.writeChar (TYPE_LABEL);
out.writeObject (((Label) obj).toString ());
} else {
out.writeChar (TYPE_OBJECT);
out.writeObject (obj);
}
}
示例4: getRank
import cc.mallet.types.Label; //导入依赖的package包/类
public int getRank (Label label)
{
//throw new UnsupportedOperationException ();
// CPAL - Implemented this
if (rankOrder == null)
setRankOrder();
int ii=-1;
int tmpIndex = ((LabelAlphabet)dictionary).lookupIndex(label.entry);
// Now find this index in the ordered list with a linear search
for(ii=0; ii<rankOrder.length ; ii++) {
if (rankOrder[ii] == tmpIndex)
break;
}
// CPAL if ii == -1 we have a problem
return ii;
}
示例5: getPrecisionForScore
import cc.mallet.types.Label; //导入依赖的package包/类
/**
* Gets the precision for a specified label and score. This differs from
* {@link ROCData.getPrecision(Label, double)} in that it is the precision
* for only scores falling in the one score value, not for all scores
* above the threshold.
*
* If data was not collected for the exact threshold specified, then results
* will for the highest threshold <= the specified threshold will be
* returned.
*
* @param label Label to get precision for
* @param threshold Threshold to get precision for
* @return Precision for specified label and score
*/
public double getPrecisionForScore(Label label, double score) {
final int[][] buckets = this.counts[label.getIndex()];
int index = Arrays.binarySearch(this.thresholds, score);
if (index < 0) {
index = (-index) - 2;
}
final double tp;
final double fp;
if (index == this.thresholds.length - 1) {
tp = buckets[index][TRUE_POSITIVE];
fp = buckets[index][FALSE_POSITIVE];
} else {
tp = buckets[index][TRUE_POSITIVE] - buckets[index + 1][TRUE_POSITIVE];
fp = buckets[index][FALSE_POSITIVE] - buckets[index + 1][FALSE_POSITIVE];
}
return (double) tp / (double) (tp + fp);
}
示例6: setCounts
import cc.mallet.types.Label; //导入依赖的package包/类
/**
* Sets the raw counts for a specified label and threshold.
*
* If data is not collected for the exact threshold specified, then counts
* for the highest threshold <= the specified threshold will be set.
*
* @param label Label to get counts for
* @param threshold Threshold to get counts for
* @param newCounts New count values for the label and threshold
* @see #TRUE_POSITIVE
* @see #FALSE_POSITIVE
* @see #FALSE_NEGATIVE
* @see #TRUE_NEGATIVE
*/
public void setCounts(Label label, double threshold, int[] newCounts) {
int index = Arrays.binarySearch(this.thresholds, threshold);
if (index < 0) {
index = (-index) - 2;
}
final int[] oldCounts = this.counts[label.getIndex()][index];
if (newCounts.length != oldCounts.length) {
throw new IllegalArgumentException ("Array of counts must contain " + oldCounts.length + " elements.");
}
for (int i = 0; i < oldCounts.length; i++) {
oldCounts[i] = newCounts[i];
}
}
示例7: testSerializable
import cc.mallet.types.Label; //导入依赖的package包/类
public void testSerializable () throws IOException, ClassNotFoundException
{
LabelAlphabet dict = new LabelAlphabet ();
Labels lbls1 = new Labels (new Label[] {
dict.lookupLabel ("A"),
dict.lookupLabel ("B"),
});
Labels lbls2 = new Labels (new Label[] {
dict.lookupLabel ("C"),
dict.lookupLabel ("A"),
});
LabelsSequence lblseq = new LabelsSequence (new Labels[] { lbls1, lbls2 });
LabelsSequence lblseq2 = (LabelsSequence) TestSerializable.cloneViaSerialization (lblseq);
assertEquals (lblseq.size(), lblseq2.size());
assertEquals (lblseq.getLabels(0).toString(), lblseq2.getLabels(0).toString ());
assertEquals (lblseq.getLabels(1).toString(), lblseq2.getLabels(1).toString ());
}
示例8: testReadResolve
import cc.mallet.types.Label; //导入依赖的package包/类
/** Tests how serializing labels separately can lead to big losses.
* This currently fails. I'm not sure what to do about this. -cas
*/
public void testReadResolve () throws IOException, ClassNotFoundException
{
LabelAlphabet dict = new LabelAlphabet ();
dict.lookupIndex ("TEST1");
dict.lookupIndex ("TEST2");
dict.lookupIndex ("TEST3");
Label t1 = dict.lookupLabel ("TEST1");
Labelee l = new Labelee (dict, t1);
Labelee l2 = (Labelee) TestSerializable.cloneViaSerialization (l);
assertTrue (l.dict == l2.dict);
assertTrue (dict.lookupLabel("TEST1") == l.theLabel);
assertTrue (dict.lookupLabel("TEST1") == l2.theLabel);
assertTrue (l.theLabel == l2.theLabel);
}
示例9: addSpansFromTags
import cc.mallet.types.Label; //导入依赖的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));
}
}
示例10: testToXml
import cc.mallet.types.Label; //导入依赖的package包/类
public void testToXml () {
LabelAlphabet dict = new LabelAlphabet ();
String document = "the quick brown fox leapt over the lazy dog";
StringTokenization toks = new StringTokenization (document, new CharSequenceLexer ());
Label O = dict.lookupLabel ("O");
Label ANML = dict.lookupLabel ("ANIMAL");
Label VB = dict.lookupLabel ("VERB");
LabelSequence tags = new LabelSequence (new Label[] { O, ANML, ANML, ANML, VB, O, O, ANML, ANML });
DocumentExtraction extr = new DocumentExtraction ("Test", dict, toks, tags, "O");
String actualXml = extr.toXmlString();
String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
"<doc>the <ANIMAL>quick brown fox </ANIMAL><VERB>leapt </VERB>over the <ANIMAL>lazy dog</ANIMAL></doc>\r\n";
assertEquals (expectedXml, actualXml);
}
示例11: testToXmlBIO
import cc.mallet.types.Label; //导入依赖的package包/类
public void testToXmlBIO () {
LabelAlphabet dict = new LabelAlphabet ();
String document = "the quick brown fox leapt over the lazy dog";
StringTokenization toks = new StringTokenization (document, new CharSequenceLexer ());
Label O = dict.lookupLabel ("O");
Label BANML = dict.lookupLabel ("B-ANIMAL");
Label ANML = dict.lookupLabel ("ANIMAL");
Label BVB = dict.lookupLabel ("B-VERB");
Label VB = dict.lookupLabel ("I-VERB");
LabelSequence tags = new LabelSequence (new Label[] { O, BANML, ANML, BANML, BVB, VB, O, ANML, ANML });
DocumentExtraction extr = new DocumentExtraction ("Test", dict, toks, tags, null, "O", new BIOTokenizationFilter());
String actualXml = extr.toXmlString();
String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
"<doc>the <ANIMAL>quick brown </ANIMAL><ANIMAL>fox </ANIMAL><VERB>leapt over </VERB>the <ANIMAL>lazy dog</ANIMAL></doc>\r\n";
assertEquals (expectedXml, actualXml);
}
示例12: addSpansFromTags
import cc.mallet.types.Label; //导入依赖的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));
}
}
示例13: Record
import cc.mallet.types.Label; //导入依赖的package包/类
public Record (String name, LabeledSpans spans) {
this.name = name;
fieldMap = new THashMap ();
for (int i = 0; i < spans.size(); i++) {
LabeledSpan span = spans.getLabeledSpan (i);
if (!span.isBackground()) {
Label tag = span.getLabel ();
Field field = (Field) fieldMap.get (tag);
if (field == null) {
field = new Field (span);
fieldMap.put (tag, field);
} else {
field.addFiller (span);
}
}
}
}
示例14: setupLabel2Var
import cc.mallet.types.Label; //导入依赖的package包/类
private void setupLabel2Var ()
{
idx2var = new Variable [lblseq.size ()][];
var2label = new THashMap();
for (int t = 0; t < lblseq.size (); t++) {
Labels lbls = lblseq.getLabels (t);
idx2var[t] = new Variable [lbls.size ()];
for (int j = 0; j < lbls.size (); j++) {
Label lbl = lbls.get (j);
Variable var = new Variable (lbl.getLabelAlphabet ());
var.setLabel ("I"+id+"_VAR[f=" + j + "][tm=" + t + "]");
idx2var[t][j] = var;
var2label.put (var, lbl);
}
}
}
示例15: serializeObject
import cc.mallet.types.Label; //导入依赖的package包/类
/** Serializes a single object without metadata
* @param out
* @param object
* @throws java.io.IOException
*/
private void serializeObject (ObjectOutputStream out, Object obj)
throws IOException {
if (obj instanceof FeatureVector) {
FeatureVector features = (FeatureVector) obj;
out.writeChar (TYPE_FEATURE_VECTOR);
out.writeObject (features.getIndices ());
out.writeObject (features.getValues ());
}
else if (obj instanceof Label) {
out.writeChar (TYPE_LABEL);
out.writeObject (((Label) obj).toString ());
} else {
out.writeChar (TYPE_OBJECT);
out.writeObject (obj);
}
}