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).
?- consult("step_demo.pro").
% step_demo.pro compiled 0.01 sec, 4,908 bytes
Yes
?- consult("body.pro").
% body.pro compiled 0.55 sec, 863,920 bytes
Yes
?- instance_entity(X,product).
X = '#1567' ;
No
?- instance_attribute_value('#1567',frame_of_reference,Y).
Y = ['#1566'] ;
No
?- 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
?- 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
?- halt.