File size: 5,477 Bytes
965a0bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://nlp.stanford.edu/CoreNLP/v1">

<xsl:output method="html"/>

<xsl:template match="/">
  <html>
  <body>
    <center><h2>Stanford CoreNLP XML Output</h2></center>
    <hr size="3" color="#333333"/>
    <center><h3>Document</h3></center>

    <table border="1" style="background-color:#f0f0f0;" align="center">
    <tr><th>Document Info</th></tr>
    <tr><td>
    <xsl:if test="root/document/docId">
        <br/><i>DocId</i>: <xsl:value-of select="root/document/docId"/>
    </xsl:if>
    <xsl:if test="root/document/docDate">
        <br/><i>DocDate</i>: <xsl:value-of select="root/document/docDate"/>
    </xsl:if>
    <xsl:if test="root/document/docSourceType">
        <br/><i>DocSourceType</i>: <xsl:value-of select="root/document/docSourceType"/>
    </xsl:if>
    <xsl:if test="root/document/docType">
        <br/><i>DocType</i>: <xsl:value-of select="root/document/docType"/>
    </xsl:if>
    <xsl:if test="root/document/author">
        <br/><i>Author</i>: <xsl:value-of select="root/document/author"/>
    </xsl:if>
    <xsl:if test="root/document/location">
        <br/><i>Location</i>: <xsl:value-of select="root/document/location"/>
    </xsl:if>
    </td></tr>

    <xsl:if test="root/document/text">
        <tr><th>Text</th></tr>
        <tr><td>
            <div class="preformatted">
              <xsl:value-of select="root/document/text"/>
            </div>
        </td></tr>
    </xsl:if>

    <tr><th>Sentences</th></tr>
    <xsl:for-each select="root/document/sentences/sentence">
      <tr><td>
      <xsl:apply-templates select=".">
        <xsl:with-param name="position" select="position()"/>
      </xsl:apply-templates>
      </td></tr>
    </xsl:for-each>
    
    <tr><th>Coreference resolution graph</th></tr>
    <tr><td>
    <xsl:apply-templates select="root/document/coreference"/>
    </td></tr>
    </table>

  </body>
  </html>
</xsl:template>

<xsl:template match="root/document/sentences/sentence">
  <xsl:param name="position" select="'0'"/>
  <p><i><b>Sentence #<xsl:value-of select="$position"/></b></i>
  <xsl:if test="@sentiment">
        <xsl:text> Sentiment: </xsl:text><xsl:value-of select="@sentiment"/>
  </xsl:if>
  </p>

  <p>
  <i>Tokens</i><br/>
  <xsl:apply-templates select="tokens"/>
  </p>

  <p>
  <i>Parse tree</i><br/>
  <xsl:value-of select="parse"/>
  </p>

  <p>
  <i>Uncollapsed dependencies</i>
  <ul>
  <xsl:for-each select="dependencies[@type='basic-dependencies']">
    <xsl:apply-templates select="dep"/>
  </xsl:for-each>
  </ul>
  </p>

  <p>
  <i>Enhanced dependencies</i>
  <ul>
  <xsl:for-each select="dependencies[@type='collapsed-ccprocessed-dependencies']">
    <xsl:apply-templates select="dep"/>
  </xsl:for-each>
  </ul>
  </p>
</xsl:template>

<xsl:template match="tokens">
  <table border="1">
  <tr>
    <th>Id</th>
    <th>Word</th>
    <th>Lemma</th>
    <th>Char begin</th>
    <th>Char end</th>
    <th>POS</th>
    <th>NER</th>
    <th>Normalized NER</th>
    <th>Speaker</th>
    <th>Sentiment</th>
  </tr>
  <xsl:for-each select="token">
    <tr>
      <td><xsl:value-of select="@id"/></td>
      <td><xsl:value-of select="word"/></td>
      <td><xsl:value-of select="lemma"/></td>
      <td><xsl:value-of select="CharacterOffsetBegin"/></td>
      <td><xsl:value-of select="CharacterOffsetEnd"/></td>
      <td><xsl:value-of select="POS"/></td>
      <td><xsl:value-of select="NER"/></td>
      <td><xsl:value-of select="NormalizedNER"/></td>
      <td><xsl:value-of select="Speaker"/></td>
      <td><xsl:value-of select="sentiment"/></td>
    </tr>
  </xsl:for-each>
  </table>
</xsl:template>

<xsl:template match="dependencies">
  <ul>
  <xsl:for-each select="dep">
    <xsl:apply-templates select="."/>
  </xsl:for-each>
  </ul>
</xsl:template>

<xsl:template match="dep">
    <li>
      <xsl:value-of select="@type"/>
      (
      <xsl:value-of select="governor"/><xsl:if test="governor/@copy">^<xsl:value-of select="governor/@copy"/></xsl:if>-<xsl:value-of select="governor/@idx"/>
      ,
      <xsl:value-of select="dependent"/><xsl:if test="dependent/@copy">^<xsl:value-of select="dependent/@copy"/></xsl:if>-<xsl:value-of select="dependent/@idx"/>
      ) 
      <xsl:if test="@extra">(extra)</xsl:if>
    </li>
</xsl:template>

<xsl:template match="coreference">
  <ol>
  <xsl:for-each select="coreference">
    <li>
        <table border="1">
        <tr>
            <th>Sentence</th>
            <th>Head</th>
            <th>Text</th>
            <th>Context</th>
        </tr>
        <xsl:for-each select="mention">
            <tr>
                <td><xsl:value-of select="sentence"/></td>
                <td><xsl:value-of select="head"/> <xsl:if test="@representative"> (gov) </xsl:if></td>
                <td><xsl:value-of select="text"/></td>
                <td><xsl:if test="leftContext or rightContext">
                    ...<xsl:value-of select="leftContext"/>
                    <span style="background-color: #99ff99;">
                      <xsl:text> </xsl:text>
                      <xsl:value-of select="text"/></span>
                      <xsl:text> </xsl:text>
                    <xsl:value-of select="rightContext"/>...
                    </xsl:if>
                </td>
            </tr>
        </xsl:for-each>
        </table>
    </li>
  </xsl:for-each>
  </ol>
</xsl:template>

</xsl:stylesheet>