更改Mallet中的目标字母:字母不匹配

时间:2012-06-18 21:06:22

标签: java nlp mallet

我很难从Mallet开发列表中获得帮助,所以我在这里尝试。

我有一个InstancesList,其目标字母为{A,B,C},我需要将另一个分析的目标字母更改为{A,NOT_A}。

到目前为止,我有以下代码(改编自其他Mallet源代码),但我 继续得到:

字母不匹配:实例:[5976,null],InstanceList:[5976,2]

...
InstanceList iListCopy = (InstanceList) instances.clone();

Alphabet blank = new Alphabet();
Alphabet newAlpha = new Alphabet();

//A and NOT_A cannot be found in alphabet, so add them.
newAlpha.lookupIndex("A", true);
newAlpha.lookupIndex("NOT_A", true);

Noop pipe = new Noop(blank, newAlpha);
InstanceList newIList = new InstanceList(pipe);

//iterate through each instance and change the target based on the
original value.
for (int i = 0; i < iListCopy.size(); i++) {
   Instance inst = iListCopy.get(i);

   FeatureVector original = (FeatureVector) inst.getData();
   Instance newInst = pipe.instanceFrom(new Instance(original,
newAlpha, inst.getName(), inst.getSource()));
   if (inst.getLabeling().toString().equals("A") {  
       newInst.setTarget("A");
   } else {
       newInst.setTarget("NOT_A");
   }
   newIList.add(newInst);   //FAILS with "Alphabets do not match."
}
...

有没有人对如何将目标字母从{A,B,C}更改为{A,NOT_A}有任何建议?

1 个答案:

答案 0 :(得分:0)

目标应该是标签。试试这个:

..
newInst.setTarget(((LabelAlphabet) newList.getTargetAlphabet()).lookupLabel("A"));
..
newInst.setTarget(((LabelAlphabet) newList.getTargetAlphabet()).lookupLabel("NOT_A"));