Constraint Topics

Constraints in NPCL are always represented as topics. Constraint topics are typed using the following NPCL-defined topic types.

Table 11.3. NPCL Constraint Topic Types

Constraint TypeRelative PSIDescription
Occurrence Constraintconstraints/occurrence-constraintConstraints of this type define the types of occurrences that are allowed on specific types of topic.
Role Player Constraintconstraints/role-player-constraintConstraints of this type define the types of association roles that can be played by specific types of topic.
Association Role Constraintconstraint/association-role-constraintConstraints of this type define the types of association roles that can be present in associations of a specific type.

Note

Relative PSIs are shown relative to the URI http://www.networkedplanet.com/psi/npcl/

Each constraint topic is connected to two or more typing topics using associations as described in the sections below.

Constraint Facets

Every constraint has two facets. The Minimum Cardinality Facet specifies the minimum number of times that the relationship defined by the constraint should occur for each instance that it applies to. The Maximum Cardinality Facet specifies the maximum number of times that the relationship should occur. The table below makes this clearer for each constraint type.

Table 11.4. Minimum And Maximum Cardinality Facet Meanings

Constraint TypeMinimum / Maximum Cardinality Facet Controls
Occurrence ConstraintThe number of occurrences of a specific type that should occur on each topic of a specific type.
Role Player ConstraintThe number of times a topic of a specific type can play a role of a specific type (optionally specific to one association type).
Association Role ConstraintThe number of times a role of a specific type can appear in an association of a specific type.

These facets are specified by adding occurrences to the constraint topic. The occurrence type for a Minimum Occurrence Facet must have the subject identifier http://www.networkedplanet.com/psi/npcl/facets/minimum-cardinality-facet. The occurrence type for a Maximum Occurrence Facet must have the subject identifier http://www.networkedplanet.com/psi/npcl/facets/maximum-cardinality-facet.

The Association Role Constraint also allows an Arc Label Facet where the facet value is a name for the association when viewed from the context of the role player. This facet value is NOT specified as an occurrence in XTM. Instead we use the common Topic Maps convention of specifying an arc label for an association using a base name on the association type, scoped by the role type. This is shown in the following example. To save space, the topics and associations that define the Association Role Constraints themselves are not shown (but a full example of this is given later in this chapter):

Example 11.5. The Arc Label Facet Expressed in XTM Syntax

<xtm:topicMap xmlns:xtm="...">

  <xtm:topic id="employment">
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef xlink:href="http://www.networkedplanet.com/psi/npcl/meta-types/association-type" />
    </xtm:instanceOf>
    <xtm:subjectIdentity>
      <xtm:subjectIndicatorRef xlink:href="http://www.networkedplanet.com/npcl/tests/employment" />
    </xtm:subjectIdentity>
    <xtm:baseName>
      <xtm:baseNameString>Employment</xtm:baseNameString>
    </xtm:baseName>

    <!-- Arc Label for the Employee Association Role -->
    <xtm:baseName>
      <xtm:scope><xtm:topicRef xlink:href="#employee"/></xtm:scope>
      <xtm:baseNameString>Works For</xtm:baseNameString>
    </xtm:baseName>

    <!-- Arc Label for the Employer Association Role -->
    <xtm:baseName>
      <xtm:scope><xtm:topicRef xlink:href="#employer"/></xtm:scope>
      <xtm:baseNameString>Employs</xtm:baseNameString>
    </xtm:baseName>
  </xtm:topic>

  <xtm:topic id="employer">
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef xlink:href="http://www.networkedplanet.com/psi/npcl/meta-types/association-role-type" />
    </xtm:instanceOf>
    <xtm:subjectIdentity>
      <xtm:subjectIndicatorRef xlink:href="http://www.networkedplanet.com/npcl/tests/employer" />
    </xtm:subjectIdentity>
    <xtm:baseName>
      <xtm:baseNameString>Employer</xtm:baseNameString>
    </xtm:baseName>
  </xtm:topic>

  <xtm:topic id="employee">
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef xlink:href="http://www.networkedplanet.com/psi/npcl/meta-types/association-role-type" />
    </xtm:instanceOf>
    <xtm:subjectIdentity>
      <xtm:subjectIndicatorRef xlink:href="http://www.networkedplanet.com/npcl/tests/employee" />
    </xtm:subjectIdentity>
    <xtm:baseName>
      <xtm:baseNameString>Employee</xtm:baseNameString>
    </xtm:baseName>
  </xtm:topic>

</xtm:topicMap>

Specifying An Occurrence Constraint

