Supporting Inference over Geometric Objects

Keywords: Scalable Vector Graphics (SVG), Geometric Inference, Semantic Web, DARPA Agent Markup Language (DAML), Meta-Data, Design Process

Robert Woodbury
Simon Fraser University
Canada
rw@sfu.ca

Biography

Professor, Graduate Program in Computing Arts and Design Sciences, Simon Fraser University. PhD (1988), Carnegie Mellon University.

David Botta
Simon Fraser University
Canada
botta@sfu.ca

Biography

Ph.D. student, Graduate Program in Computing Arts and Design Sciences, Simon Fraser University. MFA (1989) University of Calgary.

Wilson Chang
Simon Fraser University
Canada
wilsonc@sfu.ca

Biography

Masters student, Graduate Program in Computing Arts and Design Sciences, Simon Fraser University. B.Architecture (1998), Washington State University.

Andrei Missine
Simon Fraser University
Canada
userundefined@hotmail.com

Biography

Masters student, Computing Science, Simon Fraser University. B.Sc. in Computer Science (2003), University of British Columbia.


Abstract


SVG takes the notion of machine-accessible Web content well beyond the realm of text, and gives rise to new opportunities for expressing semantics over the Web. In design domains at least, SVG would be used to carry information from which other information may need to be inferred. Through an architecture project scenario in which information is distributed across several representations, each represented through either DAML or SVG, we illustrate how geometric inference can be useful. First we develop an SVG representation of a floor plan from a DAML description of an architectural brief, then demonstrate further inference of information directly from the SVG geometry. Finally, we interpret the new information into a representation of the physical walls of the building again using DAML. We show that preparing, maintaining and computing over documents in which the meta-data refers to geometry stored as SVG is helped by (perhaps requires) significant inference capability over the geometric aspects of the representation itself.


Table of Contents


1. How Geometric Inference can be Useful
2. Demonstration of Development of SVG from Meta-Data, and Geometric Inference on the SVG
     2.1 Development of an SVG Representation of Rooms
     2.2 Inference of Wall Representation from Room Representation
     2.3 Derivation of Meta-Data from SVG
3. Summary
4. Appendix
     4.1 Original DAML Code
     4.2 First XSLT
     4.3 Second XSLT
     4.4 First XML
     4.5 Second XML
     4.6 DamlConverter.java Code
     4.7 First SVG: Room representation
     4.8 Post Reduction SVG: Wall representation
     4.9 Final DAML Code: Wall representation
Bibliography

1. How Geometric Inference can be Useful

Web pages are primarily designed to provide content in a form that can be viewed and understood by humans. With respect to this goal, a bitmap of text can have the same effect as the text characters in unicode, since they are visually rendered in essentially the same manner. However, by machine, the text characters are much easier to recognize and process; for example, by search engines indexing HTML documents.

The dream of the Semantic Web is to augment Web pages with metadata expressing relationships that trigger useful machine processes. This requires more than just making Web content machine-accessible. It also requires the formal encoding of relationships between elements of Web content, such as with Resource Description Framework (RDF), and it requires the use of standard ontologies shared by many processing agents, such as is the objective of the Web Ontology Language (OWL) initiative.

In contrast to HTML, SVG takes the notion of machine-accessible Web content well beyond the realm of text, and gives rise to new opportunities for expressing semantics over the Web. Every explicitly represented curve, shape, transformation, pattern reference, filter effect or animation can be easily recognized as such by an SVG processing agent. Meaningful groups of these elements can be the subject or predicate of RDF statements about the objects they represent. The same cannot be said of a raster image, as it retains no reference to the fundamental geometric structures that gave rise to its matrix of pixel values. Whereas a raster image is typically treated as a single noun in a grammar for Web resources, an SVG image can contain many nouns between which many relationships can be expressed.

For example, a diagram of a fan might have its parts individually identified: blades, shaft, motor, wires, magnets, etc. A metadata relationship useful in a factory setting might be that of subpart. A fan includes as a subpart a motor, which includes its induction coils, so when induction coil inventory is depleted fans cannot be built. If this is properly encoded as part of a Semantic Web, a software agent ordering fans might trigger an automatic check of inventory and a subsequent order of missing parts. Alternatively, this fan might be part of a blueprint showing a household appliance network, and appropriate semantic relationships can be helpful in programming the fan to turn on when the temperature is above a certain threshold and at least one person is in the same room.

Although semantics about appliances or other objects can be encoded in the absence of vector graphic diagrams, these diagrams are very useful accompaniments for human understanding. Any data or process can be effectively bound to a diagram of that data or process. Specific SVG features allow us to take this correspondence further: animations can effectively display certain processes, user events can trigger Web agent requests through scripting, and multiple views highlighting different semantic aspects can be achieved with style sheets.

However, style sheets are not enough. We can see why by using the fan example above. The subpart relation may be very useful in a factory setting, yet provides both too much and too little information for its installation and use in a household appliance network. Missing from the subpart relation are, for example, the electrical requirements for the fan (voltage, amperage) and the size of the rough opening required for installation. The "solution" of simply building each such aspect into a geometric representation so that it can be encoded and referenced by software agents using semantic web encodings quickly encounters a severe practical data redundancy and consistency problem.

In way of explanation, consider an abstract floor plan for a very simple single-storey row house comprising rooms arrayed along a hallway, a large (perhaps subdivided) room at the end of hallway (called a skillion) and a front porch as shown in Figure 1 below.

layout.svg

Figure 1. Floor plan of single-story row house.

This design can be apprised in several ways. First it can be thought of as a collection of rooms, each of which fulfills a function. Such a view might be appropriate in supporting the a realtor's advertising for the house. Second, it can be thought of as a graph of connected rooms, where a connection between two rooms exists when a door exists in a wall shared by the two rooms. This view could be important in determining if code-mandated means of egress requirements are met. Third, it would be represented as a collection of walls, each of which is constructed by a particular construction system. A wall representation would be important in determining construction costs, thermal modelling and placement of windows, considering the context given by not only rooms, but entire facades as well.

The room, connected graph and wall representations are far from independent. Aspects of each can be inferred from the other. Such inference would not, in general, be the sort of straightforward conversion of atomic units from one representation into atomic units in another that is supported by XSLT.

decisiontable.svg

Figure 2. Flow of decisions in an architectural project.

To illustrate the use of inference over geometric objects, consider the flow of decision making in an architectural project, in which Web documents comprise a major channel of communication, as laid out in Figure 2 . The project phases are: Brief, Layout, Massing, and Detailing. Decisions are respectively made about: functions and space allocation, floor plans, spatial organization and building systems. The phases are not discrete; they influence each other in iterative cycles, particularly the layout and massing phases.

By means of a layout engine, the architect informs the SVG with geometry. A semantic encoding for the SVG could be inherited through meta-data from the Briefing phase. Nevertheless, while a geometric representation of a particular semantic encoding must be consistent with the encoding if it is to be useful, it may not be the only such consistent encoding. Apart from the necessity of adding geometric information (rooms have to be of a particular size and in a particular location), there may be several ways that a particular semantic encoding can be realized geometrically.

2. Demonstration of Development of SVG from Meta-Data, and Geometric Inference on the SVG

In the sequel, we first demonstrate the development of an SVG drawing from both a DAML-based functional representation of a simple row house and a specification of room dimensions. This first step alludes to the Briefing and Layout phases, in which knowledge about the intended style is carried in meta-data, and the architect instantiates the style with specific room dimensions and locations. Secondly, we demonstrate a simple geometric inference procedure operating solely on the SVG representation in the first step to obtain a second SVG that represents walls rather than rooms, indicating the potential for geometric inference in Web-based communication. Finally, from the second SVG representation we generate a DAML file that uses wall primitives rather than room primitives. The point of this three-step transformation is to show the necessity, or at least practicality, of having inference over geometry available in the semantic web.

2.1 Development of an SVG Representation of Rooms

    <rdf:Description rdf:ID="dining">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>

      

Figure 3. Sample of original DAML code.

