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

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:i="http://bogusnamespace.com/inference_pilot_evaluation/annotation"
xmlns:d="http://bogusnamespace.com/sentenceInfo">

<xsl:output method="html"/>


<xsl:template match="/">
  <html>
  <body>
  <table width="100%" border="0" cellpadding="5">
  <tr><td>
    <h2>RTE XML Output</h2>
    <xsl:apply-templates select="root/i:inferenceList/i:inference"/>
  </td></tr>
  </table>
  </body>
  </html>
</xsl:template>


<xsl:template match="i:inference">
  <hr size="3" color="#333333"/>
  <h3>Inference ID: <xsl:value-of select="@id"/></h3>

  <i>Passage (id = <xsl:value-of select="i:passage/@id"/>):</i>
  <br/>
  <b><xsl:value-of select="i:passage"/></b><br/><br/>
  <xsl:variable name="pDocID"><xsl:value-of select="i:passage/@id"/></xsl:variable>
  <xsl:apply-templates select="/root/d:documentList/d:docInfo[@id=$pDocID]"/>
  <br/>

  <xsl:if test="not(i:question='')">
  <i>Question (id = <xsl:value-of select="i:question/@id"/>):</i>
  <br/>
  <b><xsl:value-of select="i:question"/></b><br/>
  <br/>
  </xsl:if>

  <i>Hypothesis (id = <xsl:value-of select="i:hypothesis/@id"/>):</i>
  <br/>
  <b><xsl:value-of select="i:hypothesis"/></b><br/><br/>
  <xsl:variable name="hDocID"><xsl:value-of select="i:hypothesis/@id"/></xsl:variable>
  <xsl:apply-templates select="/root/d:documentList/d:docInfo[@id=$hDocID]"/>
  <br/>

  <xsl:apply-templates select="i:answer"/>
  <br/>
</xsl:template>


<xsl:template match="d:docInfo">
  <table width="1" border="1" style="background-color:#CCCCCC;">
  <tr><td>Document Info:</td></tr>
  <xsl:for-each select="d:sentenceInfo">
    <tr><td>
      <xsl:apply-templates select=".">
        <xsl:with-param name="pos" select="position()"/>
      </xsl:apply-templates>
    </td></tr>
  </xsl:for-each>
  </table>
</xsl:template>


<xsl:template match="d:sentenceInfo">
  <xsl:param name="pos" select="'0'"/>

  <i>Sentence #<xsl:value-of select="$pos"/></i><br/>
  <xsl:value-of select="d:sentence"/><br/><br/>

  <i>Word Table:</i><br/>
  <xsl:apply-templates select="d:wordTable"/><br/>

  <i>Parse Tree:</i>
  <pre><xsl:value-of select="d:parse"/></pre>

  <i>Typed Dependencies:</i>
  <xsl:apply-templates select="d:dependencyParse"/>

  <i>Semantic Role Labels:</i>
  <xsl:apply-templates select="d:srlTable"/>

  <i>Logical Form:</i><br/>
  <xsl:apply-templates select="d:logicalForm"/>
</xsl:template>


<xsl:template match="d:wordTable">
  <table border="1">
  <tr>
    <th>id</th>
    <th>word</th>
    <th>lemma</th>
    <th>stem</th>
    <th>POS</th>
    <th>nerTag</th>
    <th>nerID</th>
    <th>ner</th>
    <th>nerNormalized</th>
    <th>polarity</th>
    <th>idf</th>
  </tr>
  <xsl:for-each select="d:wordInfo">
    <tr>
      <td><xsl:value-of select="@id"/></td>
      <td><xsl:value-of select="d:word"/></td>
      <td><xsl:value-of select="d:lemma"/></td>
      <td><xsl:value-of select="d:stem"/></td>
      <td><xsl:value-of select="d:POS"/></td>
      <td><xsl:value-of select="d:nerTag"/></td>
      <td><xsl:value-of select="d:nerInfo/d:nerID"/></td>
      <td><xsl:value-of select="d:nerInfo/d:ner"/></td>
      <td><xsl:value-of select="d:nerInfo/d:normalized"/></td>
      <td><xsl:value-of select="d:polarity"/></td>
      <td><xsl:value-of select="d:idf"/></td>
    </tr>
  </xsl:for-each>
  </table>
</xsl:template>


<xsl:template match="d:dependencyParse">
  <ul>
  <xsl:for-each select="d:dependency">
    <xsl:variable name="govID">
      <xsl:value-of select="d:governor"/>
    </xsl:variable>
    <xsl:variable name="depID">
      <xsl:value-of select="d:dependent"/>
    </xsl:variable>
    <li>
      <xsl:value-of select="d:relation"/>
      (
      <xsl:value-of select="../../d:wordTable/d:wordInfo[@id=$govID]/d:word"/>-<xsl:value-of select="$govID"/>
      ,
      <xsl:value-of select="../../d:wordTable/d:wordInfo[@id=$depID]/d:word"/>-<xsl:value-of select="$depID"/>
      )
    </li>
  </xsl:for-each>
  </ul>
</xsl:template>

<xsl:template match="d:srlTable">
  <ul>
  <xsl:for-each select="d:srlType">
    <xsl:variable name="predID">
      <xsl:value-of select="d:predicate"/>
    </xsl:variable>
    <xsl:variable name="argID">
      <xsl:value-of select="d:argument"/>
    </xsl:variable>
    <li>
      <xsl:value-of select="d:label"/>
      (
      <xsl:value-of select="../../d:wordTable/d:wordInfo[@id=$predID]/d:word"/>-<xsl:value-of select="$predID"/>
      ,
      <xsl:value-of select="../../d:wordTable/d:wordInfo[@id=$argID]/d:word"/>-<xsl:value-of select="$argID"/>
      )
    </li>
  </xsl:for-each>
  </ul>
</xsl:template>


<xsl:template match="d:logicalForm">
  <xsl:for-each select="d:term">
    <xsl:variable name="predID">
      <xsl:value-of select="d:word/@id"/>
    </xsl:variable>
    <xsl:value-of select="../../d:wordTable/d:wordInfo[@id=$predID]/d:POS"/>:<xsl:value-of select="../../d:wordTable/d:wordInfo[@id=$predID]/d:word"/>&#160;[&#160;<xsl:value-of select="$predID"/>&#160;<xsl:for-each select="d:argument">&#160;<xsl:value-of select="d:argRefNumber"/>&#160;</xsl:for-each>]&#160;&#160;&#160;
  </xsl:for-each>
</xsl:template>


<xsl:template match="i:answer">
  <i>Answer #<xsl:value-of select="@id"/> (polarity = <xsl:value-of select="@polarity"/>, force = <xsl:value-of select="@force"/>, source = <xsl:value-of select="@source"/>)</i><br/>
    <xsl:value-of select="i:response"/>
  <br/>
</xsl:template>


</xsl:stylesheet>

