Searching for words, lemmas and strings
PaCQL has a variety of ways of searching for words, lemmas, and strings, much more so in its 2026 version than the old 2015 version. But there are also constraints to such searches that one must be aware of.
Some basic examples
To begin with, it is easy to find all examples of some word withwordexists:
konungur wordexistsThis gives 712 examples of Icelandic konungur (king) in the IcePaHC 2024 corpus. It is illustrative to consider this query as it compares to using just
exists.
konungur existsPlain
exists returns the same 712 results. But that does not mean the two are equivalent exists lines. Unlike wordexists, plain exists searches for both nodes based on their labels and leaves (or terminals) based on their words. So we could also use that for a measure phrase:
NP-MSR existsIf you just want to search for nodes, you can use
labelexists;
NP-MSR labelexistsBy the way, the names used here, konungur and NP-MSR, are regular expressions, and these can be used for pattern matchings as you wish. But the lesson here is that nodes and leaves are not the same thing in PaCQL. Let's consider that some more.
Nodes vs. leaves
If you are used to searching treebanks, the following is normal stuff, a subject that immediately dominates a node with the tag N-N. And that also works in PaCQL, because both are nodes.NP-SBJ idoms N-NBut you may be suprised then to find that the following query does not return any results.
N-N idoms konungurIn CorpusSearch, this would be normal, and work, but N-N is a node and konungur would be a leaf if it were there. So here, we need to use special relations to handle leaves.
N-N idomsleaf konungurNow it works. Using
idomsleaf returns 710 results where a node N-N immediately dominates the leaf konungur. And in a lemmatized treebank, idomslemma can be used to relate a tag and the lemma below it.
N-[NADG] idomslemma konungur
The pattern N-[NADG] matches singular nouns in any case (nom, acc, dat, gen), and for these, the lemma is konungur regardless of the case. That yields 1562 results. And it brings us back to the exists relations, because they are special in how they match the tag above the word. Since the word/leaf is not a node, the exists lines return a match of the node above them. That makes the next query possible:
NP-SBJ idoms konungur konungur lemmaexistsThis matches a tree like below, where N-N is matched by the
konungur lemmaexists line.
(NP-SBJ
(ADJ-N Allsvaldandi)
(NP-POS
(NPR-G himinríkis))
(N-N konungur)
(, ,)
(NP-PRN
(ADJ-N almáttugur)
(NPR-N Guð)))
Here, the exists line is a way to bring the node above it into the query context, and that same node can be referred to in other relations in the query.
Finding longer strings
It is possible to use PaCQL to match whole strings of words, not just single words. The next query is just a simple string search of "góður maður" (good man) in the corpus.
"góður maður" stringexistsWe also have
lemmastringexists, which is similar, but where each word matches a lemma rather than a word form. So this query finds all inflected variants of góður maður.
"góður maður" lemmastringexists
Case-sensitive vs. case-insensitive string matching
Any of the word, string and lemma matching search functions are case-sensitive by default but they can be matched in a case-insensitive manner if we like. Let's compare these two queries:"í gær" stringexists
'í gær' stringexistsThe latter one returns more results because single quotes trigger case-insensitive matching. This also includes cases where the phrase 'í gær' (yesterday) is at the beginning of a sentence.
Mixing plain words or lemmas with regular expressions
When doing a string search, the words or lemmas are regular expressions, and they can be mixed into the query line. So putting.*, which matches any string, between the two words below, gives you all strings in the corpus with three words, first word 'allur' (all), last word maður (man), and any word in between:
'allur .* maður' lemmastringexistsSince this is
lemmastringexists and not just stringexists, such strings of three words are found regardless of which inflected form is used in the string.
Finding words near each other
It is possible to look for words that are near each other in a sentence:'guð' near 2 'andi'This finds sentences where 'guð' (god) and 'andi' (spirit), both case-insensitive, appear near each other, with at most 2 words between them. This also words for longer strings, not just single words:
'sem' near 5 'í gær'
Combining string search and nodes in the structure
PaCQL has relations of the formA relation B where A matches a specific type of node and B is a string pattern. For example, to find a finite main clause that dominates 'í gær' (yesterday), use this:
IP-MAT domsstring 'í gær'There is a also a lemma based variant of the same relation:
IP-MAT domslemmastring 'allur .* maður'While
domsstring and domslemmastring match at any depth in the tree, it is possible to ask for the IP-MAT that is the lowest IP-MAT dominating that string (if there are more than one).
IP-MAT domslemmastringlowest 'allur .* maður'And there are furthermore
A relation B search functions that match only nodes that contain exactly the string in question. These are spansstring and spanslemmastring.
PP spansstring 'í gær'As one can see, there are many ways of searching for words, lemmas, and strings in the treebanks on Treebank Studio. While syntacticians may often be thinking about the more abstract structures reflected by the phrase structure above the leafs in the tree, it is sometimes useful to have convenient ways of looking at the words themselves.