Skip to content

Retrieving nested SMEM elements #145

@daveakre

Description

@daveakre

I'm trying to get a handle on loading SMEM into working memory via JSoar and am having an issue with nested structures and would really appreciate some pointers. Based on my tests, it seems like SMEM queries retrieve only the top-level structure but not anything below.

When querying smem for a structure like:

(<address> ^street "123 Main St" ^state @S1)
  (@S1 ^name California ^code CA)

I expected the retrieved structure to expand nested LTIs so that rules can match patterns like (<address> ^state <st>) (<st> ^name <name>).

What I'm actually seeing is that only the first level of queried structure is available. In the example above, after retrieval:

  • (<address> ^street "123 Main St" ^state @S1) is present
  • (@S1 ^name California ^code CA) isn't present except for the @S1 identifier

Is this the intended behavior for JSoar? If so, any recommendations for how to properly store non-trivial structures in SMEM that are retrieved via JSoar?

Here's a minimal repro if helpful. The test doesn't actually fail (there are no assertions), but you can see in the final WME output that the nested structure hasn't been retrieved.

package bugReport;

import org.jsoar.kernel.Agent;
import org.jsoar.kernel.RunType;
import org.junit.jupiter.api.Test;

public class SmemNestedLTIBugReport {
    @Test
    void testNestedLTIExpansion() throws Exception {
        Agent agent = new Agent();
        agent.initialize();

        java.io.Writer writer = new java.io.Writer() {
            @Override
            public void write(char[] cbuf, int off, int len) {
                System.out.print(new String(cbuf, off, len));
            }
            @Override
            public void flush() {
                System.out.flush();
            }
            @Override
            public void close() {}
        };
        agent.getPrinter().pushWriter(writer);

        agent.getInterpreter().eval("smem --set learning on");
        agent.getInterpreter().eval("smem --set database memory");

        agent.getInterpreter().eval(
            "sp {propose*test " +
            "   (state <s> ^superstate nil) " +
            "--> " +
            "   (<s> ^operator <o> +) " +
            "   (<o> ^name test)" +
            "}"
        );

        agent.runFor(2, RunType.DECISIONS);

        System.out.println("Storing nested structure in smem:");
        System.out.println("  address ^street \"123 Main St\" ^state <st>");
        System.out.println("  state ^name California ^code CA");

        agent.getInterpreter().eval(
            "smem --add {" +
            "(<addr> ^street |123 Main St| ^state <st>) " +
            "(<st> ^name California ^code CA)" +
            "}"
        );

        agent.getInterpreter().eval(
            "sp {query*address " +
            "   (state <s> ^superstate nil ^smem.command <scmd>) " +
            "--> " +
            "   (<scmd> ^query <q>) " +
            "   (<q> ^street |123 Main St|)" +
            "}"
        );

        // Set up propositions to for varying levels of depth in Soar

        agent.getInterpreter().eval(
            "sp {test*access-state " +
            "   (state <s> ^superstate nil ^smem.result.retrieved <addr>) " +
            "   (<addr> ^state <st>) " +
            "--> " +
            "   (write |Retrieved address has ^state| (crlf))" +
            "}"
        );

        agent.getInterpreter().eval(
            "sp {test*access-state-name " +
            "   (state <s> ^superstate nil ^smem.result.retrieved <addr>) " +
            "   (<addr> ^state <st>) " +
            "   (<st> ^name <name>) " +
            "--> " +
            "   (write |SUCCESS: Can access state.name| (crlf)) " +
            "   (<s> ^test-passed true)" +
            "}"
        );

        agent.getInterpreter().eval(
            "sp {test*detect-bug " +
            "   (state <s> ^superstate nil ^smem.result.retrieved <addr>) " +
            "   (<addr> ^state <st>) " +
            "  -(<st> ^name) " +
            "--> " +
            "   (write |BUG: state identifier exists but has no ^name| (crlf)) " +
            "   (<s> ^bug-detected true)" +
            "}"
        );

        agent.runFor(5, RunType.DECISIONS);
        agent.getInterpreter().eval("print --depth 5 S1");
        agent.getPrinter().flush();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions