Tutorial: Excluding Semantic Sub-Types with Membrane Boundaries
Illustrating The Problem
With semantic computing, data has semantic meaning, which includes structure. Very usefully, receptors can be placed into the computational space that don't just operate on the top-level structures but, importantly, on the sub-types of those structures as well. While powerful, this can also cause unwanted side-effects. This article explores those side-effects and how to use membranes to prevent unwanted sub-type computational triggers.
We can demonstrate the problem easily enough. Add the following receptors onto the surface:
- APOD (Astronomy Post Of the Day)
- Image Viewer
- Web Page Scraper
- Web Page Viewer
This applet is intended to scrape the image on the Astronomy Post Of the Day website and display it in an image viewer. If the user double-clicks on the image, the viewer will display the actual webpage from whence the image came.
Notice how the semantic type "Url" is flying around everywhere. Let's look at the semantic element in play:
The APOD receptor emits a URL semantic element. This URL is of interest to the Webpage Scraper (the one we want to receive this signal) and the Web Page Viewer, which we don't want in this particular case. (You may actually want the behavior to be such that the web page is loaded right away, but in our case, we do not want this behavior.)
Notice also that another Url semantic element is being emitted from the Webpage Scraper and received by the Web Page Viewer receptor. Again, we do not want this behavior. The reason this is happening, however, is because the WebPageHtml semantic structure consists of two sub-type: Url and Html:
The sub-type "Url" is being extracted from the primary signal and sent to the Web Page Viewer receptor. This behavior is intentional. From a biological point of view, think of a strand of DNA that contains many proteins, or "semantic data." Various process are capable of copying just that particular protein and utilizing it for specialized purposes. The analogy applies here as well, as the Web Page Viewer is interested in the sub-type "Url."
Somewhat more insidious is what is occurring when the APOD receptor emits the image. The image semantic type has the following structure:
When the APOD receptor emits the WebImage semantic instance, the sub-type Url is also received by the Webpage Scraper receptor. This causes an infinite loop - APOD issues a URL, the scraper returns the HTML, and APOD issues a WebImage sementic type, of which the URL is sent to the Webpage Scraper, and thus the process repeats all over again.
And lastly, when the user double-clicks on the image in the Image Viewer receptor, the Url semantic instance that is emitted is received by both the Web Page Viewer receptor (the desired behavior) and the Web Page Scraper receptor, the undesired behavior. Here's another way of looking at it:
Membranes to the Rescue
The first thing we can do is contain the Image Viewer and Web Page Viewer in their own membrane, or "computational island" and set the Image semantic type as permeating into the membrane:
Next, we create a membrane just around the Webpage Scraper receptor and set the Url semantic type as permeating in to the membrane and the "WebPageHtml" semantic type as permeating out of the membrane. We also configure the membrane to allow only the root type "Url." If the semantic type "Url" is a sub-type, as in the case of a "WebImage" semantic type, the "WebImage" semantic type will not be allowed to permeate the membrane:
This effectively prevents the "Url" sub-type from being received again by the Webpage Scraper receptor and thus stops the infinite loop between the APOD and Webpage Scraper receptors.
Importantly, we note that earlier, we did not specify "root only" for the Image semantic type -- even though the root type is WebImage, the membrane allows the Image sub-type to permeate into it.
The final applet now achieves the behavior we want:
- APOD emits a Url which the Webpage Scraper receptor responds to and emits the page's HTML
- The APOD receptor responds to the web page's HTML and emits a WebImage signal
- The Image component of this composite semantic type is displayed by the Image Viewer receptor
- The Image Viewer receptor, having been coded to check for the parent type, knows that this image is associated with a web page and enables the behavior allowing the user to double-click on the image.
- When the user double click's on the image, the Url signal, contained within the membrane, is received only by the Web Page Viewer receptor, which displays the web site from whence the image originated
This illustrates how membranes are an effective and necessary mechanism to control the routing of semantic signals.