-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathowl2obo.xsl
153 lines (133 loc) · 5.2 KB
/
owl2obo.xsl
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
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:roc="http://roc.bgsu.edu/">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:text>format-version: 1.2
</xsl:text>
<xsl:apply-templates select="rdf:RDF/owl:Ontology/dc:date"/>
<xsl:text>autogenerated-by: owl2obo.xsl (http://rnao.googlecode.com/svn/trunk/owl2obo.xsl)
</xsl:text>
<xsl:apply-templates select="rdf:RDF/owl:Class"/>
<xsl:apply-templates select="rdf:RDF/owl:ObjectProperty"/>
</xsl:template>
<!-- date -->
<xsl:template match="dc:date">
<xsl:analyze-string select="." regex="(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d)">
<xsl:matching-substring>
<xsl:text>date: </xsl:text>
<xsl:value-of select="regex-group(3)"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="regex-group(2)"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="regex-group(1)"/>
<xsl:text> </xsl:text>
<xsl:value-of select="regex-group(4)"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="regex-group(5)"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
<!-- entities -->
<xsl:template match="owl:Class[@rdf:about]">
<xsl:text>
[Term]
</xsl:text>
<xsl:text>id: </xsl:text><xsl:value-of select="roc:owlid2oboid(@rdf:about)"/>
<xsl:apply-templates select="rdfs:label"/>
<xsl:apply-templates select="dc:description"/>
<xsl:apply-templates select="rdfs:subClassOf"/>
</xsl:template>
<!-- relations -->
<xsl:template match="owl:ObjectProperty">
<xsl:text>
[Typedef]
</xsl:text>
<xsl:text>id: </xsl:text><xsl:value-of select="roc:owlid2oboid(@rdf:about)"/>
<xsl:apply-templates select="rdfs:label"/>
<xsl:apply-templates select="rdfs:subPropertyOf"/>
<xsl:apply-templates select="owl:inverseOf"/>
<xsl:apply-templates select="rdf:type"/>
<xsl:apply-templates select="rdfs:range"/>
<xsl:apply-templates select="rdfs:domain"/>
</xsl:template>
<xsl:template match="rdfs:label">
<xsl:text>
name: </xsl:text><xsl:value-of select="."/>
</xsl:template>
<xsl:template match="rdfs:subPropertyOf">
<xsl:text>
is_a: </xsl:text><xsl:value-of select="roc:owlid2oboid(@rdf:resource)"/>
</xsl:template>
<xsl:template match="owl:inverseOf">
<xsl:text>
inverse_of: </xsl:text><xsl:value-of select="roc:owlid2oboid(@rdf:resource)"/>
</xsl:template>
<xsl:template match="rdf:type">
<xsl:choose>
<xsl:when test="matches(@rdf:resource,'FunctionalProperty')">
<xsl:text>
is_functional: true</xsl:text>
</xsl:when>
<xsl:when test="matches(@rdf:resource,'SymmetricProperty')">
<xsl:text>
is_symmetric: true</xsl:text>
</xsl:when>
<xsl:when test="matches(@rdf:resource,'TransitiveProperty')">
<xsl:text>
is_transitive: true</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
<!-- contains test for class unions: only lets through simple domains -->
<xsl:template match="rdfs:domain">
<xsl:if test="@rdf:resource">
<xsl:text>
domain: </xsl:text><xsl:value-of select="roc:owlid2oboid(@rdf:resource)"/>
</xsl:if>
</xsl:template>
<!-- contains test for class unions: only lets through simple ranges -->
<xsl:template match="rdfs:range">
<xsl:if test="@rdf:resource">
<xsl:text>
range: </xsl:text><xsl:value-of select="roc:owlid2oboid(@rdf:resource)"/>
</xsl:if>
</xsl:template>
<xsl:template match="dc:description">
<xsl:text>
def: "</xsl:text><xsl:value-of select="normalize-space(.)"/>
<xsl:text>" [RNAO:ROC]</xsl:text>
</xsl:template>
<xsl:template match="rdfs:subClassOf[@rdf:resource]">
<xsl:text>
is_a: </xsl:text><xsl:value-of select="roc:owlid2oboid(@rdf:resource)"/>
</xsl:template>
<xsl:template match="rdfs:subClassOf[owl:Class]"/>
<xsl:template match="rdfs:subClassOf[owl:Restriction/owl:allValuesFrom]"/>
<xsl:template match="rdfs:subClassOf[owl:Restriction/owl:someValuesFrom/owl:Class]"/>
<xsl:template match="rdfs:subClassOf[owl:Restriction/not(owl:allValuesFrom) and not(descendant::owl:Class)]">
<xsl:text>
relationship: </xsl:text>
<xsl:apply-templates select="owl:Restriction"/>
</xsl:template>
<xsl:template match="owl:Restriction[not(descendant::owl:Class)]">
<xsl:value-of select="roc:owlid2oboid(owl:onProperty/@rdf:resource)"/>
<xsl:text> </xsl:text>
<xsl:value-of select="roc:owlid2oboid(owl:someValuesFrom/@rdf:resource)"/>
<xsl:value-of select="roc:owlid2oboid(owl:onClass/@rdf:resource)"/>
</xsl:template>
<xsl:template match="owl:disjointWith">
<xsl:text>
disjoint_from: </xsl:text><xsl:value-of select="roc:owlid2oboid(@rdf:resource)"/>
</xsl:template>
<!-- functions -->
<xsl:function name="roc:owlid2oboid">
<xsl:param name="id"/>
<xsl:value-of select="replace(replace($id,'[^/]*/',''),'([A-Z])_([0-9])','$1:$2')"/>
</xsl:function>
</xsl:stylesheet>