An Occurrence Constraint represents a restriction on the presence of occurrences of a defined type on topics of a defined type. Every Occurence Constraint must participate in the following associations.

Table 11.5. Associations Required To Specify An Occurrence Constraint

Association Type (Relative PSI)Constraint Role Type (Relative PSI)Target Role Type (Relative PSI)Target Topic Type (Relative PSI)
Occurrence Constraint Applies To Topic Type (constraints/oc-applies-to-tt)Occurrence Constraint Applies To Topic Type Source Role (constraint/oc-applies-to-tt-source)Occurrence Constraint Applies To Topic Type Target Role (constraints/oc-applies-to-tt-target)Topic Type (meta-types/topic-type)
Occurrence Constraint Allows Occurrence Type (constraints/oc-allows-ot)Occurrence Constraint Allows Occurrence Type Source Role (constraints/oc-allows-ot-source)Occurrence Constraint Allows Occurrence Type Target Role (constraints/oc-allows-ot-target)Occurrence Type (meta-types/occurrence-type)

Example 11.6. Example Occurrence Constraint

The following example shows an occurrence constraint that specifies that every Person topic has a single, optional Age occurrence.

<xtm:topicMap xmlns:xtm="..." xmlns:xlink="...">

  <!-- Not shown : Definitions of person and age topics. -->

  <!-- Person-Age Occcurrence Constraint -->
  <xtm:topic id="person-age-constraint">
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/occurrence-constraint"/>
    </xtm:instanceOf>
    <!-- Person must have 0 or 1 Age occurrence -->
    <xtm:occurrence>
      <xtm:instanceOf>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/facets/minimum-cardinality-facet"/>
      </xtm:instanceOf>
      <xtm:resourceData>0</xtm:resourceData>
    </xtm:occurrence>
    <xtm:occurrence>
      <xtm:instanceOf>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/facets/maximum-cardinality-facet"/>
      </xtm:instanceOf>
      <xtm:resourceData>1</xtm:resourceData>
    </xtm:occurrence>
  </xtm:topic>

  <!-- Person-Age constraint applies to Person topic type -->
  <xtm:association>
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/oc-applies-to-tt"/>
    </xtm:instanceOf>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/oc-applies-to-tt-source"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#person-age-constraint"/>
    </xtm:member>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/oc-applies-to-tt-target"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#person"/>
    </xtm:member>
  </xtm:association>

  <!-- Person-Age constraint constrains occurrences of type Age -->
  <xtm:association>
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/oc-allows-ot"/>
    </xtm:instanceOf>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/oc-allows-ot-source"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#person-age-constraint"/>
    </xtm:member>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/oc-allows-ot-target"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#age"/>
    </xtm:member>
  </xtm:association>

</xtm:topicMap>

Specifying A Role Player Constraint

A Role Player Constraint represents a relationship between a topic type and an association role type that specifies the number of times a topic of the topic type can play a role of the association role type. A third, optional, element of this constraint is an association type. If present, then the constraint applies only to the number of times a topic of the topic type can play a role of the association role type in an association of the association type. These three elements of the constraint are indicated by three separate association types as shown in the following table.

Table 11.6. Associations Used To Specify A Role Player Constraint

Association Type (Relative PSI)Constraint Role Type (Relative PSI)Target Role Type (Relative PSI)Target Topic Type (Relative PSI)
Role Player Constraint Applies To Topic Type (constraints/rpc-applies-to-tt)Role Player Constraint Applies To Topic Type Source Role (constraint/rpc-applies-to-tt-source)Role Player Constraint Applies To Topic Type Target Role (constraints/rpc-applies-to-tt-target)Topic Type (meta-types/topic-type)
Role Player Constraint Allows Role Type (constraints/rpc-allows-rt)Role Player Constraint Allows Role Type Source Role (constraints/rpc-allows-rt-source)Role Player Constraint Allows Role Type Target Role (constraints/rpc-allows-rt-target)Association Role Type (meta-types/association-role-type)
Role Player Constraint Allows Association Type (constraints/rpc-allows-at)Role Player Constraint Allows Association Type Source Role (constraints/rpc-allows-at-source)Role Player Constraint Allows Association Type Target Role (constraints/rpc-allows-at-target)Association Type (meta-types/association-type)

Example 11.7. A Role Player Constraint Specified In XTM

The following example shows a single Role Player Constraint that says that a topic of type "person" can play the role of type "employee" in an association of type "employment". Note that no minimum or maximum cardinality is specified for the constraint. This means that the default cardinalities will be applied (0 for minimum cardinality and unbounded for maximum cardinality).

