TermWare - JSR94 API

Related documents

XML representation of rule execution sets

Few examples

Format 1 - simple unstructured text

Most simple case of XML representation - just wrap definition in original termware language in XML element as text. So, root element is 'termware-text': all what is inside this element is original TermWare definitions.

DTD fragemnt looks as follow:


<!-- XML DTD --> 
<?xml version="1.0" encoding="utf-8"?>
<!-- One root element - TermWare and text inside on -->
<!ELEMENT termware-text (#PCDATA)>


For example, next definition:


    system(SemiGroup,default,
ruleset( ($x*$y)*$z -> $x*($y*$z) ),
FirstTop)
);


Will be look in XML syntax as:


<?xml  version="1.0"  encoding="utf-8"?>
<!DOCTYPE termware-text PUBLIC
"-//GradSoft//DTD TermWare ruleset form 1//EN"
"http://www.gradsoft.ua/dtd/termware-1.dtd">
<termware-text>
<![CDATA[

system(SemiGroup,default,
ruleset( ($x*$y)*$z -> $x*($y*$z) ),
FirstTop)
);

]]>

</termware-text>

Format 2 - XML element for rule set.

Next format, which can be useful - mark out XML elements for domains and systems. (System in Termware is analog of ruleset, with domains we can group systems into hierarchy). Name of system, facts db and strategy are attributes of system term.

DTD fragment looks as follow:


 <!-- XML DTD --> 
<?xml version="1.0" encoding="utf-8"?>
<! -->

<!ELEMENT termware domain>
<!ELEMENT domain (domain* system-text*) >
<!ATTLIST domain
name CDATA #REQUIRED
id NMTOKEN #IMPLIED
>
<!ELEMENT system-text (#PCDATA) >
<!ATTLIST system-text
name CDATA #REQUIRED,
facts CDATA #REQUIRED,
strategy CDATA #REQUIRED,
id NMTOKEN #IMPLIED
>

Example:




<termware>
<domain name="examples" >
<system-text name="Life" strategy="FirstTop" facts="ua.gradsoft.termwaredemos.life.Life1Facts" >
<![CDATA[

#@description born-of-new-cell
{ l($i,$j) : $T} [ n($i,$j) == 3 ] -> $T [ putCell($i,$j) ],

#@description static-cell
{ l($i,$j) : $T} [ n($i,$j) == 2 ] -> $T [ existsCell($i,$j) ? putCell($i,$j) : removeCell($i,$j) ] ,

#@description die-of-cell
{ l($i,$j) : $T} [ n($i,$j) > 3 || n($i,$j) < 2 ] -> $T [ removeCell($i,$j) ],


#@description empty-set
{ } -> checkEmpty($T) [ showGeneration(), generateNextTestSet($T) ],

#@description check-empty-notnull
checkEmpty({$x:$Y}) -> { $x:$Y },

#@description check-empty-null
checkEmpty({}) -> END

]]>
</system-text>
</domain>
</termware>

Format 3 - XML element for each rule.

In next level of detalization we can mark out XML element for each rule.:


<!--  XML  DTD  -->
<?xml version="1.0" encoding="utf-8"?>
<! -->

<!ELEMENT termware domain>
<!ELEMENT domain (domain* system*) >
<!ATTLIST domain
name CDATA #REQUIRED
id ID #IMPLIED
>
<!ELEMENT system (import-ruleset | rule-text)* >
<!ATTLIST system
name CDATA #REQUIRED,
facts CDATA #REQUIRED,
strategy CDATA #REQUIRED,
id ID #IMPLIED
>
<!ELEMENT import-ruleset (#PCDATA) >
<!ATTLIST import-ruleset
name CDATA #REQUIRED
id ID #IMPLIED
>
<!ELEMENT rule-text (#PCDATA) >
<!ATTLIST rule-text
name CDATA #IMPLIED
description PCDATA #IMPLIED
id ID #IMPLIED
>

Previous example can be rewriten as:




<domain name="examples" >
<system name="Life" strategy="FirstTop" facts="ua.gradsoft.termwaredemos.life.Life1Facts" >

<rule-text description="born-of-new-cell>
<![CDATA[
{ l($i,$j) : $T} [ n($i,$j) == 3 ] -> $T [ putCell($i,$j) ]
]]>
</rule-text>
<rule-text description="static cell">
<![CDATA[
{ l($i,$j) : $T} [ n($i,$j) == 2 ] -> $T [ existsCell($i,$j) ? putCell($i,$j) : removeCell($i,$j) ]
]]>
<rule-text description="die">
<![CDATA[
{ l($i,$j) : $T} [ n($i,$j) > 3 || n($i,$j) < 2 ] -> $T [ removeCell($i,$j) ]
]]>
</rule-text>
<rule-text description="empty set">
<![CDATA[
{ } -> checkEmpty($T) [ showGeneration() , generateNextTestSet($T) ],
]]>
</rule-text>
<rule-text description="check-empty-notempty">
<![CDATA[
checkEmpty({$x:$Y}) -> { $x:$Y },
]]>
</rule-text>
<rule-text description="check-empty-empty">
<![CDATA[
checkEmpty({}) -> END
]]>
</rule-text>
]]>
</system-text>
</domain>

DTD and attribute specifications

So, complete DTD is:




<?xml version="1.0" encoding="UTF-8"?>

<!--
Document : termware.dtd
Author : Ruslan Shevchenko
Description:
DTD for XML representation of TermWare systems


PUBLIC ID : -//GradSoft//DTD TermWare ruleset//EN
SYSTEM ID : http://www.gradsoft.ua/termware/termware.dtd
-->

<!ELEMENT termware (domain*) >
<!ELEMENT termware-text (#PCDATA) >
<!ELEMENT domain (domain | system | system-text )* >
<!ATTLIST domain
name CDATA #REQUIRED
id ID #IMPLIED
>
<!ELEMENT system (import-ruleset | rule-text)* >
<!ATTLIST system
name CDATA #REQUIRED
facts CDATA #REQUIRED
strategy CDATA #REQUIRED
id ID #IMPLIED
debug CDATA #IMPLIED
debug-entity CDATA #IMPLIED
pass-via CDATA #IMPLIED
>
<!ELEMENT import-ruleset (#PCDATA) >
<!ATTLIST import-ruleset
name CDATA #REQUIRED
id ID #IMPLIED
>
<!ELEMENT rule-text (#PCDATA) >
<!ATTLIST rule-text
name CDATA #IMPLIED
description CDATA #IMPLIED
id ID #IMPLIED
>


As you can see, all is evident. Some peculuarities:

Domain attributes:

Domain chidlren elements:

System attribute:

System child elements:

'import-ruleset' attributes:

Child elements are absent.

Properties of rule execution sets

Running JSR-94 TCK