The goal of this demo is to show how the sort tool of the CLaRK system can be used for ordering similar structures from XML documents according to a certain criteria.
The Sort tool is used for sorting XML elements within documents. By XPath expression the user can specify the data she/he wants to sort. Only elements at the same document level can be sorted.
The XML elements are sorted on the basis of certain data connected with the
elements. The data is determined via keys. The keys are defined by XPath
expressions and additional processing of the selected data like normalization,
tokenization etc. For each key user can select Order of sorting -
ascending or descending, if the data must be compared by the endings , by
selecting Reverse option. If data must be compared as numbers a
Number option must be selected. Additionally user have to select
Trim in order not to sort by the spaces around the text (if any),
and Normalize in order different writings of the same token to be
counted as equal. A tokenizer can be set.
In order to apply to more than one documents you have to select
Multiple Apply. Then a new part of the dialog appears in which you
have to select the documents from the corresponding document group via the
button Add Documents.
Additionally you have to specify the output document for the result. Normally
the system offers for each input document its own output document, but in this
case it is possible to overwrite source document with the result from the sort.
To do so, you have to select Options and then
Overwrite radio button. Then return to the main dialog.
The goal here is to sort all counted in the statistics tokens by number of their occurrences.
The document used for this demo is standartResult.stat - a
statistics document. For each token counted there is a <item>
tag. Each <item> contains the token itself
(<element> tag), the category of the token
(<category> tag), number of occurrences of the token in
document(s) (<number> tag), the percentage
(<percent> tag) and the values of the keys according to that
the statistics was made (<keyvalue> tag).
In order to run the demo you have to perform the following steps:
standartResult.stat is loaded in the system. If it is not, then load
it as it is described in Import XML Tool DemoTools.Select Elements: write the following XPath
expression : //item. This expression selects all item
elements within the document. number/text(). Additionally you have to select number
in order to compare text as numbers not as strings. For example to compare 21
and 112 . When compared as numbers 21 is less than 112. When compared as
strings 112 is less than 21 because 1 is before of 2 in lexicographic
order.
The above query is saved in document number.sort in the demo directory.
The query above can be extended to sort nodes not only in ascending order by number of occurrences but elements that have equal number of appearances to be sorted descending by the value of the token.
This can be done with a second key.
The second key in this case is the text of <element> child of <item> element. This is specified by
the XPath expression element/text(). Additionally you have to select trim in order
not to sort by the spaces around the text (if any), and normalized in order different writings of the
same token to be counted as equal. A tokenizer MixedWord can be set.
The dialog in this case will be:

The query is saved in document numElem.sort in the current directory.
The item elements in the result document will be ordered in such way:

The goal here is to sort all rules in the grammar by the Regular Expression endings. This can be done with the expectance that words with the same endings have the same grammatical characteristics, and will be easy to fill that characteristics in the grammar.
The document used for this demo is stat_to_gram.gram - a
grammar document. Each grammar consists of rules. For each rule there is a
<line> tag. Each rule contains a Regular Expression
(<RE> tag) and a Return Mark-up (<RM>
tag). It can also contain Left Content of the Regular Expression
(<LC> tag) and Right Content of the Regular Expression
(<RC> tag).
In order to run the demo you have to perform the following steps:
stat_to_gram.gram is loaded in the
system. If it is not, then load it as it is described in Import XML Tool DemoTools.Select Elements: write the following XPath
expression : //line. This expression selects all line
elements within the document (rules).RE/text().
Additionally you have to select Reverse in order to sort by the
endings of the RE, trim in order not to sort by the spaces around
the text (if any), and normalized in order different writings of
the same token to be counted as equal. A tokenizer MixedWord can be set.
The above query is saved in document grammar.sort in the demo
directory.