Exemplo n.º 1
0
 /**
  * Loads a pair from the supplied XML element.
  *
  * @param graph the graph which elements to load Ideally, I need to match string IDs loaded to
  *     those of the graph but this is not done because
  *     <ul>
  *       <li>graphseries used to mangle names of vertices, now this should not happen often (and
  *           if I use relabelling when loading graphs, this would never happen).
  *       <li>this method is expected to be general - purpose hence we do not expect a matching
  *           graph to be present.
  *       <li>matching was only needed when loading a compatibility table from a graph - graph
  *           loader now does the matching after reading pairs.
  *     </ul>
  *
  * @param elem element to load from
  * @return loaded state pair.
  */
 public static <TARGET_TYPE, CACHE_TYPE extends CachedData<TARGET_TYPE, CACHE_TYPE>>
     PairScore readPair(AbstractLearnerGraph<TARGET_TYPE, CACHE_TYPE> graph, Element elem) {
   if (!elem.getNodeName().equals(StatechumXML.ELEM_PAIR.name()))
     throw new IllegalArgumentException("expected to load a pair but got " + elem.getNodeName());
   if (!elem.hasAttribute(StatechumXML.ATTR_Q.name())
       || !elem.hasAttribute(StatechumXML.ATTR_R.name()))
     throw new IllegalArgumentException("missing attribute in a pair");
   String q = elem.getAttribute(StatechumXML.ATTR_Q.name()),
       r = elem.getAttribute(StatechumXML.ATTR_R.name()),
       score = elem.getAttribute(StatechumXML.ATTR_SCORE.name()),
       otherscore = elem.getAttribute(StatechumXML.ATTR_OTHERSCORE.name());
   int scoreInt = JUConstants.intUNKNOWN, otherScoreInt = JUConstants.intUNKNOWN;
   if (score != null && score.length() > 0)
     try {
       scoreInt = Integer.valueOf(score);
     } catch (NumberFormatException ex) {
       statechum.Helper.throwUnchecked("failed to read a score in a pair", ex);
     }
   if (otherscore != null && otherscore.length() > 0)
     try {
       otherScoreInt = Integer.valueOf(otherscore);
     } catch (NumberFormatException ex) {
       statechum.Helper.throwUnchecked("failed to read a anotherscore in a pair", ex);
     }
   return new PairScore(
       AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID(q), graph.config),
       AbstractLearnerGraph.generateNewCmpVertex(VertexID.parseID(r), graph.config),
       scoreInt,
       otherScoreInt);
 }
  /** Tests that updating a maximal automata can chop off parts of a tree. */
  @Test
  public void testPTAconstruction_max5() {
    Configuration config = mainConfiguration;
    Set<List<Label>> minusStrings = buildSet(new String[][] {new String[] {}}, config, converter);

    LearnerGraph graph =
        buildLearnerGraph(
            "A-a->B-b->C-c->A\nA-b->C-d->C", "initial_max", mainConfiguration.copy(), converter);
    graph.findVertex(VertexID.parseID("A")).setDepth(0);
    graph.config.setLearnerIdMode(Configuration.IDMode.POSITIVE_NEGATIVE);
    graph.paths.augmentPTA(minusStrings, false, true);

    final LearnerGraph expected = new LearnerGraph(mainConfiguration.copy());
    expected.getVertex(new LinkedList<Label>()).setAccept(false);
    DifferentFSMException result = WMethod.checkM(expected, graph);
    Assert.assertNull(result);
    checkDepthLabelling(graph);
  }