Treebank StudioDocumentation

PaCQL tutorial (for "pack-well", the Parsed Corpus Query Language)

This is an introduction to the PaCQL query language using examples from IcePaHC 2024.03, the Icelandic Parsed Historical Corpus. The best way to use this document is to have PaCQL search box for the corpus open in another window and try out the queries as you go through the material. Note that although this introduction will get you started, you will need to consult further sources of information in order to use parsed corpora for advanced work.

PaCQL ("pack-well") is designed to meet the following criteria:

Because many linguistic researchers are familiar with CorpusSearch (henceforth CS), this guide will occasionally point out similarities and differences between the two system. There is considerable overlap in the functionality of the two systems and it should be easy transfer knowledge of one system to the other.

Basic concepts

We will start right away with the first query. Type the following PaCQL query into the search box and click the Run button (or press Ctrl+Enter).
NP-SBJ idoms N-D
In the IcePaHC 2024.03 corpus, this query matches 835 noun phrases (NP) which are subjects (NP-SBJ) and which immediately dominate (idoms) a singular common noun (N) in the dative case (N-D). Dative subjects are a well known property of Icelandic syntax so we are already seeing something linguistically interesting!

The first label you type into the query box, NP-SBJ in this case, becomes the "anchor" for the query. The query answers the question: For which anchors in the corpus does the pattern described be the query hold? By default, the box "Anchor only" is checked and this means that the output will display only the part of the tree which is the matched anchor.
(NP-SBJ
  (Q-D öllu)          'all'-dative
  (N-D mál$)          'language'-dative
  (D-D $inu))         'the'-dative
The full text of the tree which contains the anchor is displayed above the anchor tree. Note that the words of the matching anchor are highlighted inside the full text for the matching tree when you are looking at the results. Try unselecting "Anchor only". Each tree in which there is a matching anchor will now be displayed in full so you may have to scroll down to find the dative subject. The labels NP-SBJ and N-D in the example above are highlighted in orange in the tree so they will still stand out.

In addition to using colors to highlight important parts of the results, the query box highlights the names of search functions like "idoms". If they turn blue as you type, you can be sure that you typed them correctly. The results are shown on the page by default. Above the results there is a "Download TSV" button, which gives you tab-seperated values corresponding to the coding values shown above each result tree, as well as the raw text for the relevant tree. The current query only gives us unique identifiers for the text and the tree, but the TSV format will become more interesting as we start coding for more variables.

Below the query box, next to the "Results" tab where it says "835 results" after you run the query, there is a "Summary" tab. Clicking the tab will give you a breakdown of the results by text and century. The following columns are shown in the text table.

ColumnInterpretation
results (r/T)results per text
result trees (rt/T)result trees per text (fewer than r/T if >1 result per tree)
trees (t/T)total trees per text
per 1,000 words (r/1Kw)results per 1000 words for this text

The last of these, r/1Kw, can be used as a rough measure of the frequency of a particular syntactic pattern. The section about coding queries below will introduce more sophisticated ways of studying syntactic change. The table which shows results by century is similar.

ColumnInterpretation
results (r/C)results per century
result trees (rt/C)result trees per century (fewer than r/T if >1 result per tree)
trees (t/C)total trees per century
per 1,000 words (r/1Kw)results per 1000 words for this century

The century table is accompanied by a visualization which displays the development of r/1Kw over time. The drop in dative subject in the 16th century is due to the New Testament translation of Oddur Gottskálksson. He moved to Norway at a young age and perhaps it is for that reason that diagnostics for oblique subjects are weak in his language. Translation effects from Luther are also a plausible source of odd patterns. The reader may feel free to use Treebank Studio to develop her own explanation of these facts!

Adding conditions

If we want to look at dative subjects in finite subordinate clauses, we can use the following query.
IP-SUB idoms NP-SBJ
NP-SBJ idoms N-D
IP-SUB matches finite subordinate clauses and the two instances of NP-SBJ in the query are taken to be the same noun phrase. The query therefore means that the IP-SUB should immediately dominate a phrase NP-SBJ and this same phrase should dominate a dative noun N-D. IP-SUB is the first label in the query and it is therefore the anchor. There are 260 results in the corpus which match this pattern, one of which is the following:
(IP-SUB
  (NEG eigi)
  (BEPS sé)
  (NP-SBJ
    (Q-D öllu)
    (N-D mál$)
    (D-D $inu))
  (ADVP (ADV orðfimlega) (CONJP *ICH*-4))
  (VAN farið)
  (CONJP-4 (CONJ eða) (ADVP (ADV skörulega)))) 
If you want to search for exactly the dative subjects which include quantifiers or determiners, but may or may not include other elements, you can use the following queries.
IP-SUB idoms NP-SBJ
NP-SBJ idoms Q-D
IP-SUB idoms NP-SBJ
NP-SBJ idoms D-D
However, if you want to capture all dative subjects in the same query, you will need to use more advanced pattern matching. For this purpose, we can use regular expressions.

Using regular expressions

In PaCQL, every label specification is a regular expression. A full treatment of regular expressions is beyond the scope of this guide, but a few basic patterns demonstrate the power of this tool. First, a list of characters inside a bracket matches any one of these characters. The following therefore matches all IP-SUB clauses whose subject immediately dominates one of the labels N-D, Q-D or D-D.
IP-SUB idoms NP-SBJ
NP-SBJ idoms [NQD]-D
A parenthesized list of strings of characters where the strings are separated by the pipe symbol (|) matches any of the strings on the list. We can use this technique to expand the search to include finite main clauses IP-MAT. Notice how the anchor indicator updates automatically as you type to reflect the first label specification in the query.
IP-(MAT|SUB) idoms NP-SBJ
NP-SBJ idoms [NQD]-D
In fact, there are some more part-of-speech tags beyond N-D, Q-D and D-D which are used to annotate dative elements in the corpus. For example, we have not looked at dative pronouns yet, PRO-D. As the reader may have noticed, all the dative tags end with the "dash tag" -D and we can use the regular expression .*-D "dot star" to capture all of these dative tags in a simple manner. The formal meaning of the star is "zero or more repetitions of the preceding character" and the dot is a special symbol which matches any character! We are now up to 3786 dative subjects!
IP-(MAT|SUB) idoms NP-SBJ
NP-SBJ idoms .*-D

Syntactic relationships

Basic syntactic rels (there must be at least one of these!): Special syntactic rels (specify conditions on what the basic rels matched):

Either/or

Alternatives go in an either: section and one or more or: sections; at least one of them must hold:
IP-SUB idoms MDPI

either:
IP-SUB idomslast MDPI

or:
IP-SUB idoms NEG

Coding queries

Define the dependent variable "ov" whose value is 1 if "ov:1" holds but 0 if "ov:0" holds.
IP-(MAT|SUB) idoms MDPI

ov:1
MDPI sprec NP-OB[12]
NP-OB[12] sprec VB   

ov:0
MDPI sprec VB
VB sprec NP-OB[12]
Types of noun phrases. Elsewhere condition.

Meta coding

Meta coding adds columns to the output. The meta block in the query has to be separated from the rest of the query by a blank line. The first line of the meta section has to be "meta:" and this first line must be followed by one or more of the meta coding commands below.

Text level meta coding:

Tree level meta coding: Node level meta coding: