XQuery, CSS, and XML Syntax Trees
Posted: November 11th, 2014, 6:06 pm
In my day job, I'm the lead editor of XQuery, a query language for XML.
In two other threads, I discussed displaying morphology and syntax trees with Cascading Stylesheets. In the SBL 2014 talk that Micheal Palmer and I are doing, we will also show how to query syntax trees using XQuery, displaying the results with Cascading Stylesheets.
To query, we need data, so let's take a look at the way we represent syntax trees in XML again. Here is how we represent the sentence βλέπετε οὖν πῶς ἀκούετε in our syntax trees, which are derived from the Global Bible Initiative's syntax trees, but simplify the markup in order to make them easier to use for generic queries and to display with stylesheets:
XQuery is optimized for querying XML like this. The following query returns all sentences in the input:
The following query returns all wg elements in the input:
If a wg element has an attribute where the class is cl, it is a clause. The following query returns all clauses in the input:
The following query returns words where the class is verb and the mood is indicative:
Let's combine these to find clauses where the main verb is indicative:
Incidentally, since the above queries return w and wg elements, which are used in the stylesheets we use to display text, the same stylesheets can be used to display query results.
In two other threads, I discussed displaying morphology and syntax trees with Cascading Stylesheets. In the SBL 2014 talk that Micheal Palmer and I are doing, we will also show how to query syntax trees using XQuery, displaying the results with Cascading Stylesheets.
To query, we need data, so let's take a look at the way we represent syntax trees in XML again. Here is how we represent the sentence βλέπετε οὖν πῶς ἀκούετε in our syntax trees, which are derived from the Global Bible Initiative's syntax trees, but simplify the markup in order to make them easier to use for generic queries and to display with stylesheets:
XQuery is optimized for querying XML like this. The following query returns all sentences in the input:
Code: Select all
//sentence
Code: Select all
//wg
Code: Select all
//wg[@class='cl']
Code: Select all
//w[ @class = "verb" and @mood="indicative"]
Code: Select all
for $wg in //wg
where $wg/@class="cl"
and $wg/w[ @class = "verb" and @mood="indicative"]
return $wg