for (int i = 0; i < feats.length; i++, ind++) {
try {
if (feats[i].equals("Anaph")) {
double anaph_prob = needsAnaph ? calcAnaphoricity(aJCas, anaphor) : 1.0;
// vec += " " + (ind+1) + ":" + anaph_prob;
svm_node n = new svm_node();
n.index = ind+1;
n.value = anaph_prob;
nodes.add(n);
continue;
}
if (feats[i].contains(":")){
String[] catFeat = feats[i].split(":");
String featType = catFeat[0];
String featName = catFeat[1];
// if catFeat[0].equalsIgnoreCase("cat"){} // Not necessary, no other feature namespaces used yet.
String methodName = "num" + featName;
// Class<String> strClass = new Class<String>();
int num = (Integer) sac.getClass().getMethod(methodName, Markable.class).invoke(sac, anaphor);
methodName = "calc" + featType + featName;
Method method = sac.getClass().getMethod(methodName, Integer.class, Markable.class);
for(int j = 0; j < num; j++, ind++){
String val = (String) method.invoke(sac, j, anaphor);
if(val.equalsIgnoreCase("Y")){
svm_node n = new svm_node();
n.index = ind+1;
n.value = 1;
nodes.add(n);
// vec += " " + (ind+1) + ":1";
}
}
continue;
}else{
Object val = sac.getClass().getMethod("calc"+feats[i]).invoke(sac);
if (val instanceof String) {
String s = (String) val;
if (s.equals("yes") || s.equals("Y") || s.equals("C")) {
// vec += " " + (ind+1) + ":1";
svm_node n = new svm_node();
n.index = ind+1;
n.value = 1;
nodes.add(n);
}
}
else if (val instanceof Integer) {
int v = ((Integer)val).intValue();
if (v!=0) {
// vec += " " + (ind+1) + ":" + ((double)v/(i==0?600:10));
svm_node n = new svm_node();
n.index = ind+1;
n.value = (double) v; // ((double)v/(i==0?600:10));
nodes.add(n);
}
}
else if (val instanceof Double) {
// vec += " " + (ind+1) + ":" + val;
if((Double)val != 0.0){
svm_node n = new svm_node();
n.index = ind+1;
n.value = (Double) val;
nodes.add(n);
}
}
}
} catch (Exception e) { e.printStackTrace(); }
}
if(frags != null && frags.size() > 0){
SimpleTree tn = TreeExtractor.extractPathTree(MarkableTreeUtils.markableNode(aJCas, antecedent.getBegin(), antecedent.getEnd()),
MarkableTreeUtils.markableNode(aJCas, anaphor.getBegin(), anaphor.getEnd()));
// SimpleTree tn = TreeExtractor.extractPathEnclosedTree(MarkableTreeUtils.markableNode(aJCas, antecedent.getBegin(), antecedent.getEnd()),
// MarkableTreeUtils.markableNode(aJCas, anaphor.getBegin(), anaphor.getEnd()),
// aJCas);
// now go over the tree fragment features:
for(SimpleTree frag : frags){
if(TreeUtils.contains(tn, frag)){
svm_node n = new svm_node();
n.index = ind+1;
n.value = 1.0;
nodes.add(n);
}
ind++;