Types

If you look at the simple topic map shown in Sample 1, you will see that the topic does not really convey any meaning. There is nothing to indicate that the topic represents a company, nor is there anything to indicate how the occurrences are related to the topic. What we need is some way to indicate the type of 'thing' represented by the topic and the type of relationship between the topic and the resources identified or specified by the occurrences.

In topic maps types are defined, like almost everything else, by topics. We create a topic for the topic type or for the type of relationship between the topic and the occurrence resource and then use the <instanceOf> element with a nested <topicRef> element to reference the type-specifying topic. So to do this with our simple sample, we need to create some new topics as shown in Sample 2, below.

You can also see the principle of typing conceptually in Figure 3, where the different topic types are rendered as different shapes for the topics. In the diagram, the topics defining the types are shown as hollow shapes; the instances of those types are shown as solid shapes and the class-instance relationship is shown as a dashed line. However there are no restrictions placed on a topic used to define a type. A topic that is used to define a type can still be used like any other topic in the topic map and it is perfectly legal for a topic to be used as a type and to have one or more types of its own. This feature makes it possible to document both the ontology used by the topic map and the instances of that ontology, all with the same basic topic map mechanics.

<topicMap>
  <topic id="company">
    <baseName><baseNameString>Company</baseNameString></baseName>
  </topic>

  <topic id="homepage">
    <baseName><baseNameString>Home Page</baseNameString></baseName>
  </topic>

  <topic id="year-established">
    <baseName>
      <baseNameString>Year Established</baseNameString>
    </baseName>
  </topic>

  <topic id="xzyyz">
    <instanceOf>
      <topicRef xlink:href="#company"/>
    </instanceOf>
    <baseName>
	   <baseNameString>Redmond Computers Inc.</baseNameString>
	 </baseName>
	 <occurrence>
      <instanceOf>
        <topicRef xlink:href="#homepage"/>
      </instanceOf>
	   <resourceRef xlink:href="http://www.redmondcomputers.com/"/>
	 </occurrence>
	 <occurrence>
      <instanceOf>
        <topicRef xlink:href="#year-established"/>
      </instanceOf>
	   <resourceData>1977</resourceData>
	 </occurrence>
  </topic>

</topicMap>
        

Sample 2 - A topic map with types

Representation of a topic map showing different topic types

Figure 3 - A topic map with topic types (SVG version)

Each occurrence can only be of a single type; however, a topic may have multiple types, which are represented using multiple <instanceOf> elements. The <instanceOf> element asserts a class-instance relationship between the object containing the <instanceOf> element (be it a topic, occurrence or association) and the topic which is referenced from the <instanceOf> element.

It is important to understand that an instance-of relationship is not the same as a superclass-subclass relationship. It is a common mistake to think that mark-up like the fragment shown in Sample 3 represents a class-hierarchy "'mycorp' is a 'company', a 'company' is an 'organisation', therefore 'mycorp' is an 'organisation'". Unfortunately, that statement is not what is represented in the fragment. In fact the fragment asserts that "'mycorp' is a 'company' and 'company' is an 'organisation'." Not only is that English statement grammatically incorrect, the topic map is also semantically incorrect! What we really need to do is to create a subclass-superclass relationship between organisation and company. Such an association would make the assertion that "any company is an organisation". We will see how to do this later.

<topic id="organisation"/>
<topic id="company">
  <instanceOf><topicRef xlink:href="#organisation"/></instanceOf>
</topic>
<topic id="mycorp">
  <instanceOf><topicRef xlink:href="#company"/></instanceOf>
</topic>
        

Sample 3 - Not a class hierarchy

Up: Topic Map Basics
Previous: Topics Next: Name Variants