/** * Reads the arguments to AugmentPTA from XML element. * * <p>At the moment, storage of instances of leaf nodes in trees is not implemented (and leaf * nodes are used in filtering), hence I have to rely on storage of the whole set of sequences. * * @param element data to load from * @return constructed arguments. */ protected AugmentPTAData readAugmentPTA(Element element) { if (!element.getNodeName().equals(StatechumXML.ELEM_AUGMENTPTA.name())) throw new IllegalArgumentException( "cannot load augmentPTA data from " + element.getNodeName()); AugmentPTAData result = new AugmentPTAData(); if (!element.hasAttribute(StatechumXML.ATTR_ACCEPT.name())) throw new IllegalArgumentException("missing accept"); if (!element.hasAttribute(StatechumXML.ATTR_KIND.name())) throw new IllegalArgumentException("missing kind"); String accept = element.getAttribute(StatechumXML.ATTR_ACCEPT.name()), colour = element.getAttribute(StatechumXML.ATTR_COLOUR.name()), kind = element.getAttribute(StatechumXML.ATTR_KIND.name()), sequence = element.getTextContent(); if (sequence.length() == 0) throw new IllegalArgumentException("missing sequence"); result.sequence = labelio.readInputSequence(sequence); result.accept = Boolean.valueOf(accept); if (colour.length() > 0) result.colour = Enum.valueOf(JUConstants.class, colour); result.kind = Enum.valueOf(RestartLearningEnum.class, kind); 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; }