Exemplo n.º 1
0
public class Viewer extends SemanticAgent {
  // Create a GUI using the provided DefaultViewerGUI implementation
  ViewerGUI myGUI = new DefaultViewerGUI("Photo Viewer");

  IdentifyingExpression ANY_IMAGE_CONTENT_IRE =
      (IdentifyingExpression) SL.fromTerm("(any (sequence ?x ?y) (image-content ?x ?y))");

  // Define the ViewerSemanticCapabilities class
  public class ViewerSemanticCapabilities extends SemanticCapabilities {

    // Override the setupSemanticInterpretationPrinciples method
    protected SemanticInterpretationPrincipleTable setupSemanticInterpretationPrinciples() {
      // Create a default SIP table
      SemanticInterpretationPrincipleTable table = super.setupSemanticInterpretationPrinciples();

      // Create a new SIP to display the picture, using a NotificationSIPAdapter
      SemanticInterpretationPrinciple sip_view =
          new NotificationSIPAdapter(this, "(image-content ??id ??content)") {
            protected void notify(final MatchResult applyResult, SemanticRepresentation sr) {
              potentiallyAddBehaviour(
                  new OneShotBehaviour() {
                    public void action() {
                      myGUI.displayPhoto(((Constant) applyResult.term("content")).byteValue());
                    }
                  });
            }
          };

      // Add the created SIP into the SIP table
      table.addSemanticInterpretationPrinciple(sip_view);
      return table;
    }
  }

  public Viewer() {
    // Initialize the agent's capabilities using the ViewerSemanticCapabilities class
    setSemanticCapabilities(new ViewerSemanticCapabilities());
  }

  public void setup() {
    super.setup();
    Term album = Tools.AID2Term(new AID((String) getArguments()[0], AID.ISLOCALNAME));
    getSemanticCapabilities().queryRef(ANY_IMAGE_CONTENT_IRE, album);
  }
}
Exemplo n.º 2
0
 public JSAQuery(Node node) {
   super();
   if (node instanceof StringConstantNode) {
     this.node = SL.formula("(false)");
   } else this.node = node;
 }