# Advanced Search

The Advanced Search implements the **CQP** query syntax.
CQP is a powerful query language for searching linguistic corpora. It is designed for querying large annotated text corpora with complex conditions and linguistic annotations. CQP syntax allows for pattern matching, searching for word forms, lemmas, parts of speech, named entities and other annotations, and supports advanced linguistic queries. In the following sections, we show some of the most important, *but not all* features of the CQP syntax. For exploring its full capacity, see [CQP Interface and Query Language Manual](https://cwb.sourceforge.io/files/CQP_Manual.pdf) and [The CQP Query Language Tutorial](https://www.inf.ed.ac.uk/teaching/courses/inf1/da/2010-2011/tutorials/cqp-tutorial.pdf).




## Examples in German

| Search Type | Syntax | Explanation |
|-------------|--------|-------------|
| **One-term search** | `"Demokratie"` | Searches for the exact word *Demokratie*. |
| **Word search using parameter** | `[word="Demokratie"]` | Searches for the word *Demokratie* using the **word** parameter. |
| **Lemma search** | `[lemma="Demokratie"]` | Searches for all **inflected forms** of the lemma *Demokratie*. |
| **Part-of-speech (PoS) search** | `[pos="NN"]` | Searches for common **nouns** (*NN*), see the German PoS tagset. |
| **Named Entity (NER) search** | `<ne_entityType="LOC"> [];` | Searches for named entities labeled as *LOC* (locations). You can also specify *ORG* for organisations and *PER* for persons |
| **Finding a sequence of words** | `[pos="ADJA"][lemma="Gesellschaft"]` | Searches for an **attributive adjective** (*ADJA*), followed by the lemma *Gesellschaft*. |
| **Combining multiple PoS tags** | `([pos="ADJA"]\|[pos="ART"]) [lemma="Gesellschaft"]` | Searches for either an **attributive adjective** (*ADJA*) or an **article** (*ART*), followed by *Gesellschaft*. |
| **Multiple conditions in one token** | `[lemma="Essen" & pos="NN"]` | Searches for the lemma *Essen*, but **only when tagged as a noun** (*NN*). |
| **Negation (Excluding a specific PoS tag)** | `[lemma="gross" & pos!="ADJD"]` | Searches for *gross*, but **only when it is not** tagged as a **predicative adjective or adverb** (*ADJD*). |
| **Longer word sequences** | `[pos="ART"][pos="ADJA"][lemma="Gesellschaft"]` | Searches for an **article** (*ART*), followed by an **adjective** (*ADJA*), followed by *Gesellschaft*. |

:::{seealso}
See [Tagsets](./tagsets.md) for the full list of German PoS tags.
:::


<!--

## German Examples

-->

## Examples in French

| Search Type | Syntax | Explanation |
|-------------|--------|-------------|
| **One-term search** | `"démocratie"` | Searches for the exact word *démocratie*. |
| **Word search using parameter** | `[word="démocratie"]` | Searches for the word *démocratie* using the **word** parameter. |
| **Lemma search** | `[lemma="démocratie"]` | Searches for all **inflected forms** of the lemma *démocratie*. |
| **Part-of-speech (PoS) search** | `[pos="NOUN"]` | Searches for **nouns** (*NOUN*) in the French PoS tagset. |
| **Named Entity (NER) search** | `<ne_entityType="LOC"> [];` | Searches for named entities labeled as *LOC* (locations). You can also specify *ORG* for organisations and *PER* for persons |
| **Finding a sequence of words** | `[pos="ADJ"][lemma="société"]` | Searches for an **adjective** (*ADJ*), followed by the lemma *société*. |
| **Combining multiple PoS tags** | `([pos="ADJ"]\|[pos="DET"]) [lemma="société"]` | Searches for either an **adjective** (*ADJ*) or a **determiner** (*DET*), followed by *société*. |
| **Multiple conditions in one token** | `[lemma="marche" & pos="NOUN"]` | Searches for the lemma *marche*, but **only when tagged as a noun** (*NOUN*). |
| **Negation (Excluding a specific PoS tag)** | `[lemma="grand" & pos!="ADV"]` | Searches for *grand*, but **only when it is not** tagged as an **adverb** (*ADV*). |
| **Longer word sequences** | `[pos="DET"][pos="ADJ"][lemma="société"]` | Searches for a **determiner** (*DET*), followed by an **adjective** (*ADJ*), followed by *société*. |

:::{seealso}
See [Tagsets](./tagsets.md) for the full list of French PoS tags.
:::


<!--

## French Examples

--> 


## Examples in Italian

| Search Type | Syntax | Explanation |
|-------------|--------|-------------|
| **One-term search** | `"democrazia"` | Searches for the exact word *democrazia*. |
| **Word search using parameter** | `[word="democrazia"]` | Searches for the word *democrazia* using the **word** parameter. |
| **Lemma search** | `[lemma="democrazia"]` | Searches for all **inflected forms** of the lemma *democrazia*. |
| **Part-of-speech (PoS) search** | `[pos="NOUN"]` | Searches for **nouns** (*NOUN*) in the Italian PoS tagset. |
| **Named Entity (NER) search** | `<ne_entityType="LOC"> [];` | Searches for named entities labeled as *LOC* (locations). You can also specify *ORG* for organisations and *PER* for persons |
| **Finding a sequence of words** | `[lemma="società"][pos="ADJ"]` | Searches for the lemma *società*, followed by an **adjective** (*ADJ*). |
| **Combining multiple PoS tags** | `([pos="ADJ"]\|[pos="DET"]) [lemma="società"]` | Searches for either an **adjective** (*ADJ*) or a **determiner** (*DET*), followed by *società*. |
| **Multiple conditions in one token** | `[lemma="lavoro" & pos="NOUN"]` | Searches for the lemma *lavoro*, but **only when tagged as a noun** (*NOUN*). |
| **Negation (Excluding a specific PoS tag)** | `[lemma="grande" & pos!="ADV"]` | Searches for *grande*, but **only when it is not** tagged as an **adverb** (*ADV*). |
| **Longer word sequences** | `[pos="DET"][pos="ADJ"][lemma="società"]` | Searches for a **determiner** (*DET*), followed by an **adjective** (*ADJ*), followed by *società*. |

:::{seealso}
See [Tagsets](./tagsets.md) for the full list of Italian PoS tags.
:::


<!--

## Italian Examples

-->

## Regular Expressions

This CQP syntax accepts regular expressions, which act as placeholders for certain characters or combinations of characters. The following table shows the most important regular expressions and examples how to use them:


| RegEx      | Meaning                                                                                                                                                        | Example                                                                                                     |
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| `.`        | Matches any single character:                                                                                                                                  | **DE:** `[word="erneuerbare."]` → erneuerbaren, erneuerbarem, erneuerbarer, …  <br> **FR:** `[word="ou."]` → oui, oué …  <br> **IT:** `[word="ecologic."]` → ecologica, ecologici, ecologica, … |
| `+`        | Repetition operator: The preceding character must occur at least once but can appear multiple times (up to the word boundary). Useful with `.`:                | **DE:** `[word="Energie.+"]` → Energien, Energiegesetz, Energiestrategien, …  <br> **FR:** `[word="nation.+"]` → nations, national, nationale, nationalisme, …  <br> **IT:** `[word="nazi.+"]` → nazioni, nazionalità, nazionalismo, … |
| `*`        | Repetition operator: The preceding character can occur any number of times, including zero (up to the word boundary). Useful with `.`:                         | **DE:** `[word="Energie.*"]` → Energie, Energien, Energiegesetz, Energiestrategien, …  <br> **FR:** `[word="éducation.*"]` → éducation, éducations, …  <br> **IT:** `[word="posta.*"]` → posta, postale, postali, … |
| `?`        | Repetition operator: The preceding character is optional (can appear or not):                                                                                  | **DE:** `[word="energie–?effizient"]` → energie–effizient, energieeffizient, …  <br> **FR:** `[word="co–?working"]` → co–working, coworking, …  <br> **IT:** `[word="eco–?turismo"]` → eco–turismo, ecoturismo, … |
| `(x\|y)`    | Matches either element in parentheses separately:                                                                                                              | **DE:** `[word="(E\|e)nergie–?(Z\|z)ukunft"]` → Energiezukunft, energiezukunft, Energie-zukunft, Energie-Zukunft, …  <br> **FR:** `[word="(É\|é)cologie–?(V\|v)erte"]` → Écologie verte, écologie-verte, écologieVerte, …  <br> **IT:** `[word="(E\|e)cologia"]` → ecologia, Ecologia |
| `x{0,3}`   | Matches between 0 and 3 repetitions of the preceding element. Multiple elements can be included in square brackets:                                            | **DE:** `[word="ja{0,3}]"` → ja, jaa, jaaa, jaaaa <br> **FR:** `[word="oui{0,3}"]` → oui, ouii, ouiii, ouiiii <br> **IT:** `[word="no{0,3}"]` → no, noo, nooo, noooo |
| `[]`       | Matches any single token between search terms:                                                                                                                | **DE:** `[word="die"] [] [word="Energie"]` → die graue Energie, die saubere Energie, …  <br> **FR:** `[word="la"] [] [word="nature"]` → la belle nature, la vraie nature, …  <br> **IT:** `[word="la"] [] [word="volta"]` → la prima volta, la seconda volta, la terza volta, … |
| `[^]`      | Excludes the characters in brackets after `^` from occurring:                                                                                                  | **DE:** `[word=".*?[^eE]nergie"]` → Minergie, Synergie, … but not Energie  <br> **FR:** `[word=".*?[^eEÉé]nergie"]]` → Minergie, synergie, … but not énergie   <br> **IT:** `[word=".*?[^Ee]nergia"]` → Minergia, sinergia, … but not energia  |
| `!`        | Excludes any match for the expression after the exclamation mark.                                                                                             | **DE:** `[pos!="NN"]` → Results include all word types except nouns (NN).  <br> **FR:** `[pos!="NOUN"]` → Results include all word types except nouns (NOUN).  <br> **IT:** `[pos!="NOUN"]` → Results include all word types except nouns (NOUN). |
| `&`        | Combines `pos`, `word` or `lemma` for a single search term:                                                                          | **DE:** `[word="richtig" & pos="ADV"]` → Occurrences of *richtig* only as an adverb, not as an adjective.  <br> **FR:** `[word="juste" & pos="ADV"]` → Occurrences of *juste* only as an adverb, not as an adjective.  <br> **IT:** `[word="giusto" & pos="ADV"]` → Occurrences of *giusto* only as an adverb, not as an adjective. |
| `\`        | Interprets characters literally, even if they are placeholders in CQP:                                                                                         | **DE:** `[word="Erneuerbare"] [word="\?"]` → Finds *Erneuerbare?* literally.  <br> **FR:** `[word="Énergie"] [word="\?"]` → Finds *Énergie?* literally.  <br> **IT:** `[word="Energia"] [word="\?"]` → Finds *Energia?* literally. |
| `%c`       | Case-insensitive search:                                                                                                                                       | **DE:** `[word="energie"%c]` → Energie, energie  <br> **FR:** `[word="énergie"%c]` → Énergie, énergie  <br> **IT:** `[word="energia"%c]` → Energia, energia |
