我很难从 Mallet 开发列表中获得帮助,所以我在这里尝试。
我有一个目标字母为 {A, B, C} 的实例列表,我需要将另一个分析的目标字母更改为 {A, NOT_A}。
到目前为止,我有以下代码(改编自其他 Mallet 源代码),但我继续得到:
字母不匹配:实例:[5976,空],实例列表:[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} 有任何建议?
目标应为标签。试试这个:
..
newInst.setTarget(((LabelAlphabet) newList.getTargetAlphabet()).lookupLabel("A"));
..
newInst.setTarget(((LabelAlphabet) newList.getTargetAlphabet()).lookupLabel("NOT_A"));