<xtm:topicMap xmlns:xtm="..." xmlns:xlink="...">

  <!-- Not shown: Definitions of person, employee and employment topics -->

  <!-- Person-Employee Role Player Constraint -->
  <xtm:topic id="person-employee-constraint">
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/role-player-constraint"/>
    </xtm:instanceOf>
  </xtm:topic>

  <!-- Person-Employee constraint applies to Person topic type -->
  <xtm:association>
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/rpc-applies-to-tt"/>
    </xtm:instanceOf>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/rpc-applies-to-tt-source"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#person-employee-constraint"/>
    </xtm:member>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/rpc-applies-to-tt-target"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#person"/>
    </xtm:member>
  </xtm:association>

  <!-- Person-Employee constraint constrains roles of type Employee -->
  <xtm:association>
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/rpc-allows-rt"/>
    </xtm:instanceOf>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/rpc-allows-rt-source"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#person-employee-constraint"/>
    </xtm:member>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/rpc-allows-rt-target"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#employee"/>
    </xtm:member>
  </xtm:association>

  <!-- Person-Employee constraint constrains roles in associations of type Employment -->
  <xtm:association>
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/rpc-allows-at"/>
    </xtm:instanceOf>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/rpc-allows-at-source"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#person-employee-constraint"/>
    </xtm:member>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/rpc-allows-at-target"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#employment"/>
    </xtm:member>
  </xtm:association>

</xtm:topicMap>

Specifying An Association Role Constraint

An Association Role Constraint specifies a relationship between an association type and an association role type that defines how many roles of the association role type can appear on an association of the association type. To specify an Association Role Constraint, two associations are required, one between the constraint topic and the association type topic and one between the constraint topic and the association role type topic. The table below provides details of the associations required.

Table 11.7. Associations Required To Specify An Association Role Constraint

Association Type (Relative PSI)Constraint Role Type (Relative PSI)Target Role Type (Relative PSI)Target Topic Type (Relative PSI)
Association Role Constraint Applies To Association Type (constraints/arc-applies-to-at)Association Role Constraint Applies To Association Type Source Role (constraint/arc-applies-to-at-source)Association Role Constraint Applies To Association Type Target Role (constraints/arc-applies-to-at-target)Association Type (meta-types/association-type)
Association Role Constraint Allows Role Type (constraints/arc-allows-rt)Association Role Constraint Allows Role Type Source Role (constraints/arc-allows-rt-source)Association Role Constraint Allows Role Type Target Role (constraints/arc-allows-rt-target)Association Role Type (meta-types/association-role-type)

Example 11.8. An Association Role Constraint in XTM

The following example shows how to specify an Association Role Constraint in XTM syntax. The example shows a constraint the requires an association of type "employment" to have exactly one role of type "employee".

<xtm:topicMap xmlns:xtm="..." xmlns:xlink="...">

  <!-- Not defined : The topics employment and employee. -->

  <!-- Employment-Employee Constraint. -->
  <topic id="employment-employee-constraint">
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/association-role-constraint"/>
    </xtm:instanceOf>
    <!-- Employment association must have exactly 1 employee role -->
    <xtm:occurrence>
      <xtm:instanceOf>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/facets/minimum-cardinality-facet"/>
      </xtm:instanceOf>
      <xtm:resourceData>1</xtm:resourceData>
    </xtm:occurrence>
    <xtm:occurrence>
      <xtm:instanceOf>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/facets/maximum-cardinality-facet"/>
      </xtm:instanceOf>
      <xtm:resourceData>1</xtm:resourceData>
    </xtm:occurrence>
  </topic>

  <!-- Employment-Employee constraint applies to Employment association type -->
  <xtm:association>
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/arc-applies-to-at"/>
    </xtm:instanceOf>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/arcc-applies-to-at-source"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#employment-employee-constraint"/>
    </xtm:member>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/arc-applies-to-at-target"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#employment"/>
    </xtm:member>
  </xtm:association>

  <!-- Employment-Employee constraint constrains roles of type employee -->
  <xtm:association>
    <xtm:instanceOf>
      <xtm:subjectIndicatorRef 
           xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/arc-allows-rt"/>
    </xtm:instanceOf>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/arc-allows-rt-source"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#employment-employee-constraint"/>
    </xtm:member>
    <xtm:member>
      <xtm:roleSpec>
        <xtm:subjectIndicatorRef 
             xlink:href="http://www.networkedplanet.com/psi/npcl/constraints/arc-allows-rt-target"/>
      </xtm:roleSpec>
      <xtm:topicRef xlink:href="#employee"/>
    </xtm:member>
  </xtm:association>

</xtm:topicMap>