-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathproiel2lowfat.xquery
275 lines (253 loc) · 6.62 KB
/
proiel2lowfat.xquery
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
declare variable $pos := //parts-of-speech;
declare variable $morph := //morphology;
declare function local:morph-description($tag, $category)
{
$morph/field[@tag=$category]/value[@tag=$tag]/@summary ! string(.)
};
declare function local:number($morph as xs:string)
{
let $tag := substring($morph,2,1)
where $tag != "-"
return
attribute number {
local:morph-description($tag, "number")
}
};
declare function local:person($morph as xs:string)
{
let $tag := substring($morph,1,1)
where $tag != "-"
return
attribute person {
tokenize(local:morph-description($tag, "person"))[1]
}
};
declare function local:gender($morph as xs:string)
{
let $tag := substring($morph,6,1)
where $tag != "-"
return
attribute gender {
local:morph-description($tag,"gender")
}
};
declare function local:case($morph as xs:string)
{
let $tag := substring($morph,7,1)
where $tag != "-"
return
attribute case {
local:morph-description($tag,"case")
}
};
declare function local:tense($morph as xs:string)
{
let $tag := substring($morph,3,1)
where $tag != "-"
return
attribute tense {
local:morph-description($tag,"tense")
}
};
declare function local:voice($morph as xs:string)
{
let $tag := substring($morph,5,1)
where $tag != "-"
return
attribute voice {
local:morph-description($tag,"voice")
}
};
declare function local:mood($morph as xs:string)
{
let $tag := substring($morph,4,1)
where $tag != "-"
return
attribute mood {
local:morph-description($tag,"mood")
}
};
declare function local:degree($morph as xs:string)
{
let $tag := substring($morph,8,1)
where $tag != "-"
return
attribute degree {
local:morph-description($tag,"degree")
}
};
declare function local:strength($morph as xs:string)
{
let $tag := substring($morph,9,1)
where $tag != "-"
return
attribute strength {
local:morph-description($tag,"strength")
}
};
declare function local:inflection($morph as xs:string)
{
let $tag := substring($morph,10,1)
where $tag != "-"
return
attribute inflection {
local:morph-description($tag,"inflection")
}
};
declare function local:morphology($t)
{
let $morph := string($t/@morphology)
where $morph
return (
$t/@lemma,
local:number($morph),
local:person($morph),
local:gender($morph),
local:case($morph),
local:tense($morph),
local:voice($morph),
local:mood($morph),
local:degree($morph),
local:strength($morph),
local:inflection($morph),
local:information-status($t/@information-status)
)
};
declare function local:class($t)
{
let $description := string($pos/value[@tag = $t/@part-of-speech]/@summary)
let $class :=
switch ($description)
case "interrogative adverb" return "adverb"
case "relative adverb" return "adverb"
case "common noun" return "noun"
case "proper noun" return "noun"
case "cardinal numeral" return "numeral"
case "ordinal numeral" return "numeral"
case "demonstrative pronoun" return "pronoun"
case "indefinite pronoun" return "pronoun"
case "interrogative pronoun" return "pronoun"
case "relative pronoun" return "pronoun"
case "personal pronoun" return "pronoun"
case "personal reflexive pronoun" return "pronoun"
case "possessive pronoun" return "pronoun"
case "possessive reflexive pronoun" return "pronoun"
case "reciprocal pronoun" return "pronoun"
case "" return ()
default return $description
let $type :=
switch ($description)
case "interrogative adverb" return "interrogative"
case "relative adverb" return "relative"
case "common noun" return "common"
case "proper noun" return "proper"
case "cardinal numeral" return "cardinal"
case "ordinal numeral" return "ordinal"
case "demonstrative pronoun" return "demonstrative"
case "indefinite pronoun" return "indefinite"
case "interrogative pronoun" return "interrogative"
case "relative pronoun" return "relative"
case "personal pronoun" return "personal"
case "personal reflexive pronoun" return "personal relative"
case "possessive pronoun" return "possessive"
case "possessive reflexive pronoun" return "possessive reflexive"
case "reciprocal pronoun" return "reciprocal"
default return ()
return
(
$class ! attribute class {$class},
$type ! attribute type {$type}
)
};
declare function local:information-status($tis)
{
$tis ! attribute information-status { $tis }
};
declare function local:token($t)
{
<w>
{
local:class($t),
attribute role {$t/@relation},
local:morphology($t),
attribute n {$t/@id},
$t/@head-id ! attribute head-id {$t/@head-id }
}
{
string($t/@form)
}
</w>,
$t/@presentation-after[. != ' '] ! <pc>{normalize-space(.)}</pc>
};
declare function local:unwrap($t, $stok)
{
let $children := $stok[@head-id = $t/@id]
let $seq := ($children | $t)/.
return
if ($children)
then
<wg role="{$t/@relation}" head="{$t/@id}">
{
for $s in $seq
return
if ($s is $t)
then local:token($t)
else local:unwrap($s, $stok)
}
</wg>
else local:token($t)
};
declare function local:milestone($ms)
{
let $groups := analyze-string($ms, "(\d+)?(\w+) (\d+)\.(\d+)")//fn:group
let $name :=
switch ($groups[@nr="2"])
case "PHILEM" return "phlm"
default return $groups[@nr="2"]
let $first :=
string-join(($groups[@nr="1"], upper-case(substring($name,1,1)),lower-case(substring($name,2))),"")
let $osisId := string-join(($first, $groups[@nr="3"], $groups[@nr="4"]),".")
return
<milestone unit="verse" id="{$osisId}">{ $osisId }</milestone>
};
declare function local:lastchild($t)
{
let $children :=
for $c in $t[@head-id = $t/@id]
order by $c/@id descending
return $c
return $children[1]
};
declare function local:sentence($s)
{
<sentence>
{
attribute id { $s/@id }
}
{
for $ms in distinct-values($s//@citation-part)
return local:milestone($ms)
}
{
<p>
{
string-join( $s//token ! (@form, @presentation-after), "")
}
</p>
}
{
let $stok := $s//token
for $t in $stok[not(@head-id)]
order by local:lastchild($t)
return local:unwrap($t, $stok)
}
</sentence>
};
<?xml-stylesheet href="treedown.css"?>,
<?xml-stylesheet href="boxwood.css"?>,
<book>
{
for $s in //sentence
return local:sentence($s)
}
</book>