/** * Loads the initial data from the supplied XML element. * * @param elem where to load from * @return initial data */ public InitialData readInitialData(Element elem) { if (!elem.getNodeName().equals(StatechumXML.ELEM_INIT.name())) throw new IllegalArgumentException( "expecting to load learner initial data " + elem.getNodeName()); NodeList children = elem.getChildNodes(); InitialData result = new InitialData(); for (int i = 0; i < children.getLength(); ++i) if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) children.item(i); if (e.getNodeName().equals(StatechumXML.graphmlNodeNameNS.toString())) { if (result.graph != null) throw new IllegalArgumentException("duplicate graph element"); result.graph = new LearnerGraph(config); AbstractPersistence.loadGraph(e, result.graph, decoratedLearner.getLabelConverter()); } else if (e.getNodeName().equals(StatechumXML.ELEM_SEQ.name())) { String sequenceName = e.getAttribute(StatechumXML.ATTR_SEQ.name()); if (sequenceName.equals(StatechumXML.ATTR_POSITIVE_SEQUENCES.name())) { if (result.plus != null) throw new IllegalArgumentException("duplicate positive element"); result.plus = labelio.readSequenceList(e, StatechumXML.ATTR_POSITIVE_SEQUENCES.name()); if (!e.hasAttribute(StatechumXML.ATTR_POSITIVE_SIZE.name())) throw new IllegalArgumentException("missing positive size"); String size = e.getAttribute(StatechumXML.ATTR_POSITIVE_SIZE.name()); try { result.plusSize = Integer.valueOf(size); } catch (NumberFormatException ex) { statechum.Helper.throwUnchecked("positive value is not an integer " + size, ex); } } else if (sequenceName.equals(StatechumXML.ATTR_NEGATIVE_SEQUENCES.name())) { if (result.minus != null) throw new IllegalArgumentException("duplicate negative element"); result.minus = labelio.readSequenceList(e, StatechumXML.ATTR_NEGATIVE_SEQUENCES.name()); if (!e.hasAttribute(StatechumXML.ATTR_NEGATIVE_SIZE.name())) throw new IllegalArgumentException("missing negative size"); String size = e.getAttribute(StatechumXML.ATTR_NEGATIVE_SIZE.name()); try { result.minusSize = Integer.valueOf(size); } catch (NumberFormatException ex) { statechum.Helper.throwUnchecked("negative value is not an integer " + size, ex); } } else throw new IllegalArgumentException("unexpected kind of sequences: " + sequenceName); } else throw new IllegalArgumentException("unexpected element " + e.getNodeName()); } if (result.graph == null) throw new IllegalArgumentException("missing graph"); if (result.plus == null) throw new IllegalArgumentException("missing positive sequences"); if (result.minus == null) throw new IllegalArgumentException("missing negative sequences"); return result; }
/** * Data need to construct an experiment and evaluate the results. This is not a part of * <em>AbstractExperiment</em> because this is only for testing and hence one would only want to * record data from <b>some</b> experiments, not all of them. * * <p>If possible, this also loads the configuration and uses it for all methods requiring a * configuration. Unexpected elements are ignored. * * <p>{@link LearnerEvaluationConfiguration#labelConverter} is not assigned since it is a function * that is supposed to be set globally for an entire experiment. */ public LearnerEvaluationConfiguration readLearnerEvaluationConfiguration( Element evaluationDataElement, Configuration defaultConfig) { if (!evaluationDataElement.getNodeName().equals(StatechumXML.ELEM_EVALUATIONDATA.name())) throw new IllegalArgumentException( "expecting to load learner evaluation data but found " + evaluationDataElement.getNodeName()); NodeList nodesGraph = StatechumXML.getChildWithTag( evaluationDataElement, StatechumXML.graphmlNodeNameNS.toString()), nodesSequences = StatechumXML.getChildWithTag(evaluationDataElement, StatechumXML.ELEM_SEQ.name()), nodesLtl = StatechumXML.getChildWithTag( evaluationDataElement, StatechumXML.ELEM_CONSTRAINTS.name()), nodesConfigurations = StatechumXML.getChildWithTag(evaluationDataElement, Configuration.configXMLTag), graphNumberNodes = StatechumXML.getChildWithTag( evaluationDataElement, StatechumXML.ELEM_PROGRESSINDICATOR.name()), nodesLabelDetails = StatechumXML.getChildWithTag( evaluationDataElement, StatechumXML.ELEM_LABELDETAILS.name()); if (nodesGraph.getLength() < 1) throw new IllegalArgumentException("missing graph"); if (nodesGraph.getLength() > 1) throw new IllegalArgumentException("duplicate graph"); if (nodesSequences.getLength() < 1) throw new IllegalArgumentException("missing test set"); if (nodesSequences.getLength() > 1) throw new IllegalArgumentException("duplicate test set"); if (nodesLtl.getLength() > 1) throw new IllegalArgumentException("duplicate ltl sets"); if (nodesConfigurations.getLength() > 1) throw new IllegalArgumentException("duplicate configuration"); if (nodesLabelDetails.getLength() > 1) throw new IllegalArgumentException("duplicate label details"); int graphNumber = -1; if (graphNumberNodes.getLength() > 1) try { graphNumber = Integer.parseInt( ((Element) graphNumberNodes.item(0)) .getAttribute(StatechumXML.ATTR_GRAPHNUMBER.name())); } catch (Exception e) { // ignore - graphNumber is unchanged. } LearnerEvaluationConfiguration result = new LearnerEvaluationConfiguration(defaultConfig); if (nodesConfigurations.getLength() > 0) result.config.readXML(nodesConfigurations.item(0)); initIO(evaluationDataElement.getOwnerDocument(), result.config); result.graph = new LearnerGraph(result.config); AbstractPersistence.loadGraph( (Element) nodesGraph.item(0), result.graph, decoratedLearner.getLabelConverter()); result.testSet = labelio.readSequenceList( (Element) nodesSequences.item(0), StatechumXML.ATTR_TESTSET.name()); if (nodesLtl.getLength() > 0) result.ifthenSequences = stringio.readInputSequence(nodesLtl.item(0).getTextContent()); if (nodesLabelDetails.getLength() > 0) { result.labelDetails = new SmtLabelRepresentation(result.config, getLabelConverter()); result.labelDetails.loadXML((Element) nodesLabelDetails.item(0), stringio); } result.graphNumber = graphNumber; return result; }