}
private static FcmConnection parseLearningConnection(FcmLearning map, XPath xpath, Element connElem)
throws Exception {
FcmConnection conn;
String s;
String name;
name = xpath.evaluate("@name", connElem);
if (StringUtils.isBlank(name)) {
throw new Exception("Missing connection name");
}
String type = xpath.evaluate("@type", connElem);
/* Set weight if weighted*/
if ("WEIGHTED".equalsIgnoreCase(type)) {
LearningWeightedConnection wConn = new LearningWeightedConnection();
NodeList params = (NodeList) xpath.evaluate("param", connElem, XPathConstants.NODESET);
Element param = (Element) params.item(0);
s = xpath.evaluate("@value", param);
if ("weight".equals(param.getAttribute("name"))) {
wConn.setWeight(Double.parseDouble(s));
// by default the uncertainty is set equal to the weight
wConn.setWeightUncertainty(wConn.getWeight());
}
/* set weight uncertainty*/
if(params.getLength()>1){
param = (Element) params.item(1);
s = xpath.evaluate("@value", param);
if ("uncertainty".equals(param.getAttribute("name"))) {
wConn.setWeightUncertainty(Double.parseDouble(s));
}
}
conn = wConn;
} else {
throw new UnsupportedOperationException("Connection type not supported: \"" + type
+ "\"");
}
conn.setName(name);
String description = xpath.evaluate("description/text()", connElem);
if (StringUtils.isNotBlank(description)) {
conn.setDescription(description);
}
Concept c;
s = xpath.evaluate("@from", connElem);
if (StringUtils.isBlank(s)) {
throw new Exception("Missing \"from\" reference in connection \"" + conn.getName()
+ "\"");
}
c = map.getConcept(s);
if (c == null) {
throw new Exception("Missing \"from\" reference in connection \"" + conn.getName()
+ "\"");
}
conn.setFrom(c);
s = xpath.evaluate("@to", connElem);
if (StringUtils.isBlank(s)) {
throw new Exception("Missing \"to\" reference in connection \"" + conn.getName() + "\"");
}
c = map.getConcept(s);
if (c == null) {
throw new Exception("Missing \"to\" reference in connection \"" + conn.getName() + "\"");
}
conn.setTo(c);
//System.out.println(conn);
return conn;
}