-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpeg72rdf.xslt
200 lines (184 loc) · 15.6 KB
/
mpeg72rdf.xslt
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
190
191
192
193
194
195
196
197
198
199
200
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:mpeg7="http://mpeg7.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lmdr="http://spider.sigappfr.org/linkedmdr/#" xmlns:tei="http://www.tei-c.org/release/doc/tei-p5-doc/en/html/#" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="document">
<xsl:apply-templates select="//mpeg7:MediaUri" />
</xsl:variable>
<xsl:variable name="image" select="concat($document,'.image')" />
<xsl:variable name="mainstillregion" select="concat($document,'.stillregion.','main')" />
<xsl:template match="/">
<!--This is to resolve the namespace when & is used within attribute values-->
<xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE rdf:RDF [
<!ENTITY lmdr "http://spider.sigappfr.org/linkedmdr/#" >
<!ENTITY mpeg7 "http://mpeg7.org/" >
<!ENTITY tei "http://www.tei-c.org/release/doc/tei-p5-doc/en/html/#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >]>]]>
</xsl:text>
<xsl:text disable-output-escaping="yes"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:lmdr="http://spider.sigappfr.org/linkedmdr/#"
xmlns:mpeg7="http://mpeg7.org/"
xmlns:tei="http://www.tei-c.org/release/doc/tei-p5-doc/en/html/#">
</xsl:text>
<xsl:text disable-output-escaping="yes">
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="$document"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&lmdr;Document"/>
<lmdr:hasPart_Object>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="$image"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&mpeg7;Image"/>
<lmdr:hasPart_mpeg7Image>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="$mainstillregion"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&mpeg7;StillRegion"/></xsl:text>
<xsl:apply-templates select="//mpeg7:Descriptor" />
<xsl:apply-templates select="//mpeg7:VisualDescriptor[parent::mpeg7:Image]" />
<xsl:apply-templates select="//mpeg7:StillRegion"/>
<xsl:apply-templates select="//mpeg7:Semantic/mpeg7:SemanticBase[@xsi:type='ObjectType']" />
<xsl:text disable-output-escaping="yes"></rdf:Description>
</lmdr:hasPart_mpeg7Image>
</rdf:Description>
</lmdr:hasPart_Object>
</rdf:Description></xsl:text>
<xsl:text disable-output-escaping="yes"></rdf:RDF></xsl:text>
</xsl:template>
<xsl:template match="mpeg7:Semantic/mpeg7:SemanticBase">
<xsl:text disable-output-escaping="yes">
<lmdr:isAssociatedTo>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.semanticdescription.',generate-id(.))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&mpeg7;SemanticDescription"/>
<lmdr:hasPart_mpeg7SemanticDescription>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.object.',generate-id(./mpeg7:Label/mpeg7:Name))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&mpeg7;Object"/>
<lmdr:hasValue></xsl:text><xsl:value-of select="./mpeg7:Label/mpeg7:Name"/>
<xsl:text disable-output-escaping="yes"></lmdr:hasValue>
</rdf:Description>
</lmdr:hasPart_mpeg7SemanticDescription>
</rdf:Description>
</lmdr:isAssociatedTo></xsl:text>
</xsl:template>
<xsl:template match="mpeg7:StillRegion">s
<xsl:text disable-output-escaping="yes">
<lmdr:hasPart_mpeg7StillRegion>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.stillregion.',generate-id(.))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&mpeg7;</xsl:text><xsl:value-of select="local-name(.)"/><xsl:text disable-output-escaping="yes">"/></xsl:text>
<xsl:apply-templates select="./mpeg7:VisualDescriptor" />
<xsl:apply-templates select="./mpeg7:TextAnnotation/mpeg7:FreeTextAnnotation" />
<xsl:text disable-output-escaping="yes">
</rdf:Description>
</lmdr:hasPart_mpeg7StillRegion></xsl:text>
</xsl:template>
<xsl:template match="mpeg7:TextAnnotation/mpeg7:FreeTextAnnotation">
<xsl:text disable-output-escaping="yes">
<lmdr:hasPart_mpeg7StillRegion>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.imageannotation.',generate-id(.))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&lmdr;ImageAnnotation"/>
<lmdr:hasPart_Object>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.sentence.',generate-id(.))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&tei;s"/>
<lmdr:hasValue></xsl:text><xsl:value-of select="."/><xsl:text disable-output-escaping="yes"></lmdr:hasValue>
</rdf:Description>
</lmdr:hasPart_Object>
</rdf:Description>
</lmdr:hasPart_mpeg7StillRegion></xsl:text>
</xsl:template>
<xsl:template match="mpeg7:StillRegion[count(*)=1]">
<xsl:text disable-output-escaping="yes">
<lmdr:hasPart_mpeg7StillRegion>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.textstillregion.',generate-id(.))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&lmdr;Text</xsl:text><xsl:value-of select="local-name(.)"/><xsl:text disable-output-escaping="yes">"/>
<lmdr:hasPart_Object>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.sentence.',generate-id(./mpeg7:TextAnnotation/mpeg7:FreeTextAnnotation))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&tei;s"/>
<lmdr:hasValue></xsl:text><xsl:value-of select="./mpeg7:TextAnnotation/mpeg7:FreeTextAnnotation"/><xsl:text disable-output-escaping="yes"></lmdr:hasValue>
</rdf:Description>
</lmdr:hasPart_Object>
</rdf:Description>
</lmdr:hasPart_mpeg7StillRegion></xsl:text>
</xsl:template>
<xsl:template match="mpeg7:Descriptor|mpeg7:VisualDescriptor">
<xsl:text disable-output-escaping="yes">
<lmdr:hasPart_mpeg7StillRegion>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.visualdescriptor.',generate-id(.))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&mpeg7;</xsl:text><xsl:value-of select="substring-before(@xsi:type,'Type')"/><xsl:text disable-output-escaping="yes">"/></xsl:text>
<xsl:apply-templates select="./*"></xsl:apply-templates>
<xsl:text disable-output-escaping="yes">
</rdf:Description>
</lmdr:hasPart_mpeg7StillRegion></xsl:text>
</xsl:template>
<xsl:template match="mpeg7:Descriptor/*|mpeg7:VisualDescriptor/*">
<xsl:call-template name="elementToDataProperty">
<xsl:with-param name="descriptorProperty" select="."></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="mpeg7:Descriptor[@xsi:type='DominantColorType']/mpeg7:Value|mpeg7:VisualDescriptor[@xsi:type='DominantColorType']/mpeg7:Value">
<xsl:text disable-output-escaping="yes">
<lmdr:hasPart_mpeg7DominantColor>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.colorvalue.',generate-id(.))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&mpeg7;ColorValue"/></xsl:text>
<xsl:apply-templates select="./*" />
<xsl:text disable-output-escaping="yes">
</rdf:Description>
</lmdr:hasPart_mpeg7DominantColor></xsl:text>
</xsl:template>
<xsl:template match="mpeg7:Descriptor[@xsi:type='DominantColorType']/mpeg7:Value/*|mpeg7:VisualDescriptor[@xsi:type='DominantColorType']/mpeg7:Value/*">
<xsl:call-template name="elementToDataProperty">
<xsl:with-param name="descriptorProperty" select="."></xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template match="mpeg7:Descriptor[@xsi:type='DominantColorType']/mpeg7:ColorQuantization|mpeg7:VisualDescriptor[@xsi:type='DominantColorType']/mpeg7:ColorQuantization">
<xsl:apply-templates select="./mpeg7:Component"></xsl:apply-templates>
</xsl:template>
<xsl:template match="mpeg7:Descriptor[@xsi:type='DominantColorType']/mpeg7:ColorQuantization/mpeg7:Component|mpeg7:VisualDescriptor[@xsi:type='DominantColorType']/mpeg7:ColorQuantization/mpeg7:Component">
<xsl:text disable-output-escaping="yes">
<lmdr:hasPart_mpeg7DominantColor>
<rdf:Description rdf:about="&lmdr;</xsl:text><xsl:value-of select="concat($document,'.colorquantizationcomponent.',generate-id(.))"/><xsl:text disable-output-escaping="yes">">
<rdf:type rdf:resource="&mpeg7;ColorQuantizationComponent"/>
<mpeg7:ColorQuantizationComponentType></xsl:text>
<xsl:value-of select="." />
<xsl:text disable-output-escaping="yes">
</mpeg7:ColorQuantizationComponentType>
<lmdr:hasValue></xsl:text>
<xsl:value-of select="./following::mpeg7:NumOfBins[1]" />
<xsl:text disable-output-escaping="yes">
</lmdr:hasValue>
</rdf:Description>
</lmdr:hasPart_mpeg7DominantColor></xsl:text>
</xsl:template>
<xsl:template name="elementToDataProperty">
<xsl:param name="descriptorProperty" />
<xsl:text disable-output-escaping="yes">
<mpeg7:</xsl:text><xsl:value-of select="local-name($descriptorProperty)"/><xsl:text disable-output-escaping="yes">></xsl:text><xsl:value-of select="$descriptorProperty"/>
<xsl:text disable-output-escaping="yes">
</mpeg7:</xsl:text><xsl:value-of select="local-name($descriptorProperty)"/><xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:template>
<!--Get the name of a document from the MediaURI inside mpeg7 element-->
<xsl:template match="mpeg7:MediaUri[parent::mpeg7:Mpeg7]">
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string" select="./text()" />
<xsl:with-param name="delimiter" select="'\'" />
</xsl:call-template>
</xsl:template>
<!--Do not do anything-->
<xsl:template match="//mpeg7:MediaUri[parent::mpeg7:MediaLocator]" />
<!--Get the name of a document from the MediaURI inside MediaLocator element child of MediaProfile-->
<xsl:template match="//mpeg7:MediaProfile[@master='true']//mpeg7:MediaUri">
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string" select="./text()" />
<xsl:with-param name="delimiter" select="'/'" />
</xsl:call-template>
</xsl:template>
<!--Substring after last occurrence of a string-->
<xsl:template name="substring-after-last">
<xsl:param name="string" />
<xsl:param name="delimiter" />
<xsl:choose>
<xsl:when test="contains($string, $delimiter)">
<xsl:call-template name="substring-after-last">
<xsl:with-param name="string"
select="substring-after($string, $delimiter)" />
<xsl:with-param name="delimiter" select="$delimiter" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:value-of
select="$string" /></xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>