We start with a DAML representation of the rooms of a house linked to their functions, as indicated in Figure 3 above (see the Appendix for the full DAML). The DAML is converted to valid XML without loops. That is, the DAML file is input to a Java package called DAML Adapter (see http://www.davincinetbook.com:8080/daml/damlxslt/TechnicalOverview.html for more information about DAML Adapter). The DAML Adapter requires two more packages, namely RDF API (see http://www-db.stanford.edu/~melnik/rdf/api.html for more information about RDF API), and XALAN by the Apache Project (see http://xml.apache.org/xalan-j/ for more information about XALAN). In this instance, it appears the DAML structure is not well preserved in the resulting XML (some sub-trees are mislocated), therefore we employ an XSLT to transform it into a more compact and readable XML document. The second intermediate XML document is shown in Figure 4 below.

<?xml version="1.0" encoding="UTF-8"?>
<Design id="row_house">
  <DesignUnit id="row_form">
    <DesignUnit id="skillion">
      <DesignUnit id="room5" function="bathroom"/>
      <DesignUnit id="room4" function="kitchen"/>
    </DesignUnit>
    <DesignUnit id="room7" function="hall"/>
    <DesignUnit id="room6" function="porch"/>
    <DesignUnit id="room_row">
      <DesignUnit id="room3" function="dining"/>
      <DesignUnit id="room2" function="lounge"/>
      <DesignUnit id="room1" function="sleeping"/>
    </DesignUnit>
  </DesignUnit>
</Design>

      

Figure 4. The second version of valid XML from DAML.

In our scenario, information which is external to the DAML representation is required in order to instantiate the semantic description, as mentioned above. This external information may be considered to simulate the activity of the architect during the Layout phase , or an automatic layout generator such as that of Flemming [FLEMMING 1986] In this demonstration, the external information is contained in the two XSLT files. The first XSLT (see the Appendix), the one used to transform the intermediate XML, as described above, selects the relevant elements to draw. The second XSLT (see the Appendix) introduces the dimensions of the elements with respect to each other as it transforms the second XML to SVG. The process transforming the first XML through the second to the SVG is handled by a small Java program called DamlConverter (see the Appendix for the code). The result is just one plausible layout. A sample of the SVG code is shown in Figure 5 below (see the Appendix for the full layout SVG). There are an infinity of others: first as members of a large but finite set of alternative layouts and second as any of the infinite dimensional variations of a given layout.

    <g id="skillion">
      <line stroke-width="2" stroke="black" y2="50" x2="550" y1="50" x1="450"/>
      <line stroke-width="2" stroke="black" y2="250" x2="550" y1="50" x1="550"/>
      <line stroke-width="2" stroke="black" y2="250" x2="450" y1="250" x1="550"/>
      <line stroke-width="2" stroke="black" y2="50" x2="450" y1="250" x1="450"/>
      <g id="bathroom">
        <line stroke-width="2" stroke="black" y2="50" x2="550" y1="50" x1="450"/>
        <line stroke-width="2" stroke="black" y2="150" x2="550" y1="50" x1="550"/>
        <line stroke-width="2" stroke="black" y2="150" x2="450" y1="150" x1="550"/>
        <line stroke-width="2" stroke="black" y2="50" x2="450" y1="150" x1="450"/>
        <text text-anchor="middle" fill="blue" font-size="12" font-family="Verdana" y="106" x="500">bathroom</text>
      </g>
      <g id="kitchen">
        <line stroke-width="2" stroke="black" y2="150" x2="550" y1="150" x1="450"/>
        <line stroke-width="2" stroke="black" y2="250" x2="550" y1="150" x1="550"/>
        <line stroke-width="2" stroke="black" y2="250" x2="450" y1="250" x1="550"/>
        <line stroke-width="2" stroke="black" y2="150" x2="450" y1="250" x1="450"/>
        <text text-anchor="middle" fill="blue" font-size="12" font-family="Verdana" y="206" x="500">kitchen</text>
      </g>
    </g>

      

Figure 5. Sample of room representation SVG code.

2.2 Inference of Wall Representation from Room Representation

layout.svg

Figure 6. Rendering of room representation SVG code.

Clearly the rectangles of the above figure are graphically equivalent to their constituent lines, and the transformation from rectangles to lines is a trivial one. The result is a set of lines differentiated only by their coordinates:

<?xml version="1.0" standalone="no"?> 
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" 
     "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> 

<svg width="20cm" height="6cm" viewBox="0 0 20000 6000" 
     xmlns="http://www.w3.org/2000/svg"> 
<desc>Example row_house_redundantLines.svg - redundant lines for row-house</desc> 

<!-- redundant lines for row-house --> 

(    top horizontal line, 
     bottom horizontal line, 
     left vertical line, 
     right vertical line ) 

<!-- porch lines --> 
<line x1="400" y1="400" x2="2800" y2="400" stroke="red" stroke-width="50" /> 
<line x1="400" y1="5500" x2="2800" y2="5500" stroke="red" stroke-width="50" /> 
<line x1="400" y1="400" x2="400" y2="5500" stroke="red" stroke-width="50" /> 
<line x1="2800" y1="400" x2="2800" y2="5500" stroke="red" stroke-width="50" /> 

<!-- room 1 lines --> 
<line x1="2800" y1="400" x2="6400" y2="400" stroke="red" stroke-width="50" /> 
<line x1="2800" y1="4300" x2="6400" y2="4300" stroke="red" stroke-width="50" /> 
<line x1="2800" y1="400" x2="2800" y2="4300" stroke="red" stroke-width="50" /> 
<line x1="6400" y1="400" x2="6400" y2="4300" stroke="red" stroke-width="50" /> 

<!-- room 2 lines --> 
<line x1="6400" y1="400" x2="10600" y2="400" stroke="red" stroke-width="50" /> 
<line x1="6400" y1="4300" x2="10600" y2="4300" stroke="red" stroke-width="50" /> 
<line x1="6400" y1="400" x2="6400" y2="4300" stroke="red" stroke-width="50" /> 
<line x1="10600" y1="400" x2="10600" y2="4300" stroke="red" stroke-width="50" /> 

<!-- room 3 lines --> 
<line x1="10600" y1="400" x2="14200" y2="400" stroke="red" stroke-width="50" /> 
<line x1="10600" y1="4300" x2="14200" y2="4300" stroke="red" stroke-width="50" /> 
<line x1="10600" y1="400" x2="10600" y2="4300" stroke="red" stroke-width="50" /> 
<line x1="14200" y1="400" x2="14200" y2="4300" stroke="red" stroke-width="50" /> 

<!-- skillion lines --> 
<line x1="14200" y1="400" x2="19600" y2="400" stroke="red" stroke-width="50" /> 
<line x1="14200" y1="5500" x2="19600" y2="5500" stroke="red" stroke-width="50" /> 
<line x1="14200" y1="400" x2="14200" y2="5500" stroke="red" stroke-width="50" /> 
<line x1="19600" y1="400" x2="19600" y2="5500" stroke="red" stroke-width="50" /> 

<!-- hallway lines --> 
<line x1="2800" y1="4300" x2="14200" y2="4300" stroke="red" stroke-width="50" /> 
<line x1="2800" y1="5500" x2="14200" y2="5500" stroke="red" stroke-width="50" /> 
<line x1="2800" y1="4300" x2="2800" y2="5500" stroke="red" stroke-width="50" /> 
<line x1="14200" y1="4300" x2="14200" y2="5500" stroke="red" stroke-width="50" /> 

</svg>
      

Figure 7. Redundant lines for row house, SVG code.

It is now that the need for a transformation based on geometry becomes apparent. The above 24 lines are visually equivalent to a much smaller set of only 9 lines. We generate these 9 lines by recourse to the reduction rules from shape grammars.

The field of shape grammars describes grammar systems that operate over a reprepresentation for shape [STINY 1980] . The essential ideas are two: first, that there is a single canonical representation for a given shape that is based on removing (almost) all multiple representations of a given point; and second, that, in general, every shape has an indefinite number of subparts. The first property provides a simple representation over which to formally specify the second. When a shape comprises a set of lines, the canonical representation is known as the maximal line representation of the shape, and in turn comprises the least set of lines containing all points from the initial set. The maximal line representation is computed using the reduction rules, which are depicted in Figure 8 below.

reduction.svg

Figure 8. Reduction rules. The line colours indicate identity of lines only: they distinguish lines from each other and are not carried by the line representation.

Applying the reduction rules to the 24-line SVG description above yields the 9 maximal lines that stand as abstract representations of the walls of the row house. We used Prolog to write the reductions rules to do this task, ultimately obtaining the maximal line SVG representation in Figure 9 below.

<?xml version="1.0" standalone="no"?> 
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" 
     "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> 

<svg width="20cm" height="6cm" viewBox="0 0 20000 6000" 
     xmlns="http://www.w3.org/2000/svg"> 
<desc>Example row_house_maximalLines.svg - maximal lines for row-house</desc> 

<!-- maximal lines for row-house --> 

<!-- horizontal line 1 (from top) --> 
<line x1="400" y1="400" x2="19600" y2="400" 
     stroke="green" stroke-width="50" /> 

<!-- horizontal line 2 (from top) --> 
<line x1="2800" y1="4300" x2="14200" y2="4300" 
     stroke="green" stroke-width="50" /> 

<!-- horizontal line 3 (from top) --> 
<line x1="400" y1="5500" x2="19600" y2="5500" 
     stroke="green" stroke-width="50" /> 

<!-- vertical line 1 (from left) --> 
<line x1="400" y1="400" x2="400" y2="5500" 
     stroke="green" stroke-width="50" /> 

<!-- vertical line 2 (from left) --> 
<line x1="2800" y1="400" x2="2800" y2="5500" 
     stroke="green" stroke-width="50" /> 

<!-- vertical line 3 (from left) --> 
<line x1="6400" y1="400" x2="6400" y2="4300" 
     stroke="green" stroke-width="50" /> 

<!-- vertical line 4 (from left) --> 
<line x1="10600" y1="400" x2="10600" y2="4300" 
     stroke="green" stroke-width="50" /> 

<!-- vertical line 5 (from left) --> 
<line x1="14200" y1="400" x2="14200" y2="5500" 
     stroke="green" stroke-width="50" /> 

<!-- vertical line 6 (from left) --> 
<line x1="19600" y1="400" x2="19600" y2="5500" 
     stroke="green" stroke-width="50" /> 

</svg>
      

Figure 9. Maximal line representation, SVG code.

2.3 Derivation of Meta-Data from SVG

We now have a geometric representation sufficient to support the expression in DAML of the walls of the row-house. A sample of the wall representation in DAML is shown in Figure 10 below (see the Appendix for the full DAML).

    <rdf:Description rdf:ID="wall1">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room1"/>
        <ns1:has_room_rightSide rdf:resource="#room2"/>
        <ns1:has_room_rightSide rdf:resource="#room3"/>
        <ns1:has_room_rightSide rdf:resource="#room6"/>
        <ns1:has_room_rightSide rdf:resource="#room5"/>
        <ns1:has_room_leftSide rdf:resource="#room_North"/>
        <ns1:has_wall_end rdf:resource="#wall10"/>
        <ns1:has_orientation rdf:resource="#East_West"/>
        <ns1:has_wall_start rdf:resource="#wall5"/>
    </rdf:Description>
      

Figure 10. Sample of wall representation DAML code.

To support the expression of room function from wall geometry, though, would require inference over both the DAML and SVG representations. A geometric analysis could tell the difference between a hallway and a bedroom, if there is some knowledge about hallways and bedrooms.

3. Summary

Through an architecture project scenario, we illustrated how geometric inference can be useful, facilitated by SVG. We demonstrated a development of SVG from DAML. We also demonstrated an inference of further information directly from the SVG representation, and indicated that this further information could in turn be captured in DAML.

And now hopefully we have made our point. Preparing, maintaining and computing over documents in which the meta-data refers to geometry stored as SVG is helped by (perhaps requires) that significant inference capability exists over the geometric aspects of the representation itself.

4. Appendix

4.1 Original DAML Code

<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf:RDF 
    xmlns:daml="http://www.daml.org/2001/03/daml+oil#"
    xmlns:ns0="file:E:/Documents/School/SFU/RA Position/June 2003 Paper/DAML/sfc_1_mod.daml#"
    xmlns:oiled="http://img.cs.man.ac.uk/oil/oiled#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema#">
    
    <daml:Ontology rdf:about="">
        <daml:versionInfo></daml:versionInfo>
    </daml:Ontology>
    
    <daml:Class rdf:ID="FunctionalUnit">
        <rdfs:label>FunctionalUnit</rdfs:label>
    </daml:Class>
    
    <daml:Class rdf:ID="Design">
        <rdfs:label>Design</rdfs:label>
    </daml:Class>
    
    <daml:Class rdf:ID="DesignUnit">
        <rdfs:label>DesignUnit</rdfs:label>
    </daml:Class>
    
    <daml:ObjectProperty rdf:ID="has_function">
        <rdfs:label>has_function</rdfs:label>
    </daml:ObjectProperty>
    
    <daml:ObjectProperty rdf:ID="has_part">
        <rdfs:label>has_part</rdfs:label>
    </daml:ObjectProperty>
    
    <daml:ObjectProperty rdf:ID="fulfils_function">
        <rdfs:label>fulfils_function</rdfs:label>
    </daml:ObjectProperty>
    
    <daml:ObjectProperty rdf:ID="has_aspect_from">
        <rdfs:label>has_aspect_from</rdfs:label>
    </daml:ObjectProperty>
    
    <rdf:Description rdf:ID="bathroom">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>
    
    <rdf:Description rdf:ID="dining">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>
    
    <rdf:Description rdf:ID="sleeping">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>
    
    <rdf:Description rdf:ID="lounge">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>
    
    <rdf:Description rdf:ID="kitchen">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>
    
    <rdf:Description rdf:ID="porch">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>
    
    <rdf:Description rdf:ID="hall">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>
    
    <rdf:Description rdf:ID="room_row">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:has_part rdf:resource="#room1"/>
        <ns0:has_part rdf:resource="#room2"/>
        <ns0:has_part rdf:resource="#room3"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="row_form">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:has_part rdf:resource="#skillion"/>
        <ns0:has_part rdf:resource="#room6"/>
        <ns0:has_part rdf:resource="#room7"/>
        <ns0:has_part rdf:resource="#room_row"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="house">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#bathroom"/>
        <ns0:has_function rdf:resource="#dining"/>
        <ns0:has_function rdf:resource="#sleeping"/>
        <ns0:has_function rdf:resource="#lounge"/>
        <ns0:has_function rdf:resource="#kitchen"/>
        <ns0:has_function rdf:resource="#porch"/>
        <ns0:has_function rdf:resource="#hall"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="room1">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:fulfils_function rdf:resource="#sleeping"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="room2">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:fulfils_function rdf:resource="#lounge"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="room3">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:fulfils_function rdf:resource="#dining"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="room4">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:fulfils_function rdf:resource="#kitchen"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="room5">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:fulfils_function rdf:resource="#bathroom"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="room6">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:fulfils_function rdf:resource="#porch"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="room7">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:fulfils_function rdf:resource="#hall"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="row_house">
        <rdf:type>
            <daml:Class rdf:about="#Design"/>
        </rdf:type>
        <ns0:has_aspect_from rdf:resource="#row_form"/>
        <ns0:has_aspect_from rdf:resource="#house"/>
    </rdf:Description>
    
    <rdf:Description rdf:ID="skillion">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:has_part rdf:resource="#room4"/>
        <ns0:has_part rdf:resource="#room5"/>
    </rdf:Description>
    
</rdf:RDF>

4.2 First XSLT

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


    <xsl:template match="Ontology">
        <!-- Examine the design. -->
        <xsl:apply-templates select="Design"/>
    </xsl:template>


    <xsl:template match="Design">
        <xsl:variable name="id"><xsl:value-of select="@id"/></xsl:variable>
        <Design id="{$id}">
            <!-- Try to find a DesignUnit reference, if one is found, follow it. -->
            <xsl:for-each select="*">
                <xsl:variable name="origin" select="normalize-space(.)"/>
                <xsl:apply-templates select='//DesignUnit[@id=$origin]'/>
            </xsl:for-each>
        </Design>
    </xsl:template>
    

    <xsl:template match="DesignUnit">
        <!-- Display the function of this DesignUnit if applicable. -->
        <xsl:variable name="function"><xsl:value-of  select="fulfils_function"/></xsl:variable> 
        <xsl:variable name="id"><xsl:value-of select="@id"/></xsl:variable>       
        <DesignUnit>
            <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
            <xsl:if test="string-length($function) > 0">
                <xsl:attribute name="function">
                    <xsl:value-of select="normalize-space($function)"/>
                </xsl:attribute>
            </xsl:if>    
            <!-- Examine parts of this DesignUnit. -->
            <xsl:for-each select="child::has_part">
                <!-- Recurse if this itself is a DesignUnit -->
                <xsl:if test="child::DesignUnit">
                    <xsl:apply-templates select="DesignUnit"/>
                </xsl:if>

                <!-- Otherwise this must be a has_part, follow all references -->
                <!-- to other DesignUnits here.                               -->
                <xsl:if test="not(child::DesignUnit)">
                    <xsl:variable name="origin" select="normalize-space(.)"/>
                    <xsl:apply-templates select='//DesignUnit[@id=$origin]'/>
                </xsl:if>
            </xsl:for-each>
        </DesignUnit>
    </xsl:template>


    <!-- Do not print anything else -->
    <xsl:template match="text()">
    </xsl:template>

</xsl:stylesheet>

4.3 Second XSLT

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- 
Assuming the following layout:
 ______________________________________________
|          |       |        |      |           |
|          |       |        |      |           |
|          |       |        |      |   BATH    |
|          |  R1   |   R2   |  R3  |   ROOM    |
|          |       |        |      |           |
|  PORCH   |       |        |      |___________|
|          |_______________________|           |
|          |                       |  KITCHEN  |
|          |         HALL          |           |
 ______________________________________________


NOTES: the layout must have a porch, a hall, a skillion and a room row.
The room row must contain at least one room, likewise for the skillion.
Otherwise there are no restrictions. Another limitation is that rooms in 
room row will be distributed horizontally and rooms in the skillion will
be distributed vertically.
-->

    
<!-- ====================================================================== -->
<!--                          Basic layout details                          -->
<!-- ====================================================================== -->
<!-- NOTE: Modify the first 8 to change the look of the house.              -->
<!-- ====================================================================== -->
    <xsl:variable name="font_size">12</xsl:variable>
    
    <xsl:variable name="x_origin">50</xsl:variable>
    <xsl:variable name="y_origin">50</xsl:variable>

    <xsl:variable name="total_height">200</xsl:variable>
    <xsl:variable name="total_width">500</xsl:variable>
    <xsl:variable name="porch_fraction_w">0.15</xsl:variable>
    <xsl:variable name="skillion_fraction_w">0.2</xsl:variable>
    <xsl:variable name="room_row_fraction_h">0.8</xsl:variable>
    
    
    <xsl:variable name="room_row_fraction_w">
        <xsl:value-of select="1 - $skillion_fraction_w - $porch_fraction_w"/>
    </xsl:variable>
    <xsl:variable name="hall_fraction_w"><xsl:value-of select="$room_row_fraction_w"/></xsl:variable>
    <xsl:variable name="hall_fraction_h"><xsl:value-of select="1 - $room_row_fraction_h"/></xsl:variable>


<!-- ====================================================================== -->
<!--                   Setting up variables to draw the house               -->
<!-- ====================================================================== -->
    <xsl:variable name="porch_width">
        <xsl:value-of select="$porch_fraction_w * $total_width"/>
    </xsl:variable>

    <xsl:variable name="skillion_width">
        <xsl:value-of select="$skillion_fraction_w * $total_width"/>
    </xsl:variable>

    <xsl:variable name="hall_width">
        <xsl:value-of select="$hall_fraction_w * $total_width"/>
    </xsl:variable>

    <xsl:variable name="hall_height">
        <xsl:value-of select="$hall_fraction_h * $total_height"/>
    </xsl:variable>

    <xsl:variable name="room_row_width">
        <xsl:value-of select="$hall_width"/>
    </xsl:variable>

    <xsl:variable name="room_row_height">
        <xsl:value-of select="$room_row_fraction_h * $total_height"/>
    </xsl:variable>


<!-- ====================================================================== -->
<!--                                Templates                               -->
<!-- ====================================================================== -->
    <xsl:template match="/">
        <svg width="600" height="300" viewBox="0 0 600 300" xmlns="http://www.w3.org/2000/svg">
            <xsl:text>&#xA;</xsl:text>
            <xsl:apply-templates select="Design"/>
        </svg>
    </xsl:template>


    <xsl:template match="Design">
        <!-- Optional, the rooms will show the outline anyway. -->
        <g id ="row_house">
            <xsl:text>&#xA;</xsl:text>
            <xsl:call-template name="draw_house_outline"/>
            <xsl:apply-templates select="DesignUnit"/>
        </g>
        <xsl:text>&#xA;</xsl:text>
    </xsl:template>


    <xsl:template match="DesignUnit">
        <!-- Hall and porch are special cases. Draw them here. -->
        <xsl:if test="@function='hall'">
            <g id ="hall">
                <xsl:text>&#xA;</xsl:text>
                <xsl:call-template name="draw_hall"/>

                <xsl:variable name="x_center">
                    <xsl:value-of select="round($x_origin + $porch_width + 0.5 * $hall_width)"/>
                </xsl:variable>
                <xsl:variable name="y_center">
                    <xsl:value-of select="round($y_origin + $room_row_height + $hall_height div 2 + $font_size div 2)"/>
                </xsl:variable>
                <text x="{$x_center}" y="{$y_center}" font-family="Verdana" font-size="{$font_size}" fill="blue" text-anchor="middle">hall</text>
                <xsl:text>&#xA;</xsl:text>
            </g>
            <xsl:text>&#xA;</xsl:text>
        </xsl:if>
        
        <xsl:if test="@function='porch'">
            <g id="porch">
                <xsl:text>&#xA;</xsl:text>
                <xsl:call-template name="draw_porch"/>

                <xsl:variable name="x_center">
                    <xsl:value-of select="round($x_origin + $porch_width div 2)"/>
                </xsl:variable>
                <xsl:variable name="y_center">
                    <xsl:value-of select="round($y_origin + $total_height div 2 + $font_size div 2)"/>
                </xsl:variable>
                <text x="{$x_center}" y="{$y_center}" font-family="Verdana" font-size="{$font_size}" fill="blue" text-anchor="middle">porch</text>
                <xsl:text>&#xA;</xsl:text>
            </g>
            <xsl:text>&#xA;</xsl:text>
        </xsl:if>
        
        <!-- If function attribute is not present this is a nested DesignUnit. -->
        <xsl:if test="not(@function)">
            <!-- Draw the contents of the skillion. -->
            <xsl:if test="@id='skillion'">
                <g id="skillion">
                    <xsl:text>&#xA;</xsl:text>
                    <!-- Optional, the rooms will show the outline anyway. -->
                    <xsl:call-template name="draw_skillion_outline"/>
                    <xsl:for-each select="child::*">
                        <xsl:variable name="num"><xsl:value-of select="position()"/></xsl:variable>
                        <xsl:variable name="total"><xsl:value-of select="last()"/></xsl:variable>
                        <xsl:variable name="room_height">
                            <xsl:value-of select="$total_height div $total"/>
                        </xsl:variable>

                        <g><xsl:attribute name="id"><xsl:value-of select="@function"/></xsl:attribute>
                            <xsl:text>&#xA;</xsl:text>
                            <xsl:call-template name="draw_box">
                                <xsl:with-param name="x1">
                                    <xsl:value-of select="round($x_origin + $porch_width + $room_row_width)"/>
                                </xsl:with-param>
                                <xsl:with-param name="y1">
                                    <xsl:value-of select="round($y_origin + ($num - 1) * $room_height)"/>
                                </xsl:with-param>
                                <xsl:with-param name="x2">
                                    <xsl:value-of select="round($x_origin + $total_width)"/>
                                </xsl:with-param>
                                <xsl:with-param name="y2">
                                    <xsl:value-of select="round($y_origin + $num * $room_height)"/>
                                </xsl:with-param>
                            </xsl:call-template>

                            <xsl:if test="@function">
                                <xsl:variable name="function"><xsl:value-of select="@function"/></xsl:variable>
                                <xsl:variable name="x_center">
                                    <xsl:value-of select="round($x_origin + $porch_width + $room_row_width + $skillion_width div 2)"/>
                                </xsl:variable>
                                <xsl:variable name="y_center">
                                    <xsl:value-of select="round($y_origin + ($num - 0.5) * $room_height + $font_size div 2)"/>
                                </xsl:variable>
                                <text x="{$x_center}" y="{$y_center}" font-family="Verdana" font-size="{$font_size}" fill="blue" text-anchor="middle">
                                    <xsl:value-of select="@function"/>
                                </text>
                                <xsl:text>&#xA;</xsl:text>
                            </xsl:if>       
                        </g>
                        <xsl:text>&#xA;</xsl:text>
                    </xsl:for-each>
                </g>
                <xsl:text>&#xA;</xsl:text>
            </xsl:if>

            <!-- Draw the contents of the room_row. -->
            <xsl:if test="@id='room_row'">
                <g id="room_row">
                    <xsl:text>&#xA;</xsl:text>
                    <!-- Optional, the rooms will show the outline anyway. -->
                    <xsl:call-template name="draw_room_row_outline"/>
                    <xsl:for-each select="child::*">
                        <xsl:variable name="num"><xsl:value-of select="position()"/></xsl:variable>
                        <xsl:variable name="total"><xsl:value-of select="last()"/></xsl:variable>
                        <xsl:variable name="room_width">
                            <xsl:value-of select="$room_row_width div $total"/>
                        </xsl:variable>

                        <g><xsl:attribute name="id"><xsl:value-of select="@function"/></xsl:attribute>
                            <xsl:text>&#xA;</xsl:text>
                            <xsl:call-template name="draw_box">
                                <xsl:with-param name="x1">
                                    <xsl:value-of select="round($x_origin + $porch_width + ($num - 1) * $room_width)"/>
                                </xsl:with-param>
                                <xsl:with-param name="y1">
                                    <xsl:value-of select="round($y_origin)"/>
                                </xsl:with-param>
                                <xsl:with-param name="x2">
                                    <xsl:value-of select="round($x_origin + $porch_width + $num * $room_width)"/>
                                </xsl:with-param>
                                <xsl:with-param name="y2">
                                    <xsl:value-of select="round($y_origin + $room_row_height)"/>
                                </xsl:with-param>
                            </xsl:call-template>

                            <xsl:if test="@function">
                                <xsl:variable name="function"><xsl:value-of select="@function"/></xsl:variable>
                                <xsl:variable name="x_center">
                                    <xsl:value-of select="round($x_origin + $porch_width + ($num - 0.5) * $room_width)"/>
                                </xsl:variable>
                                <xsl:variable name="y_center">
                                    <xsl:value-of select="round($y_origin + $room_row_height div 2 + $font_size div 2)"/>
                                </xsl:variable>
                                <text x="{$x_center}" y="{$y_center}" font-family="Verdana" font-size="{$font_size}" fill="blue" text-anchor="middle">
                                    <xsl:value-of select="@function"/>
                                </text>
                                <xsl:text>&#xA;</xsl:text>
                            </xsl:if>       
                        </g>
                        <xsl:text>&#xA;</xsl:text>
                    </xsl:for-each>
                </g>
                <xsl:text>&#xA;</xsl:text>
            </xsl:if>
        </xsl:if>
        <!-- Recurse. -->
        <xsl:apply-templates select="DesignUnit"/>
    </xsl:template>


<!-- ====================================================================== -->
<!--                           Drawing Templates                            -->
<!-- ====================================================================== -->
    <xsl:template name="draw_house_outline">
        <xsl:call-template name="draw_box">
            <xsl:with-param name="x1">
                <xsl:value-of select="$x_origin"/>
            </xsl:with-param>
            <xsl:with-param name="y1">
                <xsl:value-of select="$y_origin"/>
            </xsl:with-param>
            <xsl:with-param name="x2">
                <xsl:value-of select="$x_origin + $total_width"/>
            </xsl:with-param>
            <xsl:with-param name="y2">
                <xsl:value-of select="$y_origin + $total_height"/>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>


    <xsl:template name="draw_skillion_outline">
        <xsl:call-template name="draw_box">
            <xsl:with-param name="x1">
                <xsl:value-of select="$x_origin + $porch_width + $room_row_width"/>
            </xsl:with-param>
            <xsl:with-param name="y1">
                <xsl:value-of select="$y_origin"/>
            </xsl:with-param>
            <xsl:with-param name="x2">
                <xsl:value-of select="$x_origin + $total_width"/>
            </xsl:with-param>
            <xsl:with-param name="y2">
                <xsl:value-of select="$y_origin + $total_height"/>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>


    <xsl:template name="draw_room_row_outline">
        <xsl:call-template name="draw_box">
            <xsl:with-param name="x1">
                <xsl:value-of select="$x_origin + $porch_width"/>
            </xsl:with-param>
            <xsl:with-param name="y1">
                <xsl:value-of select="$y_origin"/>
            </xsl:with-param>
            <xsl:with-param name="x2">
                <xsl:value-of select="$x_origin + $porch_width + $room_row_width"/>
            </xsl:with-param>
            <xsl:with-param name="y2">
                <xsl:value-of select="$y_origin + $room_row_height"/>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>


    <xsl:template name="draw_hall">
        <xsl:call-template name="draw_box">
            <xsl:with-param name="x1">
                <xsl:value-of select="$x_origin + $porch_width"/>
            </xsl:with-param>
            <xsl:with-param name="y1">
                <xsl:value-of select="$y_origin + $room_row_height"/>
            </xsl:with-param>
            <xsl:with-param name="x2">
                <xsl:value-of select="$x_origin + $porch_width + $hall_width"/>
            </xsl:with-param>
            <xsl:with-param name="y2">
                <xsl:value-of select="$y_origin + $total_height"/>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>


    <xsl:template name="draw_porch">
        <xsl:call-template name="draw_box">
            <xsl:with-param name="x1">
                <xsl:value-of select="$x_origin"/>
            </xsl:with-param>
            <xsl:with-param name="y1">
                <xsl:value-of select="$y_origin"/>
            </xsl:with-param>
            <xsl:with-param name="x2">
                <xsl:value-of select="$x_origin + $porch_width"/>
            </xsl:with-param>
            <xsl:with-param name="y2">
                <xsl:value-of select="$y_origin + $total_height"/>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>


    <xsl:template name="draw_box">
        <xsl:param name="x1">0</xsl:param>
        <xsl:param name="y1">0</xsl:param>
        <xsl:param name="x2">0</xsl:param>
        <xsl:param name="y2">0</xsl:param>
        
        <line x1="{$x1}" y1="{$y1}" x2="{$x2}" y2="{$y1}" stroke="black" stroke-width="2"/>
        <xsl:text>&#xA;</xsl:text>
        <line x1="{$x2}" y1="{$y1}" x2="{$x2}" y2="{$y2}" stroke="black" stroke-width="2"/>
        <xsl:text>&#xA;</xsl:text>
        <line x1="{$x2}" y1="{$y2}" x2="{$x1}" y2="{$y2}" stroke="black" stroke-width="2"/>
        <xsl:text>&#xA;</xsl:text>
        <line x1="{$x1}" y1="{$y2}" x2="{$x1}" y2="{$y1}" stroke="black" stroke-width="2"/>
        <xsl:text>&#xA;</xsl:text>
    </xsl:template>

</xsl:stylesheet>

4.4 First XML

<Ontology id="">
    <versionInfo>
        <null id="null">
        </null>
    </versionInfo>
    <Class id="Design">
        <label>
            Design
        </label>
    </Class>
    <Class id="DesignUnit">
        <label>
            DesignUnit
        </label>
    </Class>
    <Class id="FunctionalUnit">
        <label>
            FunctionalUnit
        </label>
    </Class>
    <FunctionalUnit id="bathroom">
    </FunctionalUnit>
    <FunctionalUnit id="dining">
    </FunctionalUnit>
    <ObjectProperty id="fulfils_function">
        <label>
            fulfils_function
        </label>
    </ObjectProperty>
    <FunctionalUnit id="hall">
    </FunctionalUnit>
    <ObjectProperty id="has_aspect_from">
        <label>
            has_aspect_from
        </label>
    </ObjectProperty>
    <ObjectProperty id="has_function">
        <label>
            has_function
        </label>
    </ObjectProperty>
    <ObjectProperty id="has_part">
        <label>
            has_part
        </label>
    </ObjectProperty>
    <FunctionalUnit id="house">
        <has_function>
            <FunctionalUnit id="sleeping">
            </FunctionalUnit>
        </has_function>
        <has_function>
            hall
        </has_function>
        <has_function>
            <FunctionalUnit id="porch">
            </FunctionalUnit>
        </has_function>
        <has_function>
            dining
        </has_function>
        <has_function>
            <FunctionalUnit id="lounge">
            </FunctionalUnit>
        </has_function>
        <has_function>
            bathroom
        </has_function>
        <has_function>
            <FunctionalUnit id="kitchen">
            </FunctionalUnit>
        </has_function>
    </FunctionalUnit>
    <DesignUnit id="room1">
        <fulfils_function>
            sleeping
        </fulfils_function>
    </DesignUnit>
    <DesignUnit id="room2">
        <fulfils_function>
            lounge
        </fulfils_function>
    </DesignUnit>
    <DesignUnit id="room3">
        <fulfils_function>
            dining
        </fulfils_function>
    </DesignUnit>
    <DesignUnit id="room4">
        <fulfils_function>
            kitchen
        </fulfils_function>
    </DesignUnit>
    <DesignUnit id="room5">
        <fulfils_function>
            bathroom
        </fulfils_function>
    </DesignUnit>
    <DesignUnit id="room6">
        <fulfils_function>
            porch
        </fulfils_function>
    </DesignUnit>
    <DesignUnit id="room7">
        <fulfils_function>
            hall
        </fulfils_function>
    </DesignUnit>
    <DesignUnit id="room_row">
        <has_part>
            room3
        </has_part>
        <has_part>
            room2
        </has_part>
        <has_part>
            room1
        </has_part>
    </DesignUnit>
    <DesignUnit id="row_form">
        <has_part>
            <DesignUnit id="skillion">
                <has_part>
                    room5
                </has_part>
                <has_part>
                    room4
                </has_part>
            </DesignUnit>
        </has_part>
        <has_part>
            room7
        </has_part>
        <has_part>
            room6
        </has_part>
        <has_part>
            room_row
        </has_part>
    </DesignUnit>
    <Design id="row_house">
        <has_aspect_from>
            row_form
        </has_aspect_from>
        <has_aspect_from>
            house
        </has_aspect_from>
    </Design>
</Ontology>

4.5 Second XML

<?xml version="1.0" encoding="UTF-8"?>
<Design id="row_house">
  <DesignUnit id="row_form">
    <DesignUnit id="skillion">
      <DesignUnit id="room5" function="bathroom"/>
      <DesignUnit id="room4" function="kitchen"/>
    </DesignUnit>
    <DesignUnit id="room7" function="hall"/>
    <DesignUnit id="room6" function="porch"/>
    <DesignUnit id="room_row">
      <DesignUnit id="room3" function="dining"/>
      <DesignUnit id="room2" function="lounge"/>
      <DesignUnit id="room1" function="sleeping"/>
    </DesignUnit>
  </DesignUnit>
</Design>

4.6 DamlConverter.java Code

import com.bah.xml.DamlAdapter;
import javax.xml.transform.stream.*;
import javax.xml.transform.*;
import java.io.*;

/**
 * @author Andrei Missine
 *
 */
public class DamlConverter
{
    static public void main(String[] args)
    {
        DamlAdapter      adapter = null;
        StreamResult     streamResult = null;
        String           result = null;
        FileOutputStream out;

        String filename;

        /* check for valid arguments */
        if (args.length < 2)
        {
            System.out.println("Not enough arguments supplied!\n");
            System.out.println("Usage: DamlConverter" +
                               "  <a DAML URI> <output filename> [<an XSL URI> ...] ");
            System.exit(0);
        }

        filename = args[1];
        try {out = new FileOutputStream(filename);}
        catch (FileNotFoundException e)
        {
            System.out.println("Unable to write output to " + filename);
            return;
        }

        try
        {
            adapter = new DamlAdapter();
            adapter.setDamlSourceURI(args[0]);

            if (args.length == 2)
            {
                /* no style sheet; perform default transformation */
                result = adapter.applyXmlTransformation();
            }
            else
            {
                /* use the given style sheet */
                adapter.setXslSourceURI(args[2]);
                streamResult = adapter.applyTransformation();
                result = streamResult.getOutputStream().toString();
            }

            if(args.length > 3)
            {
                int i = 3;
                javax.xml.transform.TransformerFactory tFactory =
                    javax.xml.transform.TransformerFactory.newInstance();
                while(i < args.length)
                {
                    streamResult.setOutputStream(new ByteArrayOutputStream());
                    StringBufferInputStream is = new StringBufferInputStream(result);
                    javax.xml.transform.stream.StreamSource source =
                        new javax.xml.transform.stream.StreamSource(is);

                    javax.xml.transform.Transformer transformer = tFactory.newTransformer
                        (new javax.xml.transform.stream.StreamSource(args[i++]));

                    transformer.transform(source, streamResult);
                    result = streamResult.getOutputStream().toString();
                }
            }

            out.write(result.getBytes());
            System.out.println("Conversion successful. Result stored in " + filename);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
}

4.7 First SVG: Room representation

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 300" height="300" width="600">
  <g id="row_house">
    <line stroke-width="2" stroke="black" y2="50" x2="550" y1="50" x1="50"/>
    <line stroke-width="2" stroke="black" y2="250" x2="550" y1="50" x1="550"/>
    <line stroke-width="2" stroke="black" y2="250" x2="50" y1="250" x1="550"/>
    <line stroke-width="2" stroke="black" y2="50" x2="50" y1="250" x1="50"/>
    <g id="skillion">
      <line stroke-width="2" stroke="black" y2="50" x2="550" y1="50" x1="450"/>
      <line stroke-width="2" stroke="black" y2="250" x2="550" y1="50" x1="550"/>
      <line stroke-width="2" stroke="black" y2="250" x2="450" y1="250" x1="550"/>
      <line stroke-width="2" stroke="black" y2="50" x2="450" y1="250" x1="450"/>
      <g id="bathroom">
        <line stroke-width="2" stroke="black" y2="50" x2="550" y1="50" x1="450"/>
        <line stroke-width="2" stroke="black" y2="150" x2="550" y1="50" x1="550"/>
        <line stroke-width="2" stroke="black" y2="150" x2="450" y1="150" x1="550"/>
        <line stroke-width="2" stroke="black" y2="50" x2="450" y1="150" x1="450"/>
        <text text-anchor="middle" fill="blue" font-size="12" font-family="Verdana" y="106" x="500">bathroom</text>
      </g>
      <g id="kitchen">
        <line stroke-width="2" stroke="black" y2="150" x2="550" y1="150" x1="450"/>
        <line stroke-width="2" stroke="black" y2="250" x2="550" y1="150" x1="550"/>
        <line stroke-width="2" stroke="black" y2="250" x2="450" y1="250" x1="550"/>
        <line stroke-width="2" stroke="black" y2="150" x2="450" y1="250" x1="450"/>
        <text text-anchor="middle" fill="blue" font-size="12" font-family="Verdana" y="206" x="500">kitchen</text>
      </g>
    </g>
    <g id="room_row">
      <line stroke-width="2" stroke="black" y2="50" x2="450" y1="50" x1="125"/>
      <line stroke-width="2" stroke="black" y2="210" x2="450" y1="50" x1="450"/>
      <line stroke-width="2" stroke="black" y2="210" x2="125" y1="210" x1="450"/>
      <line stroke-width="2" stroke="black" y2="50" x2="125" y1="210" x1="125"/>
      <g id="dining">
        <line stroke-width="2" stroke="black" y2="50" x2="233" y1="50" x1="125"/>
        <line stroke-width="2" stroke="black" y2="210" x2="233" y1="50" x1="233"/>
        <line stroke-width="2" stroke="black" y2="210" x2="125" y1="210" x1="233"/>
        <line stroke-width="2" stroke="black" y2="50" x2="125" y1="210" x1="125"/>
        <text text-anchor="middle" fill="blue" font-size="12" font-family="Verdana" y="136" x="179">dining</text>
      </g>
      <g id="lounge">
        <line stroke-width="2" stroke="black" y2="50" x2="342" y1="50" x1="233"/>
        <line stroke-width="2" stroke="black" y2="210" x2="342" y1="50" x1="342"/>
        <line stroke-width="2" stroke="black" y2="210" x2="233" y1="210" x1="342"/>
        <line stroke-width="2" stroke="black" y2="50" x2="233" y1="210" x1="233"/>
        <text text-anchor="middle" fill="blue" font-size="12" font-family="Verdana" y="136" x="288">lounge</text>
      </g>
      <g id="sleeping">
        <line stroke-width="2" stroke="black" y2="50" x2="450" y1="50" x1="342"/>
        <line stroke-width="2" stroke="black" y2="210" x2="450" y1="50" x1="450"/>
        <line stroke-width="2" stroke="black" y2="210" x2="342" y1="210" x1="450"/>
        <line stroke-width="2" stroke="black" y2="50" x2="342" y1="210" x1="342"/>
        <text text-anchor="middle" fill="blue" font-size="12" font-family="Verdana" y="136" x="396">sleeping</text>
      </g>
    </g>
    <g id="hall">
      <line stroke-width="2" stroke="black" y2="210" x2="450" y1="210" x1="125"/>
      <line stroke-width="2" stroke="black" y2="250" x2="450" y1="210" x1="450"/>
      <line stroke-width="2" stroke="black" y2="250" x2="125" y1="250" x1="450"/>
      <line stroke-width="2" stroke="black" y2="210" x2="125" y1="250" x1="125"/>
      <text text-anchor="middle" fill="blue" font-size="12" font-family="Verdana" y="236" x="288">hall</text>
    </g>
    <g id="porch">
      <line stroke-width="2" stroke="black" y2="50" x2="125" y1="50" x1="50"/>
      <line stroke-width="2" stroke="black" y2="250" x2="125" y1="50" x1="125"/>
      <line stroke-width="2" stroke="black" y2="250" x2="50" y1="250" x1="125"/>
      <line stroke-width="2" stroke="black" y2="50" x2="50" y1="250" x1="50"/>
      <text text-anchor="middle" fill="blue" font-size="12" font-family="Verdana" y="156" x="88">porch</text>
    </g>
  </g>
</svg>

4.8 Post Reduction SVG: Wall representation

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" 
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">

<svg width="20cm" height="6cm" viewBox="0 0 20000 6000"
     xmlns="http://www.w3.org/2000/svg">
  <desc>Example row_house_maximalLines.svg - maximal lines for row-house</desc>

<!-- maximal lines for row-house -->

<!-- horizontal line 1 (from top) -->
    <line x1="400" y1="400" x2="19600" y2="400"
            stroke="green" stroke-width="50"  />

<!-- horizontal line 2 (from top) -->
    <line x1="2800" y1="4300" x2="14200" y2="4300"
            stroke="green" stroke-width="50"  />

<!-- horizontal line 3 (from top) -->
    <line x1="400" y1="5500" x2="19600" y2="5500"
            stroke="green" stroke-width="50"  />

<!-- vertical line 1 (from left) -->
    <line x1="400" y1="400" x2="400" y2="5500"
            stroke="green" stroke-width="50"  />

<!-- vertical line 2 (from left) -->
    <line x1="2800" y1="400" x2="2800" y2="5500"
            stroke="green" stroke-width="50"  />

<!-- vertical line 3 (from left) -->
    <line x1="6400" y1="400" x2="6400" y2="4300"
            stroke="green" stroke-width="50"  />

<!-- vertical line 4 (from left) -->
    <line x1="10600" y1="400" x2="10600" y2="4300"
            stroke="green" stroke-width="50"  />

<!-- vertical line 5 (from left) -->
    <line x1="14200" y1="400" x2="14200" y2="5500"
            stroke="green" stroke-width="50"  />

<!-- vertical line 6 (from left) -->
    <line x1="19600" y1="400" x2="19600" y2="5500"
            stroke="green" stroke-width="50"  />

</svg>

4.9 Final DAML Code: Wall representation

<?xml version="1.0" encoding="ISO-8859-1"?>
<rdf:RDF xmlns:daml="http://www.daml.org/2001/03/daml+oil#"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:ns0="#"
    xmlns:ns1="#"
    xmlns:oiled="http://img.cs.man.ac.uk/oil/oiled#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2000/10/XMLSchema#">
    <daml:Ontology rdf:about="">
        <dc:title>&quot;An Ontology&quot;</dc:title>
        <dc:date></dc:date>
        <dc:creator></dc:creator>
        <dc:description></dc:description>
        <dc:subject></dc:subject>
        <daml:versionInfo></daml:versionInfo>
    </daml:Ontology>
    <daml:Class rdf:ID="DesignUnit">
        <rdfs:label>DesignUnit</rdfs:label>
    </daml:Class>
    <daml:Class rdf:ID="Door">
        <rdfs:label>Door</rdfs:label>
        <rdfs:subClassOf>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdfs:subClassOf>
    </daml:Class>
    <daml:Class rdf:ID="Wall">
        <rdfs:label>Wall</rdfs:label>
        <rdfs:subClassOf>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdfs:subClassOf>
    </daml:Class>
    <daml:Class rdf:ID="FunctionalUnit">
        <rdfs:label>FunctionalUnit</rdfs:label>
    </daml:Class>
    <daml:ObjectProperty rdf:ID="has_room_leftSide">
        <rdfs:label>has_room_leftSide</rdfs:label>
        <rdfs:domain>
            <daml:Class rdf:about="#Wall"/>
        </rdfs:domain>
        <rdfs:domain>
            <daml:Class rdf:about="#Door"/>
        </rdfs:domain>
    </daml:ObjectProperty>
    <daml:ObjectProperty rdf:ID="has_part">
        <rdfs:label>has_part</rdfs:label>
    </daml:ObjectProperty>
    <daml:ObjectProperty rdf:ID="has_wall_start">
        <rdfs:label>has_wall_start</rdfs:label>
        <rdfs:domain>
            <daml:Class rdf:about="#Wall"/>
        </rdfs:domain>
    </daml:ObjectProperty>
    <daml:ObjectProperty rdf:ID="has_room_rightSide">
        <rdfs:label>has_room_rightSide</rdfs:label>
        <rdfs:domain>
            <daml:Class rdf:about="#Wall"/>
        </rdfs:domain>
        <rdfs:domain>
            <daml:Class rdf:about="#Door"/>
        </rdfs:domain>
    </daml:ObjectProperty>
    <daml:ObjectProperty rdf:ID="has_orientation">
        <rdfs:label>has_orientation</rdfs:label>  
        <rdfs:range>
            <daml:Class>
                <daml:oneOf>
                    <daml:List>
                        <daml:first>
                            <daml:Thing rdf:about="#East_West"/>
                        </daml:first>
                        <daml:rest>
                            <daml:List>
                                <daml:first>
                                    <daml:Thing rdf:about="#North_South"/>
                                </daml:first>
                                <daml:rest>
                                    <daml:nil/>
                                </daml:rest>
                            </daml:List>
                        </daml:rest>
                    </daml:List>
                </daml:oneOf>
            </daml:Class>
        </rdfs:range>
    </daml:ObjectProperty>
    <daml:ObjectProperty rdf:IDt="has_function">
        <rdfs:label>has_function</rdfs:label>
    </daml:ObjectProperty>
    <daml:ObjectProperty rdf:ID="has_wall_end">
        <rdfs:label>has_wall_end</rdfs:label>
        <rdfs:domain>
            <daml:Class rdf:about="#Wall"/>
        </rdfs:domain>
    </daml:ObjectProperty>
    <rdf:Description rdf:ID="divider">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>
    <rdf:Description rdf:ID="wall10">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room5"/>
        <ns1:has_room_rightSide rdf:resource="#room4"/>
        <ns1:has_room_leftSide rdf:resource="#room_East"/>
        <ns1:has_wall_end rdf:resource="#wall4"/>
        <ns1:has_orientation rdf:resource="#North_South"/>
        <ns1:has_wall_start rdf:resource="#wall5"/>
    </rdf:Description>
    <rdf:Description rdf:ID="opening">
        <rdf:type>
            <daml:Class rdf:about="#FunctionalUnit"/>
        </rdf:type>
    </rdf:Description>
    <rdf:Description rdf:ID="North_South">
        <rdf:type rdf:resource="http://www.daml.org/2001/03/daml+oil#Thing"/>
    </rdf:Description>
    <rdf:Description rdf:ID="door1">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#opening"/>
        <ns1:has_room_rightSide rdf:resource="#room7"/>
        <ns1:has_room_leftSide rdf:resource="#room1"/>
    </rdf:Description>
    <rdf:Description rdf:ID="door2">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#opening"/>
        <ns1:has_room_rightSide rdf:resource="#room7"/>
        <ns1:has_room_leftSide rdf:resource="#room2"/>
    </rdf:Description>
    <rdf:Description rdf:ID="door3">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#opening"/>
        <ns1:has_room_rightSide rdf:resource="#room7"/>
        <ns1:has_room_leftSide rdf:resource="#room3"/>
    </rdf:Description>
    <rdf:Description rdf:ID="door4">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#opening"/>
        <ns1:has_room_rightSide rdf:resource="#room7"/>
        <ns1:has_room_leftSide rdf:resource="#room4"/>
    </rdf:Description>
    <rdf:Description rdf:ID="room1">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
    </rdf:Description>
    <rdf:Description rdf:ID="room2">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
    </rdf:Description>
    <rdf:Description rdf:ID="room3">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
    </rdf:Description>
    <rdf:Description rdf:ID="room4">   
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
    </rdf:Description>
    <rdf:Description rdf:ID="room5">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
    </rdf:Description>
    <rdf:Description rdf:ID="room6">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
    </rdf:Description>
    <rdf:Description rdf:ID="room7">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
    </rdf:Description>
    <rdf:Description rdf:ID="wall1">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room1"/>
        <ns1:has_room_rightSide rdf:resource="#room2"/>
        <ns1:has_room_rightSide rdf:resource="#room3"/>
        <ns1:has_room_rightSide rdf:resource="#room6"/>
        <ns1:has_room_rightSide rdf:resource="#room5"/>
        <ns1:has_room_leftSide rdf:resource="#room_North"/>
        <ns1:has_wall_end rdf:resource="#wall10"/>
        <ns1:has_orientation rdf:resource="#East_West"/>
        <ns1:has_wall_start rdf:resource="#wall5"/>
    </rdf:Description>
    <rdf:Description rdf:ID="wall2">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns1:has_part rdf:resource="#door5"/>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room4"/>
        <ns1:has_room_leftSide rdf:resource="#room5"/>
        <ns1:has_wall_end rdf:resource="#wall10"/>
        <ns1:has_orientation rdf:resource="#East_West"/>
        <ns1:has_wall_start rdf:resource="#wall9"/>
    </rdf:Description>
    <rdf:Description rdf:ID="wall3">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns1:has_part rdf:resource="#door1"/>
        <ns1:has_part rdf:resource="#door2"/>
        <ns1:has_part rdf:resource="#door3"/>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room7"/>
        <ns1:has_room_leftSide rdf:resource="#room1"/>
        <ns1:has_room_leftSide rdf:resource="#room2"/>
        <ns1:has_room_leftSide rdf:resource="#room3"/>
        <ns1:has_wall_end rdf:resource="#wall9"/>
        <ns1:has_orientation rdf:resource="#East_West"/>
        <ns1:has_wall_start rdf:resource="#wall6"/>
    </rdf:Description>
    <rdf:Description rdf:ID="wall5">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room_West"/>
        <ns1:has_room_leftSide rdf:resource="#room6"/>
        <ns1:has_wall_end rdf:resource="#wall4"/>
        <ns1:has_orientation rdf:resource="#North_South"/>
        <ns1:has_wall_start rdf:resource="#wall1"/>
    </rdf:Description>
    <rdf:Description rdf:ID="wall6">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns1:has_part rdf:resource="#door6"/>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room6"/>
        <ns1:has_room_leftSide rdf:resource="#room1"/>
        <ns1:has_room_leftSide rdf:resource="#room7"/>
        <ns1:has_wall_end rdf:resource="#wall4"/>
        <ns1:has_orientation rdf:resource="#North_South"/>
        <ns1:has_wall_start rdf:resource="#wall1"/>
    </rdf:Description>
    <rdf:Description rdf:ID="wall7">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room1"/>
        <ns1:has_room_leftSide rdf:resource="#room2"/>
        <ns1:has_wall_end rdf:resource="#wall3"/>
        <ns1:has_orientation rdf:resource="#North_South"/>
        <ns1:has_wall_start rdf:resource="#wall1"/>
    </rdf:Description>
    <rdf:Description rdf:ID="wall8">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room2"/>
        <ns1:has_room_leftSide rdf:resource="#room3"/>
        <ns1:has_wall_end rdf:resource="#wall3"/>
        <ns1:has_orientation rdf:resource="#North_South"/>
        <ns1:has_wall_start rdf:resource="#wall1"/>
    </rdf:Description>
    <rdf:Description rdf:ID="wall9">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns1:has_part rdf:resource="#door4"/>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room3"/>
        <ns1:has_room_rightSide rdf:resource="#room7"/>
        <ns1:has_room_leftSide rdf:resource="#room4"/>
        <ns1:has_room_leftSide rdf:resource="#room5"/>
        <ns1:has_wall_end rdf:resource="#wall4"/>
        <ns1:has_orientation rdf:resource="#North_South"/>
        <ns1:has_wall_start rdf:resource="#wall1"/>
    </rdf:Description>
    <rdf:Description rdf:ID="door6">
        <rdf:type rdf:resource="http://www.daml.org/2001/03/daml+oil#Thing"/>
        <ns0:has_function rdf:resource="#opening"/>
        <ns1:has_room_rightSide rdf:resource="#room6"/>
        <ns1:has_room_leftSide rdf:resource="#room7"/>
    </rdf:Description>
    <rdf:Description rdf:ID="wall4">
        <rdf:type>
            <daml:Class rdf:about="#Wall"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#divider"/>
        <ns1:has_room_rightSide rdf:resource="#room_South"/>
        <ns1:has_room_leftSide rdf:resource="#room6"/>
        <ns1:has_room_leftSide rdf:resource="#room7"/>
        <ns1:has_room_leftSide rdf:resource="#room4"/>
        <ns1:has_wall_end rdf:resource="#wall10"/>
        <ns1:has_orientation rdf:resource="#East_West"/>
        <ns1:has_wall_start rdf:resource="#wall5"/>
    </rdf:Description>
    <rdf:Description rdf:ID="room_East">
        <rdf:type rdf:resource="http://www.daml.org/2001/03/daml+oil#Thing"/>
    </rdf:Description>
    <rdf:Description rdf:ID="room_West">
        <rdf:type rdf:resource="http://www.daml.org/2001/03/daml+oil#Thing"/>
    </rdf:Description>
    <rdf:Description rdf:ID="door5">
        <rdf:type>
            <daml:Class rdf:about="#DesignUnit"/>
        </rdf:type>
        <ns0:has_function rdf:resource="#opening"/>
        <ns1:has_room_rightSide rdf:resource="#room4"/>
        <ns1:has_room_leftSide rdf:resource="#room5"/>
    </rdf:Description>
    <rdf:Description rdf:ID="East_West">
        <rdf:type rdf:resource="http://www.daml.org/2001/03/daml+oil#Thing"/>
    </rdf:Description>
    <rdf:Description rdf:ID="room_North">
        <rdf:type rdf:resource="http://www.daml.org/2001/03/daml+oil#Thing"/>
    </rdf:Description>
    <rdf:Description rdf:ID="room_South">
        <rdf:type rdf:resource="http://www.daml.org/2001/03/daml+oil#Thing"/>
    </rdf:Description>
</rdf:RDF>

Bibliography

[STINY 1980]
Stiny, G. 1980. Introduction to shape and shape grammars. Environment and Planning B, Planning and Design, vol. 7, no. 3, 343-352.
[FLEMMING 1986]
Flemming, U. 1986. On the representation and generation of loosely-packed arrangements of rectangles. Environment and Planning B, Planning and Design, vol. 13, 189-205.

XHTML rendition created by gcapaper Web Publisher v2.0, © 2001-3 Schema Software Inc.