The approach of this toolkit was suggested by the observation that a central task in querying a STEP based dataset is navigating between entity instances. This is particularly true for the datasets based on STEP AIM (application-interpreted model) schema, in which the entity definitions are fine-grained (i.e. large number of entities with relatively few attributes) and in which entity relations are often expressed indirectly through a third entity. Working with Prolog allows these relations between entities to be declared as logic statements referencing the instance_entity and instance_attribute value facts defining a dataset. Once a relation is defined, navigating among instances is equivalent to testing the truth of this logical statement in the context of a particular dataset.
The simplest relation between instances is expressed when one instance contains a reference to another as the value of one of its attributes. An example of this from the EXPRESS product_definition_schema of Part 41 of STEP is the relation connecting the product entity and the product_definition_formation (considered the version) entity. An instance of a product_definition_formation entity has an attribute of_product whose value is a reference to an instance of the product_entity. Table 1 shows a graphical representation of this relation between two instances and the prolog predicate which declares this particular relation; the prolog predicate states essentially:
|
Prolog predicate
product_to_version(X,Y) :-
instance_entity(X, product),
instance_attribute_value(X,of_product,Y),
instance_entity(Y, product_definition_formation).
|
|
| Example 1: Relation between two entities defined through an entity attribute. (note: version is an alias used for the entity product_definition_formation in this example) | |
So far this work has restated a small part of the semantics of an EXPRESS schema as a prolog predicate, and has expressed the information content of a Part 21 file as a collection of Prolog facts. The payoff comes from using the Prolog interpreter's built-in features of unification and backtracking. This allows invocation of this single prolog predicate to perform searches and navigation in four distinct cases. The predicate product_to_version can be invoked with either (or both) of the arguments unified with a value or a free variable. For this predicate an appropriate bound value would be a Prolog atom denoting an instance, for example the atom represented as '#23'. In the case of a STEP file in which instance #23 is a product instance and #39 is a version (entity product_definition_formation) instance, the prolog goal:
will succeed, and the variable X will be unified with the atom '#39', thereby performing the product to version navigation. The Prolog goal:
will succeed with X unified with '#23'; implementing the version to product navigation with the same user code. The goal
will succeed, while
will fail. This use allows the predicate product_to_version to function as a boolean test, while finally the goal
acts as a general search, returning all (product, version) pairs in the STEP file.
In this example the relation between product and version entities was defined in the EXPRESS schema in a way which satisfied an information modelling requirement that the the product entity by independent of the product_definition_formation (version) entity. This leads to what has been called a "reverse reference", from the point of view that an application most typically has a product instance and needs to find versions of that product. Finding these versions requires searching through all instances of a product for those which contain the product_definition_formation and testing the of_product attribute. The requirement to prepare code for these types of searches has been noted as an obstacle to preparing STEP application software. The implementation in Prolog sidesteps the need for a developer to write such code as the searching and testing is done automatically by the Prolog execution engine.
These Prolog navigation predicates are readily prepared for other mechanisms by which relations between entities are defined in EXPRESS schema. In the representation_schema of Part 43 of STEP the entity representation contains an attribute items whose value is an EXPRESS SET of (reference to) representation_item entities. The Prolog predicate below expresses this relation (using the Prolog standard predicate member); and this predicate representation_to_representation_item can be used to navigate either from representation_item to representation or oppositely.
|
Prolog predicate
representation_to_representation_item(X,Y) :-
instance_entity(X, representation),
instance_attribute_value(Rep,items, ItemList),
member(Y,ItemList),
instance_entity(Y, representation_item).
|
|
| Example 2: Relation between entities defined through an entity attribute; for which one instance references a collection of instances of another entity. | |
A third way to express relations between instances of a dataset is via a third instance which "connects" the two. This mechanism is used in the product_property_representation_schema schema of Part 41 to connect a product_definition_shape instance with a concrete shape_representation instance. An intermediary instance of the entity shape_definition_representation connects the two as depicted in Example 3 below. Also shown in the Prolog predicate which asserts this relation and, as before, can be used to navigate in either direction between a product_definition_shape and a shape representation.
|
Prolog predicate
shape_property_to_representation(X,Y) :-
instance_entity(X,product_definition_shape),
instance_entity(Z,shape_definition_representation),
instance_attribute_value(Z,definition,X),
instance_attribute_value(Z,used_representation,Y),
instance_entity(Y,shape_representation).
|
|
| Example 3: A relation defined between two instances defined through a third instance | |
The syntax of the Prolog language allows predicates such as defined above to be easily combined. For example, given Examples 2 and 3 above, and since shape_representation is a subtype of representation (that is, any instance which contains a shape_representation also contains a representation) it is meaningful to combine these example and write a Prolog predicate which asserts the relation between a shape_representation and the the representation_items which specify it as: