Normalizer Inserts Map Attributes Too Much

From RuleML Wiki
Jump to: navigation, search

--Athant 12:42, 29 June 2012 (UTC)

1 Issue Description

In some sublanguages such as Datalog, the "map" attributes, such as mapClosure, are not allowed on some elements, such as <Implies>, but the Normalizer inserts these attributes if they are absent.

Unfortunately, the use of attributes with default values causes there to be different normal forms depending on the "target" sublanguage. This is because the normal form has all attributes with default values explicit.

For Version 1.0x, we need multiple normalizers. The one currently implemented applies to fologeq and up.

In Version 1.1, it would be best if we could eliminate the attributes with default values (see Default_or_Absent_Attributes).

2 Options

2.1 Option 1

In RuleML 1.01, the approach to attributes with default values has not been changed relative to RuleML 1.0. Therefore, it is still necessary to have multiple normalizers. The ones that are needed are:

  1. Hornlog without Equality (but can have Naf and Neg), or lesser;
  2. Hornlog with Equality (but can have Naf and Neg), or lesser (but excluding the previous);
  3. FOL without Equality (but can have Naf), or lesser (but excluding the previous);
  4. everything else.

The proposed implementation may be seen at http://deliberation.ruleml.org/1.01/xslt/normalizer

2.2 Option 2

If the approach to attributes with default values is changed, then a different strategy is necessary.

If all attributes with default values are removed, then it should be possible to have only one normalizer.

3 Discussion

4 Resolution

4.1 Relax NG Modules

The Relax NG Modules will be affected only in the case that the spproach to attributes with default values is changed.

4.2 Relax NG Drivers

The Relax NG Drivers will be affected only in the case that the spproach to attributes with default values is changed.

4.3 MYNG Engine

The MYNG Engine will be affected only in the case that the spproach to attributes with default values is changed.

4.4 MYNG GUI

The MYNG GUI will be affected only in the case that the spproach to attributes with default values is changed.

4.5 XSDs

The XSDs will be affected only in the case that the spproach to attributes with default values is changed.

4.6 Unit Tests

In the case of several normalizers, each needs to be tested on an appropriate input.

4.7 XSLT

In both options, the major change is to the Normalizer XSLT.

In Option 2, all Normalizer templates that make attributes with default values explicit would be deleted, and the same XSLT would be used for all RuleML sublanguages.

The Option 1 changes are shown below:

4.7.1 In Version 1.0

 <!-- Adds the material attribute with default value (yes) to Implies elements where this attribute is absent. -->
    <!-- Makes @material explicit. -->
    <!-- Makes @mapMaterial explicit. -->
    <!-- Makes @direction explicit. -->
    <!-- Makes @mapDirection explicit. -->
    <xsl:template match="r:Implies[not(@material) or not(@direction) or not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not(@material)">
                <xsl:attribute name="material">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@direction)">
                <xsl:attribute name="direction">bidirectional</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@mapMaterial)">
                <xsl:attribute name="mapMaterial">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@mapDirection)">
                <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- Makes @val explicit. -->
    <!-- Makes @per explicit. -->
    <xsl:template match="r:Fun[not(@val)or not(@per)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not (@val)">
                <xsl:attribute name="val">0..</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@per)">
                <xsl:attribute name="per">copy</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- Makes @oriented explicit. -->
    <xsl:template match="r:Equal[not(@oriented)]" mode="phase-3">
        <xsl:copy>
            <xsl:attribute name="oriented">no</xsl:attribute>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>

4.7.2 In Version 1.01 nafneghornlog

 <!-- Adds attributes with default values to Node elements where these attribute is absent. -->
  <!-- For Implies -->
  <!-- Makes @material explicit. -->
  <!-- Makes @direction explicit. -->
  <xsl:template match="r:Implies[not(@material) or not(@direction)]" mode="phase-3">
    <xsl:copy>
      <xsl:if test="not(@material)">
        <xsl:attribute name="material">yes</xsl:attribute>
      </xsl:if>
      <xsl:if test="not(@direction)">
        <xsl:attribute name="direction">bidirectional</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="node() | @*" mode="phase-3"/>
    </xsl:copy>
  </xsl:template>
  
  <!-- For Assert -->
  <!-- Makes @mapMaterial explicit. -->
  <!-- Makes @mapDirection explicit. -->
  <xsl:template match="r:Assert[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
    <xsl:copy>
      <xsl:if test="not(@mapMaterial)">
        <xsl:attribute name="mapMaterial">yes</xsl:attribute>
      </xsl:if>
      <xsl:if test="not(@mapDirection)">
        <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="node() | @*" mode="phase-3"/>
    </xsl:copy>
  </xsl:template>
  
  <!-- For Retract -->
  <!-- Makes @mapMaterial explicit. -->
  <!-- Makes @mapDirection explicit. -->
  <xsl:template match="r:Retract[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
    <xsl:copy>
      <xsl:if test="not(@mapMaterial)">
        <xsl:attribute name="mapMaterial">yes</xsl:attribute>
      </xsl:if>
      <xsl:if test="not(@mapDirection)">
        <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="node() | @*" mode="phase-3"/>
    </xsl:copy>
  </xsl:template>

  <!-- for Rulebase -->
  <!-- Makes @mapMaterial explicit. -->
  <!-- Makes @mapDirection explicit. -->
  <xsl:template match="r:Rulebase[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
    <xsl:copy>
      <xsl:if test="not(@mapMaterial)">
        <xsl:attribute name="mapMaterial">yes</xsl:attribute>
      </xsl:if>
      <xsl:if test="not(@mapDirection)">
        <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="node() | @*" mode="phase-3"/>
    </xsl:copy>
  </xsl:template>
  
    <!-- for Fun -->
    <!-- Makes @per explicit. -->
    <xsl:template match="r:Fun[not(@per)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not(@per)">
                <xsl:attribute name="per">copy</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>

   <!-- for Expr -->
  <!-- Makes @per explicit. -->
  <xsl:template match="r:Expr[not(@per)]" mode="phase-3">
    <xsl:copy>
      <xsl:if test="not(@per)">
        <xsl:attribute name="per">copy</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="node() | @*" mode="phase-3"/>
    </xsl:copy>
  </xsl:template>

4.7.3 In Version 1.01 nafneghornlogeq

Modify the templates for Fun and Expr, and add a template for Equal:

   --- 101_nafneghornlog_normalizer.xslt	2014-05-02 16:34:36.000000000 -0400
  +++ 101_nafneghornlogeq_normalizer.xslt	2014-05-02 16:38:11.000000000 -0400
  @@ -644,8 +644,12 @@
     
     <!-- for Fun -->
     <!-- Makes @per explicit. -->
  -  <xsl:template match="r:Fun[not(@per)]" mode="phase-3">
  +  <!-- Makes @val explicit. -->
  +  <xsl:template match="r:Fun[not(@val)or not(@per)]" mode="phase-3">
           <xsl:copy>
  +            <xsl:if test="not (@val)">
  +                <xsl:attribute name="val">0..</xsl:attribute>
  +            </xsl:if>
               <xsl:if test="not(@per)">
                   <xsl:attribute name="per">copy</xsl:attribute>
               </xsl:if>
  @@ -663,6 +667,15 @@
         <xsl:apply-templates select="node() | @*" mode="phase-3"/>
       </xsl:copy>
     </xsl:template>
  +  
  +    <!-- for Equal -->
  +    <!-- Makes @oriented explicit. -->
  +    <xsl:template match="r:Equal[not(@oriented)]" mode="phase-3">
  +        <xsl:copy>
  +            <xsl:attribute name="oriented">no</xsl:attribute>
  +            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
  +        </xsl:copy>
  +    </xsl:template>
       
       <!-- Adds the required index attribute to the arg tag 
           There are errors with the indexing when the argument is within a slot-->

4.7.4 In Version 1.01 naffolog

Modified templates:

 <!-- For Implies -->
   <!-- Makes @material explicit. -->
   <!-- Makes @direction explicit. -->
-  <xsl:template match="r:Implies[not(@material) or not(@direction)]" mode="phase-3">
+  <!-- Makes @mapMaterial explicit. -->
+  <!-- Makes @mapDirection explicit. -->
+  <xsl:template match="r:Implies[not(@material) or not(@direction) or 
+                           not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
      <xsl:copy>
          <xsl:if test="not(@material)">
                <xsl:attribute name="material">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@direction)">
                <xsl:attribute name="direction">bidirectional</xsl:attribute>
            </xsl:if>
+            <xsl:if test="not(@mapMaterial)">
+                <xsl:attribute name="mapMaterial">yes</xsl:attribute>
+            </xsl:if>
+            <xsl:if test="not(@mapDirection)">
+                <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
+            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>

New templates:

   <!-- for Query -->
  <!-- Makes @mapMaterial explicit. -->
  <!-- Makes @mapDirection explicit. -->
  <xsl:template match="r:Query[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
    <xsl:copy>
      <xsl:if test="not(@mapMaterial)">
        <xsl:attribute name="mapMaterial">yes</xsl:attribute>
      </xsl:if>
      <xsl:if test="not(@mapDirection)">
        <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="node() | @*" mode="phase-3"/>
    </xsl:copy>
  </xsl:template>

  <!-- for Equivalent -->
    <!-- Makes @mapMaterial explicit. -->
    <!-- Makes @mapDirection explicit. -->
    <xsl:template match="r:Equivalent[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not(@mapMaterial)">
                <xsl:attribute name="mapMaterial">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@mapDirection)">
                <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- for And -->
    <!-- Makes @mapMaterial explicit. -->
    <!-- Makes @mapDirection explicit. -->
    <xsl:template match="r:And[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not(@mapMaterial)">
                <xsl:attribute name="mapMaterial">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@mapDirection)">
                <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- for Or -->
    <!-- Makes @mapMaterial explicit. -->
    <!-- Makes @mapDirection explicit. -->
    <xsl:template match="r:Or[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not(@mapMaterial)">
                <xsl:attribute name="mapMaterial">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@mapDirection)">
                <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- for Naf -->
    <!-- Makes @mapMaterial explicit. -->
    <!-- Makes @mapDirection explicit. -->
    <xsl:template match="r:Naf[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not(@mapMaterial)">
                <xsl:attribute name="mapMaterial">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@mapDirection)">
                <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- for Neg -->
    <!-- Makes @mapMaterial explicit. -->
    <!-- Makes @mapDirection explicit. -->
    <xsl:template match="r:Neg[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not(@mapMaterial)">
                <xsl:attribute name="mapMaterial">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@mapDirection)">
                <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- for Forall -->
    <!-- Makes @mapMaterial explicit. -->
    <!-- Makes @mapDirection explicit. -->
    <xsl:template match="r:Forall[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not(@mapMaterial)">
                <xsl:attribute name="mapMaterial">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@mapDirection)">
                <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>
    
    <!-- for Exists -->
    <!-- Makes @mapMaterial explicit. -->
    <!-- Makes @mapDirection explicit. -->
    <xsl:template match="r:Exists[not(@mapMaterial) or not(@mapDirection)]" mode="phase-3">
        <xsl:copy>
            <xsl:if test="not(@mapMaterial)">
                <xsl:attribute name="mapMaterial">yes</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(@mapDirection)">
                <xsl:attribute name="mapDirection">bidirectional</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="node() | @*" mode="phase-3"/>
        </xsl:copy>
    </xsl:template>

4.7.5 In Version 1.01 naffologeq

Modify the templates for Fun and Expr, and add a template for Equal:

   --- 101_naffolog_normalizer.xslt	2014-05-02 17:03:13.000000000 -0400
  +++ 101_naffologeq_normalizer.xslt	2014-05-02 17:13:40.000000000 -0400
  @@ -813,8 +813,12 @@
   
     <!-- for Fun -->
     <!-- Makes @per explicit. -->
  -  <xsl:template match="r:Fun[not(@per)]" mode="phase-3">
  +  <!-- Makes @val explicit. -->
  +  <xsl:template match="r:Fun[not(@val)or not(@per)]" mode="phase-3">
       <xsl:copy>
  +      <xsl:if test="not (@val)">
  +        <xsl:attribute name="val">0..</xsl:attribute>
  +      </xsl:if>
         <xsl:if test="not(@per)">
           <xsl:attribute name="per">copy</xsl:attribute>
         </xsl:if>
  @@ -833,6 +837,15 @@
       </xsl:copy>
     </xsl:template>
   
  +  <!-- for Equal -->
  +  <!-- Makes @oriented explicit. -->
  +  <xsl:template match="r:Equal[not(@oriented)]" mode="phase-3">
  +    <xsl:copy>
  +      <xsl:attribute name="oriented">no</xsl:attribute>
  +      <xsl:apply-templates select="node() | @*" mode="phase-3"/>
  +    </xsl:copy>
  +  </xsl:template>
  +
     <!-- Adds the required index attribute to the arg tag 
           There are errors with the indexing when the argument is within a slot-->
     <xsl:template match="r:arg[namespace-uri(.)='http://ruleml.org/spec']" mode="phase-3">

5 References