示例#1
0
  @Test
  public void testElementOrderIsPreservedThroughNextPointers() throws Exception {
    final Agent agent =
        setUpAndRunAgent(
            "testFromXml (state <s> ^superstate nil ^io.input-link <il>) -->"
                + "(<il> ^xml (from-xml |<ignored><a/><b/><c/><d/></ignored>|))");

    final Identifier il = agent.getInputOutput().getInputLink();
    final MatcherBuilder m = Wmes.matcher(agent);
    final Identifier xml = m.attr("xml").find(il).getValue().asIdentifier();
    assertNotNull(xml);

    final Wme[] wmes = {
      m.attr("a").find(xml), m.attr("b").find(xml), m.attr("c").find(xml), m.attr("d").find(xml)
    };
    for (int i = 0; i < wmes.length; ++i) {
      Wme wme = wmes[i];
      assertNotNull(wme);
      if (i != 0) {
        Wme prev = wmes[i - 1];
        Wme next = m.attr(DefaultWmeToXml.NEXT).find(prev);
        assertNotNull(next);
        assertSame(prev.getValue(), next.getIdentifier());
        assertSame(next.getValue(), wme.getValue());
      }
    }
  }
示例#2
0
  @Test
  public void testFromXmlWithOnlyText() throws Exception {
    final Agent agent =
        setUpAndRunAgent(
            "testFromXml (state <s> ^superstate nil ^io.input-link <il>) -->"
                + "(<il> ^xml (from-xml |<ignored>This is the only text in the document</ignored>|))");

    final Identifier il = agent.getInputOutput().getInputLink();
    final MatcherBuilder m = Wmes.matcher(agent);
    final Wme xml = m.attr("xml").find(il);
    assertNotNull(xml);
    assertEquals(
        "This is the only text in the document",
        m.attr(DefaultWmeToXml.TEXT).find(xml).getValue().asString().getValue());
  }
示例#3
0
  @Test
  public void testFromXmlWithOnlyAttributes() throws Exception {
    final Agent agent =
        setUpAndRunAgent(
            "testFromXml (state <s> ^superstate nil ^io.input-link <il>) -->"
                + "(<il> ^xml (from-xml |<ignored name='Boo' value='Radley'/>|))");

    final Identifier il = agent.getInputOutput().getInputLink();
    final MatcherBuilder m = Wmes.matcher(agent);
    final Identifier xml = m.attr("xml").find(il).getValue().asIdentifier();
    assertNotNull(xml);
    final Wme attrs = m.attr(DefaultWmeToXml.ATTRS).find(xml);
    assertNotNull(attrs);
    assertEquals(1, Iterators.size(xml.getWmes())); // Only /attrs

    assertEquals("Boo", m.attr("name").find(attrs).getValue().asString().getValue());
    assertEquals("Radley", m.attr("value").find(attrs).getValue().asString().getValue());
  }
示例#4
0
  @Test
  public void testFromXml() throws Exception {
    final Agent agent =
        setUpAndRunAgent(
            "testFromXml (state <s> ^superstate nil ^io.input-link <il>) -->"
                + "(<il> ^xml (from-xml |"
                + "<ignored>"
                + "<location name='Ann Arbor' population='100000'>This is some text"
                + "</location>"
                + "<person>"
                + "   <name>Bill</name>"
                + "</person>"
                + "</ignored>|))");

    final Identifier il = agent.getInputOutput().getInputLink();
    final MatcherBuilder m = Wmes.matcher(agent);
    final Identifier xml = m.attr("xml").find(il).getValue().asIdentifier();
    assertNotNull(xml);

    final Wme location = m.attr("location").find(xml);
    assertNotNull(location);
    final Wme locAttrs = m.attr(DefaultWmeToXml.ATTRS).find(location);
    assertNotNull(locAttrs);
    assertEquals("Ann Arbor", m.attr("name").find(locAttrs).getValue().asString().getValue());
    assertEquals("100000", m.attr("population").find(locAttrs).getValue().asString().getValue());

    assertEquals(
        "This is some text",
        m.attr(DefaultWmeToXml.TEXT).find(location).getValue().asString().getValue());

    final Wme person = m.attr("person").find(xml);
    assertNotNull(person);

    assertSame(person.getValue(), m.attr(DefaultWmeToXml.NEXT).find(location).getValue());

    final Wme name = m.attr("name").find(person);
    assertEquals("Bill", m.attr(DefaultWmeToXml.TEXT).find(name).getValue().asString().getValue());
  }