Part 21 Translator Home

Download of Prolog Code

The Prolog files available here allow the user to reproduce simple processing of Part 21 files (translated) and to examine the the base Prolog techniques used to navigate the information content of a (translated) Part 21 file. For such use these files should be saved to a common working directory

step_demo.pro
This file defines the initial Prolog environment (particularly the double quotation convention for string input) and also defines the predicates for navigating among the entities used in this example.
products.pro
This file defines a Prolog predicate (root/1) which generates a data structure (a Prolog compound term) which is equivalent to an XML view which is centered on the product entities of a Part 21 files, and treats the versions of a product and the product contexts in a file as essentially attributes of each product. This is the view which is called "products" in the examples generated by the online Prolog translator.
xml_output.pro
This file defines predicate which is satisfied for for the data structures generated by products:root predicate, and which as a side effect prints out the corresponding XML file.
body.pro
This is an example of a Part 21 file translated into Prolog facts; a similar file as generated by the Prolog translator may be substituted in the examples below.

These files were developed in the freely available Prolog interpreter SWI-Prolog, but only standard Prolog constructions are used and it should be possible to run these files in any comparable interpreter with only minor modification.

Simple Processing example:

The following terminal log is based on running the SWI-Prolog interpreter in a working directory containing the four files. Note that there is a simpler form for consulting files, namely [step_demo] in place of consult("step_demo.pro"), but the latter form is used here for clarity.

bash> swipl Welcome to SWI-Prolog (Multi-threaded, Version 5.4.7) Copyright (c) 1990-2003 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word).
The ? prefix is the user prompt; % labels output from the interpreter. The first user input instructs the interpreter to "consult" the file step_demo; that is read the file as a file of prolog predicates; The "Yes" response indicates that the consult goal was satisfied
?- consult("step_demo.pro"). % step_demo.pro compiled 0.01 sec, 4,908 bytes Yes
The following reads in the information content of the translated Part 21 file
?- consult("body.pro"). % body.pro compiled 0.55 sec, 863,920 bytes Yes
The first example of a query is to satisfy the goal instance_entity with a free variable as the instance -- this essentially is a search for all product entities in the part file. The interpreter returns an initial reply (X='#1567'), the following semicolon is user input instructing the interpreter to return the next solution; the reply "No" indicates there are no other solutions.
?- instance_entity(X,product). X = '#1567' ; No
The following query is to find the value of the attribute frame_of_reference of the entity found by the earlier query, the reply form Y=['#1567'] indicates the attribute is a list of one element which is itself an instance reference
?- instance_attribute_value('#1567',frame_of_reference,Y). Y = ['#1566'] ; No
The following input of the files products.pro and xml_output is the setup to generate the XML "view" of information content.
?- consult("products.pro"). % products.pro compiled into products 0.00 sec, 4,328 bytes Yes ?- consult("xml_output.pro"). % xml_output.pro compiled into xml_output 0.00 sec, 4,436 bytes Yes
The following compound predicate generates the XML model (and binds it to the variable X), then prints out the XML formatted model to standard output. Following the XML text is the Prolog interpreters return of the value X, which displays the compound Prolog term corresponding to the XML model.
?- products:root(X), write_xml_document(X). <?xml version='1.0' encoding='UTF-8'?> <products> <product_contexts_versions> <product> <id> 43</id> <name> car body</name> <description> inital formed car body; without wheels;</description> </product> <version> <id> 1</id> <description> PRODUCT_DEFINITION_FORMATION_DESCRIPTION</description> </version> <product_context> <discipline_type> mechanical</discipline_type> <name> MECHANICAL_CONTEXT_NAME</name> <frame_of_reference_application> CONFIGURATION CONTROLLED 3D DESIGNS OF MECHANICAL PARTS AND ASSEMBLIES</frame_of_reference_application> </product_context> </product_contexts_versions> </products> X = element(products, [], [element(product_contexts_versions, [], [element(product, [], [element(id, [], ["43"]), element(name, [], ["car body"]), element(description, [], [...])]), element(version, [], [element(id, [], ["1"]), element(description, [], [...])]), element(product_context, [], [element(discipline_type, [], [...]), element(..., ..., ...)|...])])]) ; No
The Prolog halt predicates ends the interpreter session
?- halt.