Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 1 | % layout 'main', title => 'KorAP: Poliqarp+'; |
| 2 | |
Akron | 9490e3b | 2019-10-17 12:26:29 +0200 | [diff] [blame] | 3 | %= page_title |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 4 | |
Akron | 84b9199 | 2019-07-16 11:35:49 +0200 | [diff] [blame] | 5 | <p>The following documentation introduces all features provided by our version of the Poliqarp Query Language and some KorAP specific extensions.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 6 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 7 | <section id="segments"> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 8 | <h3>Simple Segments</h3> |
| 9 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 10 | <p>The atomic elements of Poliqarp queries are segments. Most of the time segments represent words and can be simple queried:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 11 | %# footnote: In the polish national corpus, Poliqarp can join multiple segments when identifying a single word. |
| 12 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 13 | %= doc_query poliqarp => loc('Q_poliqarp_simple', '** Tree') |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 14 | |
| 15 | <p>Sequences of simple segments are expressed using a space delimiter:</p> |
| 16 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 17 | %= doc_query poliqarp => loc('Q_poliqarp_simpleseq', '** the Tree') |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 18 | |
| 19 | <p>Simple segments always refer to the surface form of a word. To search for surface forms without case sensitivity, you can use the <code>/i</code> flag.</p> |
| 20 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 21 | %= doc_query poliqarp => loc('Q_poliqarp_simpleci', '** run/i') |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 22 | |
Akron | a7cfd90 | 2017-12-21 19:28:36 +0100 | [diff] [blame] | 23 | <p>The query above will find all occurrences of the term irrespective of the capitalization of letters.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 24 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 25 | <h4 id="regexp">Regular Expressions</h4> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 26 | |
Akron | 3cfa26d | 2019-10-24 15:17:34 +0200 | [diff] [blame] | 27 | <p>Segments can also be queried using <%= embedded_link_to 'doc', 'regular expressions', 'ql', 'regexp' %> - by surrounding the segment with double quotes.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 28 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 29 | %= doc_query poliqarp => loc('Q_poliqarp_re', '** "r(u|a)n"'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 30 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 31 | <p>Regular expression segments will always match the whole segment, meaning the above query will find words starting with the first letter of the regular expression and ending with the last letter. To support subqueries, you can use the <code>/x</code> flag.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 32 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 33 | %= doc_query poliqarp => loc('Q_poliqarp_rex', '** "r(u|a)n"/x'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 34 | |
| 35 | <p>The <code>/x</code> will search for all segments that contain a sequence of characters the regular expression matches. That means the above query is equivalent to:</p> |
| 36 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 37 | %= doc_query poliqarp => loc('Q_poliqarp_recontext', '** ".*?r(u|a)n.*?"'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 38 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 39 | <p>The <code>/x</code> flag can also be used in conjunction with strict expressions to search for substrings:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 40 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 41 | %= doc_query poliqarp => loc('Q_poliqarp_simplex', '** part/xi'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 42 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 43 | <p>The above query will find all occurrences of segments including the defined substring regardless of upper and lower case.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 44 | |
| 45 | <blockquote class="warning"> |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 46 | <p>Beware: Queries with prepended <code>.*</code> expressions can become extremely slow!</p> |
Akron | 81afd28 | 2018-07-24 11:39:55 +0200 | [diff] [blame] | 47 | <p>In the original Poliqarp specification, regular expressions can be marked both by double quotes and single quotes. In Poliqarp+ only double quotes are used for regular expressions, while single quotes are used to mark verbatim strings.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 48 | </blockquote> |
| 49 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 50 | <p>You can again apply the <code>/i</code> flag to regular expressions to search case insensitive.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 51 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 52 | %= doc_query poliqarp => loc('Q_poliqarp_rexi', '** "r(u|a)n"/xi'), cutoff => 1 |
Akron | 852fb8a | 2023-07-21 07:48:13 +0200 | [diff] [blame^] | 53 | |
| 54 | <h4 id="reserved">Reserved terms</h4> |
| 55 | |
| 56 | <p>The following terms are <em>reserved words</em> in Poliqarp+ and can therefore not be used in short notation of simple segments. |
| 57 | Use the notation for <%= embedded_link_to 'doc', 'complex segments', 'ql', 'poliqarp-plus#complex'%> to query them (e.g. <code>[orth='contains']</code>):</p> |
| 58 | |
| 59 | <ul> |
| 60 | <li><code>contains</code></li> |
| 61 | <li><code>dependency</code></li> |
| 62 | <li><code>dominates</code></li> |
| 63 | <li><code>endswith</code></li> |
| 64 | <li><code>endsWith</code></li> |
| 65 | <li><code>focus</code></li> |
| 66 | <li><code>i</code> and <code>I</code></li> |
| 67 | <li><code>meta</code></li> |
| 68 | <li><code>matches</code></li> |
| 69 | <li><code>overlaps</code></li> |
| 70 | <li><code>relatesTo</code></li> |
| 71 | <li><code>split</code></li> |
| 72 | <li><code>startswith</code> and <code>startsWith</code></li> |
| 73 | <li><code>submatch</code></li> |
| 74 | <li><code>within</code></li> |
| 75 | <li><code>x</code> and <code>X</code></li> |
| 76 | </ul> |
| 77 | |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 78 | </section> |
| 79 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 80 | <section id="complex"> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 81 | <h3>Complex Segments</h3> |
| 82 | |
| 83 | <p>Complex segments are expressed in square brackets and contain additional information on the resource of the term under scrutiny by providing key/value pairs, separated by an equal-sign.</p> |
| 84 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 85 | <p>The KorAP implementation of Poliqarp provides three special segment keys: <code>orth</code> for surface forms, <code>base</code> for lemmata, and <code>pos</code> for Part-of-Speech. The following complex query finds all surface forms of the defined word.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 86 | %# There are more special keys in Poliqarp, but KorAP doesn't provide them. |
| 87 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 88 | %= doc_query poliqarp => loc('Q_poliqarp_complexorth', '** [orth=Tree]') |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 89 | |
| 90 | <p>The query is thus equivalent to:</p> |
| 91 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 92 | %= doc_query poliqarp => loc('Q_poliqarp_simple', '** Tree') |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 93 | |
| 94 | <p>Complex segments expect simple expressions as values, meaning that the following expression is valid as well:</p> |
| 95 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 96 | %= doc_query poliqarp => loc('Q_poliqarp_complexre', '** [orth="r(u|a)n"/xi]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 97 | |
Akron | 3cfa26d | 2019-10-24 15:17:34 +0200 | [diff] [blame] | 98 | <p>Another special key is <code>base</code>, refering to the lemma annotation of the <%= embedded_link_to 'doc', 'default foundry', 'data', 'annotation' %>. |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 99 | The following query finds all occurrences of segments annotated as a specified lemma by the default foundry.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 100 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 101 | %= doc_query poliqarp => loc('Q_poliqarp_complexlemma', '** [base=Tree]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 102 | |
Akron | 3cfa26d | 2019-10-24 15:17:34 +0200 | [diff] [blame] | 103 | <p>The third special key is <code>pos</code>, refering to the part-of-speech annotation of the <%= embedded_link_to 'doc', 'default foundry', 'data', 'annotation' %>. |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 104 | The following query finds all attributive adjectives:</p> |
| 105 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 106 | %= doc_query poliqarp => loc('Q_poliqarp_complexpos', '** [pos=ADJA]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 107 | |
| 108 | <p>Complex segments requesting further token annotations can have keys following the <code>foundry/layer</code> notation. |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 109 | For example to find all occurrences of plural words in a supporting foundry, you can search using the following query:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 110 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 111 | %= doc_query poliqarp => loc('Q_poliqarp_complexplural', '** [mate/m=number:pl]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 112 | |
Akron | 81afd28 | 2018-07-24 11:39:55 +0200 | [diff] [blame] | 113 | <p>In case an annotation contains special non-alphabetic and non-numeric characters, the annotation part can be surrounded by single quotes to ensure a verbatim interpretation:</p> |
| 114 | |
| 115 | %= doc_query poliqarp => loc('Q_poliqarp_complexverbatim', '** [mate/o=\'This is an annotation with space characters\']'), cutoff => 1 |
| 116 | |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 117 | <h4>Negation</h4> |
Akron | 5474018 | 2017-06-17 14:17:23 +0200 | [diff] [blame] | 118 | <p>Negation of terms in complex expressions can be expressed by prepending the equal sign or the whole expression with an exclamation mark.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 119 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 120 | %= doc_query poliqarp => loc('Q_poliqarp_neg1', '** [pos!=ADJA]'), cutoff => 1 |
| 121 | %= doc_query poliqarp => loc('Q_poliqarp_neg2', '** [!pos=ADJA]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 122 | |
| 123 | <blockquote class="warning"> |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 124 | <p>Beware: Negated complex segments can't be searched as a single statement. |
Akron | 3cfa26d | 2019-10-24 15:17:34 +0200 | [diff] [blame] | 125 | However, they work in case they are part of a <%= embedded_link_to 'doc', 'sequence', 'ql', 'poliqarp-plus#syntagmatic-operators-sequence' %>.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 126 | </blockquote> |
| 127 | |
| 128 | <h4 id="empty-segments">Empty Segments</h4> |
| 129 | |
| 130 | <p>A special segment is the empty segment, that matches every word in the index.</p> |
| 131 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 132 | %= doc_query poliqarp => '[]', cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 133 | |
Akron | 3cfa26d | 2019-10-24 15:17:34 +0200 | [diff] [blame] | 134 | <p>Empty segments are useful to express distances of words by using <%= embedded_link_to 'doc', 'repetitions', 'ql', 'poliqarp-plus#syntagmatic-operators-repetitions' %>.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 135 | |
| 136 | <blockquote class="warning"> |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 137 | <p>Beware: Empty segments can't be searched as a single statement. |
Akron | 3cfa26d | 2019-10-24 15:17:34 +0200 | [diff] [blame] | 138 | However, they work in case they are part of a <%= embedded_link_to 'doc', 'sequence', 'ql', 'poliqarp-plus#syntagmatic-operators-sequence' %>.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 139 | </blockquote> |
| 140 | </section> |
| 141 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 142 | <section id="spans"> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 143 | <h3>Span Segments</h3> |
| 144 | |
| 145 | <p>Not all segments are bound to words - some are bound to concepts spanning multiple words, for example noun phrases, sentences, or paragraphs. |
| 146 | Span segments can be searched for using angular brackets instead of square brackets.</p> |
| 147 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 148 | %= doc_query poliqarp => loc('Q_poliqarp_span', '** <corenlp/c=NP>'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 149 | |
| 150 | <p>Otherwise they can be treated in exactly the same way as simple or complex segments.</p> |
| 151 | </section> |
| 152 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 153 | <section id="paradigmatic-operators"> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 154 | <h3>Paradigmatic Operators</h3> |
| 155 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 156 | <p>A complex segment can have multiple properties a token requires. For example to search for all words with a certain surface form of a particular lemma (no matter if capitalized or not), you can search for:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 157 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 158 | %= doc_query poliqarp => loc('Q_poliqarp_and', '** [orth=run/i & base=Run]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 159 | |
| 160 | <p>The ampersand combines multiple properties with a logical AND. |
| 161 | Terms of the complex segment can be negated as introduced before.</p> |
| 162 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 163 | %= doc_query poliqarp => loc('Q_poliqarp_andneg1', '** [orth=run/i & base!=Run]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 164 | |
| 165 | <p>The following query is therefore equivalent:</p> |
| 166 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 167 | %= doc_query poliqarp => loc('Q_poliqarp_andneg2', '** [orth=run/i & !base=Run]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 168 | |
| 169 | <p>Alternatives can be expressed by using the pipe symbol:</p> |
| 170 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 171 | %= doc_query poliqarp => loc('Q_poliqarp_or', '** [base=run | base=go]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 172 | |
| 173 | <p>All these sub expressions can be grouped using round brackets to form complex boolean expressions:</p> |
| 174 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 175 | %= doc_query poliqarp => loc('Q_poliqarp_group', '** [(base=run | base=go) & tt/pos=VVFIN]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 176 | </section> |
| 177 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 178 | <section id="syntagmatic-operators"> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 179 | <h3>Syntagmatic Operators</h3> |
| 180 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 181 | <h4 id="syntagmatic-operators-sequence">Sequences</h4> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 182 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 183 | <p>Sequences can be used to search for segments in order. For this, simple expressions are separated by whitespaces.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 184 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 185 | %= doc_query poliqarp => loc('Q_poliqarp_seq', '** the old man'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 186 | |
| 187 | <p>However, you can obviously search using complex segments as well:</p> |
| 188 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 189 | %= doc_query poliqarp => loc('Q_poliqarp_seqcomplex', '** [orth=the][orth=old][orth=man]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 190 | |
| 191 | <p>Now you may see the benefit of the empty segment to search for words you don't know:</p> |
| 192 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 193 | %= doc_query poliqarp => loc('Q_poliqarp_seqcomplexempty', '** [orth=the][][orth=man]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 194 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 195 | <p>You are also able to mix segments and spans in sequences, for example to search for a word at the beginning of a sentence (which can be interpreted as the first word after the end of a sentence).</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 196 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 197 | %= doc_query poliqarp => loc('Q_poliqarp_seqspan', '** <base/s=s>[orth=The]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 198 | |
| 199 | <h4>Groups</h4> |
| 200 | |
| 201 | ... |
| 202 | |
| 203 | <h4>Alternation</h4> |
| 204 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 205 | <p>Alternations allow for searching alternative segments or sequences of segments, similar to the paradigmatic operator. You already have seen that you can search for a sequence with an alternative adjective in between by typing in:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 206 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 207 | %= doc_query poliqarp => loc('Q_poliqarp_seqor', '** the [orth=old | orth=young] man'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 208 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 209 | <p>However, this formulation has problems in case you want to search for alternations of sequences rather than terms. In this case you can use syntagmatic alternations and groups:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 210 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 211 | %= doc_query poliqarp => loc('Q_poliqarp_seqorgroup1', '** the (young man | old woman)'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 212 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 213 | <p>The pipe symbol works the same way as with the paradigmatic alternation, but supports sequences of different length as operands. The above query with an alternative adjective in a sequence can therefore be reformulated as:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 214 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 215 | %= doc_query poliqarp => loc('Q_poliqarp_seqorgroup2', '** the (old | young) man'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 216 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 217 | <h4 id="syntagmatic-operators-repetitions">Repetition</h4> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 218 | |
Akron | 3cfa26d | 2019-10-24 15:17:34 +0200 | [diff] [blame] | 219 | <p>Repetitions in Poliqarp are realized as in <%= embedded_link_to 'doc', 'regular expressions', 'ql', 'regexp' %>, by giving quantifieres in curly brackets.</p> |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 220 | <p>To search for a sequence of three occurrences of a defined string, you can formulate your query in any of the following ways - they will have the same results:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 221 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 222 | %= doc_query poliqarp => loc('Q_poliqarp_repmanual', '** the the the'), cutoff => 1 |
| 223 | %= doc_query poliqarp => loc('Q_poliqarp_repsimple', '** the{3}'), cutoff => 1 |
| 224 | %= doc_query poliqarp => loc('Q_poliqarp_repcomplex', '** [orth=the]{3}'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 225 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 226 | <p>In difference to regular expressions, the repetition operation won't refer to the match but to the pattern given. So the following query will give you a sequence of three words with a defined substring - but the words don't have to be identical.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 227 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 228 | %= doc_query poliqarp => loc('Q_poliqarp_repre', '** "ru.*?"/i{3}'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 229 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 230 | <p>The same is true for annotations. The following query will find a sequence of 3 to 4 adjectives in a defined context. The adjectives do not have to be identical though.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 231 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 232 | %= doc_query poliqarp => loc('Q_poliqarp_repanno', '** [base=the][tt/p=ADJA]{3,4}[tt/p=NOUN]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 233 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 234 | <p>In addition to numbered quantities, it is also possible to pass repetition information as Kleene operators <code>?</code>, <code>*</code>, and <code>+</code>.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 235 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 236 | <p>To search for a sequence with an optional segment, you can search for:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 237 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 238 | %= doc_query poliqarp => loc('Q_poliqarp_seqopt1', '** [base=the][tt/pos=ADJA]?[base=Tree]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 239 | |
| 240 | <p>This query is identical to the numbered quantification of:</p> |
| 241 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 242 | %= doc_query poliqarp => loc('Q_poliqarp_seqopt2', '** [base=the][tt/pos=ADJA]{,1}[base=Tree]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 243 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 244 | <p>To search for the same sequences but with unlimited adjectives in between, you can use the Kleene Star:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 245 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 246 | %= doc_query poliqarp => loc('Q_poliqarp_seqstar', '** [base=the][tt/pos=ADJA]*[base=Tree]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 247 | |
| 248 | <p>And to search for this sequence but with at least one adjective in between, you can use the Kleene Plus (all queries are identical):</p> |
| 249 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 250 | %= doc_query poliqarp => loc('Q_poliqarp_seqplus1', '** [base=the][tt/pos=ADJA]+[base=Tree]'), cutoff => 1 |
| 251 | %= doc_query poliqarp => loc('Q_poliqarp_seqplus2', '** [base=the][tt/pos=ADJA]{1,}[base=Tree]'), cutoff => 1 |
| 252 | %= doc_query poliqarp => loc('Q_poliqarp_seqplus3', '** [base=the][tt/pos=ADJA][tt/pos=ADJA]*[base=Tree]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 253 | |
| 254 | <blockquote class="warning"> |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 255 | <p>Repetition operators like <code>{,n}</code>, <code>?</code>, and <code>*</code> make segments or groups of segments optional. In case these queries are used separated and not as part of a sequence (and there are no mandatory segments in the query), you will be warned by the system that your query won't be treated as optional.</p> |
| 256 | <p>Keep in mind that optionality may be somehow <i>inherited</i>, for example an entire query becomes optional as soon as one segment of an alternation is optional.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 257 | </blockquote> |
| 258 | |
Akron | 3cfa26d | 2019-10-24 15:17:34 +0200 | [diff] [blame] | 259 | <p>Repetition can also be used to express distances between segments by using <%= embedded_link_to 'doc', 'empty segments', 'ql', 'poliqarp-plus#empty-segments' %>.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 260 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 261 | %= doc_query poliqarp => loc('Q_poliqarp_seqdistance1', '** [base=the][][base=Tree]'), cutoff => 1 |
| 262 | %= doc_query poliqarp => loc('Q_poliqarp_seqdistance2', '** [base=the][]{2}[base=Tree]'), cutoff => 1 |
| 263 | %= doc_query poliqarp => loc('Q_poliqarp_seqdistance3', '** [base=the][]{2,}[base=Tree]'), cutoff => 1 |
| 264 | %= doc_query poliqarp => loc('Q_poliqarp_seqdistance4', '** [base=the][]{,3}[base=Tree]'), cutoff => 1 |
| 265 | |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 266 | <p>Of course, Kleene operators can be used with empty segments as well.</p> |
| 267 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 268 | %= doc_query poliqarp => loc('Q_poliqarp_seqdistanceopt', '** [base=the][]?[base=Tree]'), cutoff => 1 |
| 269 | %= doc_query poliqarp => loc('Q_poliqarp_seqdistancestar', '** [base=the][]*[base=Tree]'), cutoff => 1 |
| 270 | %= doc_query poliqarp => loc('Q_poliqarp_seqdistanceplus', '** [base=the][]+[base=Tree]'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 271 | |
| 272 | <h4>Position</h4> |
| 273 | |
Akron | 3cfa26d | 2019-10-24 15:17:34 +0200 | [diff] [blame] | 274 | <p>Sequences as shown above can all be nested in further complex queries and treated as subqueries (see <%= embedded_link_to 'doc', 'class operators', 'ql', 'poliqarp-plus#class-operators' %> on how to later access these subqueries directly).</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 275 | <p>Positional operators compare two matches of subqueries and will match, in case a certain condition regarding the position of both is true.</p> |
| 276 | <p>The <code>contains()</code> operation will match, when a second subquery matches inside the span of a first subquery.</p> |
| 277 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 278 | %= doc_query poliqarp => loc('Q_poliqarp_poscontains', '** contains(<base/s=s>, [tt/p=KOUS])'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 279 | |
| 280 | <p>The <code>startsWith()</code> operation will match, when a second subquery matches at the beginning of the span of a first subquery.</p> |
| 281 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 282 | %= doc_query poliqarp => loc('Q_poliqarp_posstartswith', '** startsWith(<base/s=s>, [tt/p=KOUS])'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 283 | |
| 284 | <p>The <code>endsWith()</code> operation will match, when a second subquery matches at the end of the span of a first subquery.</p> |
| 285 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 286 | %= doc_query poliqarp => loc('Q_poliqarp_posendswith', '** endsWith(<base/s=s>, [opennlp/p=NN])'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 287 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 288 | <p>The <code>matches()</code> operation will match, when a second subquery has the exact same span as a first subquery.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 289 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 290 | %= doc_query poliqarp => loc('Q_poliqarp_posmatches', '** matches(<base/s=s>,[tt/p=CARD][tt/p="N.*"])'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 291 | |
| 292 | <p>The <code>overlaps()</code> operation will match, when a second subquery has an overlapping span with the first subquery.</p> |
| 293 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 294 | %= doc_query poliqarp => loc('Q_poliqarp_posoverlaps', '** overlaps([][tt/p=ADJA],{1:[tt/p=ADJA]}[])'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 295 | |
| 296 | <blockquote class="warning"> |
| 297 | <p>Positional operators are still experimental and may change in certain aspects in the future (although the behaviour defined is intended to be stable). There is also known incorrect behaviour which will be corrected in future versions.</p> |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 298 | <p>Optional operands in position operators have to be mandatory at the moment and will be reformulated to occur at least once.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 299 | <p>This behaviour may change in the future.</p> |
| 300 | </blockquote> |
| 301 | |
| 302 | <!-- |
| 303 | <blockquote> |
| 304 | <p>The KorAP implementation of Poliqarp also supports the postfix <code>within</code> operator, that works similar to the <code>contains()</code> operator, but is not nestable.</p> |
| 305 | </blockquote> |
| 306 | --> |
| 307 | |
| 308 | </section> |
| 309 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 310 | <section id="class-operators"> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 311 | <h3>Class Operators</h3> |
| 312 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 313 | <p>Classes are used to group submatches by surrounding curly brackets and a class number <code>{1:...}</code>. Classes can be used to refer to submatches in a query, similar to captures in regular expressions. In Poliqarp+ classes have multiple purposes, with highlighting being the most intuitive one:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 314 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 315 | %= doc_query poliqarp => loc('Q_poliqarp_classes', '** the {1:{2:[]} man}'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 316 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 317 | <p>In KorAP classes can be defined from 1 to 128. In case a class number is missing, the class defaults to the class number 1: <code>{...}</code> is equal to <code>{1:...}</code>.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 318 | |
| 319 | <h4>Match Modification</h4> |
| 320 | |
| 321 | <p>Based on classes, matches may be modified. The <code>focus()</code> operator restricts the span of a match to the boundary of a certain class.</p> |
| 322 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 323 | %= doc_query poliqarp => loc('Q_poliqarp_focus', '** focus(the {Tree})'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 324 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 325 | <p>The query above will search for a sequence but the match will be limited to the second segment. You can think of the first segment in this query as a <i>positive look-behind zero-length assertion</i> in regular expressions.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 326 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 327 | <p>But focus is way more useful if you are searching for matches without knowing the surface form. For example, to find all terms between defined words you can search:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 328 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 329 | %= doc_query poliqarp => loc('Q_poliqarp_focusempty', '** focus(the {[]} Tree)'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 330 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 331 | <p>Or you may want to search for all words following a known sequence immediately:</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 332 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 333 | %= doc_query poliqarp => loc('Q_poliqarp_focusextension', '** focus(the old and {[]})'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 334 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 335 | <p><code>focus()</code> is especially useful if you are searching for matches in certain areas, |
| 336 | for example in quotes using positional operators. |
| 337 | While not being interested in the whole quote as a match, you can focus on what's really relevant to you.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 338 | |
Akron | bee660d | 2018-02-14 15:57:02 +0100 | [diff] [blame] | 339 | %= doc_query poliqarp => loc('Q_poliqarp_focusrelevance', '** focus(contains(she []{,10} said, {Tree}))'), cutoff => 1 |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 340 | |
Akron | ae24e16 | 2018-02-13 18:48:44 +0100 | [diff] [blame] | 341 | <p>In case a class number is missing, the focus operator defaults to the class number 1: <code>focus(...)</code> is equal to <code>focus(1: ...)</code>.</p> |
Nils Diewald | a31a515 | 2015-04-17 21:05:23 +0000 | [diff] [blame] | 342 | |
| 343 | <blockquote class="warning"> |
| 344 | <p>As numbers in curly brackets can be ambiguous in certain circumstances, for example <code>[]{3}</code> can be read as either "any word repeated three times" or "any word followed by the number 3 highlighted as class number 1", numbers should always be expressed as <code>[orth=3]</code> for the latter case.</p> |
| 345 | </blockquote> |
| 346 | </section> |