我很难从 Mallet 开发人员列表中获得帮助,所以我在这里尝试。
我有一个 InstancesList,其目标字母表为 {A, B, C},我需要将目标字母表更改为 {A, NOT_A} 以进行另一次分析。
到目前为止,我有以下代码(改编自其他 Mallet 源代码),但我不断得到:
字母不匹配:Instance: [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} 有任何建议吗?