本文整理汇总了Java中cc.mallet.types.LabelAlphabet类的典型用法代码示例。如果您正苦于以下问题:Java LabelAlphabet类的具体用法?Java LabelAlphabet怎么用?Java LabelAlphabet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LabelAlphabet类属于cc.mallet.types包,在下文中一共展示了LabelAlphabet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toLabelsSequence
import cc.mallet.types.LabelAlphabet; //导入依赖的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);
}
示例2: testSerializable
import cc.mallet.types.LabelAlphabet; //导入依赖的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 ());
}
示例3: testReadResolve
import cc.mallet.types.LabelAlphabet; //导入依赖的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);
}
示例4: addSpansFromTags
import cc.mallet.types.LabelAlphabet; //导入依赖的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));
}
}
示例5: testToXml
import cc.mallet.types.LabelAlphabet; //导入依赖的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);
}
示例6: testToXmlBIO
import cc.mallet.types.LabelAlphabet; //导入依赖的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);
}
示例7: addSpansFromTags
import cc.mallet.types.LabelAlphabet; //导入依赖的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));
}
}
示例8: print
import cc.mallet.types.LabelAlphabet; //导入依赖的package包/类
public void print ()
{
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
// Include the feature weights according to each label
for (int li = 0; li < numLabels; li++) {
System.out.println ("FEATURES FOR CLASS "+labelDict.lookupObject (li));
System.out.println (" <default> "+parameters [li*numFeatures + defaultFeatureIndex]);
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [li*numFeatures + i];
System.out.println (" "+name+" "+weight);
}
}
}
示例9: createLabelVector
import cc.mallet.types.LabelAlphabet; //导入依赖的package包/类
/** Constructs a LabelVector which is a distribution over indices of
* the "positive" Instance. */
private LabelVector createLabelVector (LabelAlphabet labelAlphabet, double[] scores) {
if (labelAlphabet.growthStopped())
labelAlphabet.startGrowth();
for (int i=0; i < scores.length; i++)
labelAlphabet.lookupIndex(String.valueOf(i), true);
double[] allScores = new double[labelAlphabet.size()];
for (int i=0; i < labelAlphabet.size(); i++)
allScores[i] = 0.0;
for (int i=0; i < scores.length; i++) {
int index = labelAlphabet.lookupIndex(String.valueOf(i), true);
allScores[index] = scores[i];
}
return new LabelVector(labelAlphabet, allScores);
}
示例10: print
import cc.mallet.types.LabelAlphabet; //导入依赖的package包/类
public void print ()
{
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = (LabelAlphabet)getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
// Include the feature weights according to each label
//for (int li = 0; li < numLabels; li++) {
System.out.println ("FEATURES FOR CLASS "+labelDict.lookupObject (0));
System.out.println (" <default> "+parameters [defaultFeatureIndex]);
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [i];
System.out.println (" "+name+" "+weight);
}
}
示例11: print
import cc.mallet.types.LabelAlphabet; //导入依赖的package包/类
public void print (PrintStream out)
{
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
// Include the feature weights according to each label
for (int li = 0; li < numLabels; li++) {
out.println ("FEATURES FOR CLASS "+labelDict.lookupObject (li));
out.println (" <default> "+parameters [li*numFeatures + defaultFeatureIndex]);
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [li*numFeatures + i];
out.println (" "+name+" "+weight);
}
}
}
示例12: pipe
import cc.mallet.types.LabelAlphabet; //导入依赖的package包/类
public Instance pipe(Instance carrier) {
AgglomerativeNeighbor neighbor = (AgglomerativeNeighbor) carrier
.getData();
Clustering original = neighbor.getOriginal();
int[] cluster1 = neighbor.getOldClusters()[0];
int[] cluster2 = neighbor.getOldClusters()[1];
InstanceList list = original.getInstances();
int[] mergedIndices = neighbor.getNewCluster();
Record[] records = array2Records(mergedIndices, list);
Alphabet fieldAlph = records[0].fieldAlphabet();
Alphabet valueAlph = records[0].valueAlphabet();
PropertyList features = null;
features = addExactMatch(records, fieldAlph, valueAlph, features);
features = addApproxMatch(records, fieldAlph, valueAlph, features);
features = addSubstringMatch(records, fieldAlph, valueAlph, features);
carrier
.setData(new FeatureVector(getDataAlphabet(), features,
true));
LabelAlphabet ldict = (LabelAlphabet) getTargetAlphabet();
String label = (original.getLabel(cluster1[0]) == original
.getLabel(cluster2[0])) ? "YES" : "NO";
carrier.setTarget(ldict.lookupLabel(label));
return carrier;
}
示例13: DataSet2InstanceList
import cc.mallet.types.LabelAlphabet; //导入依赖的package包/类
public DataSet2InstanceList(ListDataSet dataSet, LabelAlphabet inputAlphabet, LabelAlphabet targetAlphabet,
List<Integer> cumSum) {
super(new EmptyPipe());
getPipe().setDataAlphabet(inputAlphabet);
getPipe().setTargetAlphabet(targetAlphabet);
int i = 0;
for (Sample s : dataSet) {
if (++i % 1000 == 0) {
System.out.println("Converting Sample " + i);
}
add(new Sample2Instance(s, inputAlphabet, targetAlphabet, getPipe(), cumSum));
}
}
示例14: deserializeObject
import cc.mallet.types.LabelAlphabet; //导入依赖的package包/类
/** Deserialize an object serialized using
* {@link #serializeObject(ObjectOutputStream, Object)}.
* @throws IOException
* @throws ClassNotFoundException
*/
private Object deserializeObject (ObjectInputStream in)
throws IOException, ClassNotFoundException {
char type = in.readChar ();
Object obj;
switch (type) {
case TYPE_LABEL:
LabelAlphabet ldict = (LabelAlphabet) getTargetAlphabet ();
String name = (String) in.readObject ();
obj = ldict.lookupLabel (name);
break;
case TYPE_FEATURE_VECTOR:
int[] indices = (int[]) in.readObject ();
double[] values = (double[]) in.readObject ();
obj = new FeatureVector(getDataAlphabet (), indices, values);
break;
case TYPE_OBJECT:
obj = in.readObject ();
break;
default:
throw new IOException ("Unknown object type " + type);
}
return obj;
}
示例15: print
import cc.mallet.types.LabelAlphabet; //导入依赖的package包/类
@Override
public void print(PrintWriter out) {
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
// Include the feature weights according to each label
for (int li = 0; li < numLabels; li++) {
out.println ("FEATURES FOR CLASS "+labelDict.lookupObject (li));
out.println (" <default> "+parameters [li*numFeatures + defaultFeatureIndex]);
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [li*numFeatures + i];
out.println (" "+name+" "+weight);
}
}
}