using inline scripting to put an xml file on the input-link

5 views
Skip to first unread message

Bob Marinier

unread,
Feb 10, 2012, 11:56:15 AM2/10/12
to jsoar...@googlegroups.com
I'm creating a set of soarunit tests, and one of the input-link structures is a complex thing that is already specified in an xml file. I'd like to use one of the supported scripting languages to just dump this xml on the input-link directly.

The equivalent Java code is:

final String xmlstr = Files.toString(
      new File("expert-model.xml"),
      Charset.defaultCharset());
final Element element = XmlTools.parse(xmlstr).getDocumentElement();
final InputOutput io = agent.getInputOutput();
final XmlToWme converter = SoarTechXmlToWme.forInput(io);
final Identifier messageId = converter.fromXml(element);
InputWmes.add(io, "expert-model", messageId);

(Note that first line is using google.common.io to get the file into a string. Also, this code seems to work outside the input callback, so directly running this code in script form in my soarunit setup block may be enough.)

I'm not very familiar with the scripting languages in jsoar, and I'm even less familiar with how the java and jsoar apis convert over. I've looked at the water-jugs example, but I haven't grokked it yet. I figured I'd ask before spending hours on it in case this is really simple.

As for scripting languages, I have a weak preference for Python since I've actually used it a little bit, but I'd be happy with anything if someone can show me how.

Thanks,
Bob

Dave Ray

unread,
Feb 13, 2012, 3:01:12 PM2/13/12
to jsoar...@googlegroups.com
Hey Bob,

Off the top of my head, I don't totally remember if that's the best
way to get XML on the input link. I don't know if it helps, but I
think there's also a RHS function that does the same thing. If that's
an option you could do it in a setup production.

Otherwise, I'd suggest stilcking with the JavaScript scripting
support. It's the most baked and doesn't have any external
dependencies (jython, etc). For the most part, the code translation is
very straightforward. You can fully qualify a class name like this:

Packages.google.common.io.Files.toString(...)

or shorten things:

var gio = Packages.google.common.io;
gio.Files.toString(...);

None of the script interfaces really provides any more convenience of
the code you have though since they're WME support is focused on the
native data structures of the language, not yucky xml :)

Hope this helps,

Dave

> --
> You received this message because you are subscribed to the Google Groups
> "jsoar-user" group.
> To post to this group, send email to jsoar...@googlegroups.com.
> To unsubscribe from this group, send email to
> jsoar-user+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/jsoar-user?hl=en.

Bob Marinier

unread,
Feb 14, 2012, 8:48:37 AM2/14/12
to jsoar...@googlegroups.com
The RHS functions worked well, although apparently I can't use a relative path in the url (I used Tcl's [pwd] to generate the path inline). But these hints on how to use the inline scripting will certainly be helpful in the future.

Thanks,
Bob
Reply all
Reply to author
Forward
0 new messages