@Override
public DirectedSparseGraph learnMachine()
{
currentElement = expectNextElement(ELEM_KINDS.ELEM_INIT.name());
computeStateScores graph = null, temp = null;
DirectedSparseGraph result = null;
while(currentElement != null)
{
final String elemName = currentElement.getNodeName();
if (result != null) // we already know the final graph but there are more elements to come
throw new IllegalArgumentException("unexpected element "+elemName+" after the learner result is known");
ELEM_KINDS kind = stringToEnumMap.get(elemName);
if (elemName.equals(Transform322.graphmlNodeName))
{
String graphKind = currentElement.getAttribute(ELEM_KINDS.ATTR_GRAPHKIND.name());
if (graphKind.equals(ELEM_KINDS.ATTR_LEARNINGOUTCOME.name()))
result = Transform322.loadGraph(currentElement);
else
throw new IllegalArgumentException("unexpected kind of graph: "+graphKind);
kind = ELEM_KINDS.ATTR_GRAPHKIND;// means that this case was handled successfully.
}
else
if (kind != null)
switch(kind)
{
case ELEM_ANSWER:
List<String> question = readInputSequence(new java.io.StringReader(currentElement.getAttribute(ELEM_KINDS.ATTR_QUESTION.name())),-1);
topLevelListener.CheckWithEndUser(graph, question, null);
break;
case ELEM_PAIRS:
topLevelListener.ChooseStatePairs(graph);
break;
case ELEM_QUESTIONS:
checkSingles(currentElement, childrenQuestions);
topLevelListener.ComputeQuestions(readPair(graph.getGraph(), getElement(ELEM_KINDS.ELEM_PAIR.name())),graph,temp);
break;
case ELEM_MERGEANDDETERMINIZE:
if (currentElement.getElementsByTagName(ELEM_KINDS.ELEM_PAIR.name()).getLength() != 1)
throw new IllegalArgumentException("missing or duplicate pair");
temp = topLevelListener.MergeAndDeterminize(graph, readPair(graph.getGraph(), getElement(ELEM_KINDS.ELEM_PAIR.name())));
break;
case ELEM_RESTART:
if (!currentElement.hasAttribute(ELEM_KINDS.ATTR_KIND.name())) throw new IllegalArgumentException("absent KIND attribute on RESTART");
String restartKind = currentElement.getAttribute(ELEM_KINDS.ATTR_KIND.name());
RestartLearningEnum mode = Enum.valueOf(RestartLearningEnum.class, restartKind);
topLevelListener.Restart(mode);
if (mode == RestartLearningEnum.restartNONE)
graph = temp;
// if we are restarting, graph is unchanged.
break;
case ELEM_INIT:
InitialData initial = readInitialData(currentElement);
graph = new computeStateScores(topLevelListener.init(initial.plus,initial.minus),"JUNK");
break;
case ELEM_AUGMENTPTA:
AugmentPTAData augmentData = readAugmentPTA(currentElement);
topLevelListener.AugmentPTA(null, augmentData.kind, augmentData.sequence, augmentData.accept, augmentData.colour);
break;