MtasCQLParserSentenceCondition.java.html
33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasCQLParserSentenceCondition.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.parser.cql.util</a> > <span class="el_source">MtasCQLParserSentenceCondition.java</span></div><h1>MtasCQLParserSentenceCondition.java</h1><pre class="source lang-java linenums">package mtas.parser.cql.util;
import java.util.ArrayList;
import java.util.List;
import mtas.parser.cql.ParseException;
import mtas.search.spans.MtasSpanOrQuery;
import mtas.search.spans.MtasSpanRecurrenceQuery;
import mtas.search.spans.MtasSpanSequenceItem;
import mtas.search.spans.MtasSpanSequenceQuery;
import mtas.search.spans.util.MtasSpanQuery;
/**
* The Class MtasCQLParserSentenceCondition.
*/
public class MtasCQLParserSentenceCondition {
/** The sequence list. */
// parent list: multiple items for OR
// child list: sequence
private List<List<MtasCQLParserSentenceCondition>> sequenceList;
/** The basic sentence. */
<span class="fc" id="L24"> private MtasCQLParserBasicSentenceCondition basicSentence = null;</span>
/** The minimum occurence. */
private int minimumOccurence;
/** The maximum occurence. */
private int maximumOccurence;
/** The basic. */
private boolean basic;
/** The simplified. */
private boolean simplified;
/** The optional. */
private boolean optional;
/** The ignore. */
private MtasSpanQuery ignore;
/** The maximum ignore length. */
private Integer maximumIgnoreLength;
/**
* Instantiates a new mtas CQL parser sentence condition.
*
* @param s the s
* @param ignore the ignore
* @param maximumIgnoreLength the maximum ignore length
* @throws ParseException the parse exception
*/
public MtasCQLParserSentenceCondition(MtasCQLParserBasicSentenceCondition s,
<span class="fc" id="L56"> MtasSpanQuery ignore, Integer maximumIgnoreLength) throws ParseException {</span>
<span class="fc" id="L57"> sequenceList = new ArrayList<List<MtasCQLParserSentenceCondition>>();</span>
<span class="fc" id="L58"> basicSentence = s;</span>
<span class="fc" id="L59"> minimumOccurence = 1;</span>
<span class="fc" id="L60"> maximumOccurence = 1;</span>
<span class="fc" id="L61"> simplified = false;</span>
<span class="fc" id="L62"> basic = true;</span>
<span class="fc" id="L63"> optional = false;</span>
<span class="fc" id="L64"> this.ignore = ignore;</span>
<span class="fc" id="L65"> this.maximumIgnoreLength = maximumIgnoreLength;</span>
<span class="fc" id="L66"> }</span>
/**
* Instantiates a new mtas CQL parser sentence condition.
*
* @param sp the sp
* @param ignore the ignore
* @param maximumIgnoreLength the maximum ignore length
* @throws ParseException the parse exception
*/
public MtasCQLParserSentenceCondition(MtasCQLParserSentenceCondition sp,
<span class="fc" id="L77"> MtasSpanQuery ignore, Integer maximumIgnoreLength) throws ParseException {</span>
<span class="fc" id="L78"> sequenceList = new ArrayList<List<MtasCQLParserSentenceCondition>>();</span>
<span class="fc" id="L79"> addSentenceToEndLatestSequence(sp);</span>
<span class="fc" id="L80"> minimumOccurence = 1;</span>
<span class="fc" id="L81"> maximumOccurence = 1;</span>
<span class="fc" id="L82"> simplified = false;</span>
<span class="fc" id="L83"> basic = false;</span>
<span class="fc" id="L84"> optional = false;</span>
<span class="fc" id="L85"> this.ignore = ignore;</span>
<span class="fc" id="L86"> this.maximumIgnoreLength = maximumIgnoreLength;</span>
<span class="fc" id="L87"> }</span>
/**
* Adds the basic sentence to end latest sequence.
*
* @param s the s
* @throws ParseException the parse exception
*/
public void addBasicSentenceToEndLatestSequence(
MtasCQLParserBasicSentenceCondition s) throws ParseException {
<span class="nc bnc" id="L97" title="All 2 branches missed."> if (!simplified) {</span>
<span class="nc bnc" id="L98" title="All 2 branches missed."> if (isBasic()) {</span>
<span class="nc bnc" id="L99" title="All 2 branches missed."> if (basicSentence == null) {</span>
<span class="nc" id="L100"> basicSentence = s;</span>
} else {
<span class="nc" id="L102"> basicSentence.addBasicSentence(s);</span>
}
} else {
<span class="nc" id="L105"> MtasCQLParserSentenceCondition sentenceCurrent = new MtasCQLParserSentenceCondition(</span>
s, ignore, maximumIgnoreLength);
<span class="nc bnc" id="L107" title="All 2 branches missed."> if (sequenceList.size() == 0) {</span>
<span class="nc" id="L108"> sequenceList.add(new ArrayList<MtasCQLParserSentenceCondition>());</span>
}
<span class="nc" id="L110"> sequenceList.get(sequenceList.size() - 1).add(sentenceCurrent);</span>
<span class="nc" id="L111"> }</span>
} else {
<span class="nc" id="L113"> throw new ParseException("already simplified");</span>
}
<span class="nc" id="L115"> }</span>
/**
* Adds the sentence to end latest sequence.
*
* @param s the s
* @throws ParseException the parse exception
*/
// public void addBasicSentenceAsOption(MtasCQLParserBasicSentenceCondition s)
// throws ParseException {
// if (!simplified) {
// MtasCQLParserSentenceCondition sentenceCurrent;
// List<MtasCQLParserSentenceCondition> sentenceSequence;
// if (isBasic()) {
// if (basicSentence == null) {
// basicSentence = s;
// } else {
// // add previous basic sentence as first option
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence,
// ignore, maximumIgnoreLength);
// sentenceSequence.add(sentenceCurrent);
// sequenceList.add(sentenceSequence);
// basicSentence = null;
// // create new option for current basic sentence
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// sentenceCurrent = new MtasCQLParserSentenceCondition(s, ignore,
// maximumIgnoreLength);
// sentenceSequence.add(sentenceCurrent);
// sequenceList.add(sentenceSequence);
// // not basic anymore
// basic = false;
// }
// } else {
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// sentenceCurrent = new MtasCQLParserSentenceCondition(s, ignore,
// maximumIgnoreLength);
// sentenceSequence.add(sentenceCurrent);
// sequenceList.add(sentenceSequence);
// }
// } else {
// throw new ParseException("already simplified");
// }
// }
/**
* Adds the sentence to start first sequence.
*
* @param s
* the s
* @throws ParseException
* the parse exception
*/
// public void addSentenceToStartFirstSequence(MtasCQLParserSentenceCondition
// s)
// throws ParseException {
// if (!simplified) {
// MtasCQLParserSentenceCondition sentenceCurrent;
// List<MtasCQLParserSentenceCondition> sentenceSequence;
// if (isBasic()) {
// if (basicSentence == null) {
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// sentenceCurrent = s;
// sentenceSequence.add(sentenceCurrent);
// sequenceList.add(sentenceSequence);
// // not basic anymore
// basic = false;
// } else {
// // add sentence as first item in new sequence
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// // add sentence to first option
// sentenceCurrent = s;
// sentenceSequence.add(sentenceCurrent);
// // add basic sentence as second item
// sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence,
// ignore, maximumIgnoreLength);
// sentenceSequence.add(sentenceCurrent);
// sequenceList.add(sentenceSequence);
// basicSentence = null;
// // not simple anymore
// basic = false;
// }
// } else {
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// sentenceSequence.add(s);
// sentenceSequence.addAll(sequenceList.get(0));
// sequenceList.set(0, sentenceSequence);
// sentenceSequence = sequenceList.get((sequenceList.size() - 1));
// sentenceCurrent = sentenceSequence.get((sentenceSequence.size() - 1));
// }
// } else {
// throw new ParseException("already simplified");
// }
// }
/**
* Adds the sentence to end latest sequence.
*
* @param s
* the s
* @throws ParseException
* the parse exception
*/
public void addSentenceToEndLatestSequence(MtasCQLParserSentenceCondition s)
throws ParseException {
<span class="pc bpc" id="L220" title="1 of 2 branches missed."> if (!simplified) {</span>
MtasCQLParserSentenceCondition sentenceCurrent;
List<MtasCQLParserSentenceCondition> sentenceSequence;
<span class="fc bfc" id="L223" title="All 2 branches covered."> if (isBasic()) {</span>
<span class="pc bpc" id="L224" title="1 of 2 branches missed."> if (basicSentence == null) {</span>
<span class="nc" id="L225"> sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();</span>
<span class="nc" id="L226"> sentenceCurrent = s;</span>
<span class="nc" id="L227"> sentenceSequence.add(sentenceCurrent);</span>
<span class="nc" id="L228"> sequenceList.add(sentenceSequence);</span>
// not simple anymore
<span class="nc" id="L230"> basic = false;</span>
} else {
// add previous basic sentence as first option
<span class="fc" id="L233"> sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();</span>
<span class="fc" id="L234"> sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence,</span>
ignore, maximumIgnoreLength);
<span class="fc" id="L236"> sentenceSequence.add(sentenceCurrent);</span>
<span class="fc" id="L237"> sequenceList.add(sentenceSequence);</span>
<span class="fc" id="L238"> basicSentence = null;</span>
// add sentence to first option
<span class="fc" id="L240"> sentenceCurrent = s;</span>
<span class="fc" id="L241"> sentenceSequence.add(sentenceCurrent);</span>
// not simple anymore
<span class="fc" id="L243"> basic = false;</span>
}
} else {
<span class="fc" id="L246"> sentenceCurrent = s;</span>
<span class="fc bfc" id="L247" title="All 2 branches covered."> if (sequenceList.size() == 0) {</span>
<span class="fc" id="L248"> sequenceList.add(new ArrayList<MtasCQLParserSentenceCondition>());</span>
}
<span class="fc" id="L250"> sequenceList.get(sequenceList.size() - 1).add(sentenceCurrent);</span>
}
<span class="fc" id="L252"> } else {</span>
<span class="nc" id="L253"> throw new ParseException("already simplified");</span>
}
<span class="fc" id="L255"> }</span>
/**
* Adds the sentence as first option.
*
* @param s the s
* @throws ParseException the parse exception
*/
public void addSentenceAsFirstOption(MtasCQLParserSentenceCondition s)
throws ParseException {
<span class="pc bpc" id="L265" title="1 of 2 branches missed."> if (!simplified) {</span>
MtasCQLParserSentenceCondition sentenceCurrent;
List<MtasCQLParserSentenceCondition> sentenceSequence;
<span class="fc bfc" id="L268" title="All 2 branches covered."> if (isBasic()) {</span>
<span class="pc bpc" id="L269" title="1 of 2 branches missed."> if (basicSentence == null) {</span>
<span class="nc" id="L270"> sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();</span>
<span class="nc" id="L271"> sentenceCurrent = s;</span>
<span class="nc" id="L272"> sentenceSequence.add(sentenceCurrent);</span>
<span class="nc" id="L273"> sequenceList.add(sentenceSequence);</span>
// not simple anymore
<span class="nc" id="L275"> basic = false;</span>
} else {
// add sentence as first option
<span class="fc" id="L278"> sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();</span>
<span class="fc" id="L279"> sentenceCurrent = s;</span>
<span class="fc" id="L280"> sentenceSequence.add(sentenceCurrent);</span>
<span class="fc" id="L281"> sequenceList.add(sentenceSequence);</span>
// add previous basic sentence as new option
<span class="fc" id="L283"> sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();</span>
<span class="fc" id="L284"> sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence,</span>
ignore, maximumIgnoreLength);
<span class="fc" id="L286"> sentenceSequence.add(sentenceCurrent);</span>
<span class="fc" id="L287"> sequenceList.add(sentenceSequence);</span>
<span class="fc" id="L288"> basicSentence = null;</span>
// not simple anymore
<span class="fc" id="L290"> basic = false;</span>
}
} else {
<span class="fc" id="L293"> sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();</span>
<span class="fc" id="L294"> sentenceCurrent = s;</span>
<span class="fc" id="L295"> sentenceSequence.add(sentenceCurrent);</span>
<span class="fc" id="L296"> List<List<MtasCQLParserSentenceCondition>> newsequenceList = new ArrayList<List<MtasCQLParserSentenceCondition>>();</span>
<span class="fc" id="L297"> newsequenceList.add(sentenceSequence);</span>
<span class="fc" id="L298"> newsequenceList.addAll(sequenceList);</span>
<span class="fc" id="L299"> sequenceList = newsequenceList;</span>
}
<span class="fc" id="L301"> } else {</span>
<span class="nc" id="L302"> throw new ParseException("already simplified");</span>
}
<span class="fc" id="L304"> }</span>
/**
* Checks if is basic.
*
* @return true, if is basic
*/
// public void addSentenceAsOption(MtasCQLParserSentenceCondition s)
// throws ParseException {
// if (!simplified) {
// MtasCQLParserSentenceCondition sentenceCurrent;
// List<MtasCQLParserSentenceCondition> sentenceSequence;
// if (isBasic()) {
// if (basicSentence == null) {
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// sentenceCurrent = s;
// sentenceSequence.add(sentenceCurrent);
// sequenceList.add(sentenceSequence);
// // not simple anymore
// basic = false;
// } else {
// // add previous basic sentence as first option
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// sentenceCurrent = new MtasCQLParserSentenceCondition(basicSentence,
// ignore, maximumIgnoreLength);
// sentenceSequence.add(sentenceCurrent);
// sequenceList.add(sentenceSequence);
// basicSentence = null;
// // add sentence as new option
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// sentenceCurrent = s;
// sentenceSequence.add(sentenceCurrent);
// sequenceList.add(sentenceSequence);
// // not simple anymore
// basic = false;
// }
// } else {
// sentenceSequence = new ArrayList<MtasCQLParserSentenceCondition>();
// sentenceCurrent = s;
// sentenceSequence.add(sentenceCurrent);
// sequenceList.add(sentenceSequence);
// }
// } else {
// throw new ParseException("already simplified");
// }
// }
/**
* Checks if is basic.
*
* @return true, if is basic
*/
private boolean isBasic() {
<span class="fc" id="L357"> return basic;</span>
}
/**
* Checks if is single.
*
* @return true, if is single
*/
private boolean isSingle() {
<span class="pc bpc" id="L366" title="1 of 4 branches missed."> return basic ? true : ((sequenceList.size() > 1) ? false : true);</span>
}
/**
* Simplify.
*
* @throws ParseException the parse exception
*/
public void simplify() throws ParseException {
<span class="fc bfc" id="L375" title="All 2 branches covered."> if (!simplified) {</span>
<span class="fc bfc" id="L376" title="All 2 branches covered."> if (!isBasic()) {</span>
<span class="fc bfc" id="L377" title="All 2 branches covered."> for (List<MtasCQLParserSentenceCondition> sequence : sequenceList) {</span>
<span class="fc" id="L378"> simplifySequence(sequence);</span>
<span class="fc" id="L379"> }</span>
// flatten
<span class="fc bfc" id="L381" title="All 2 branches covered."> if (sequenceList.size() > 1) {</span>
<span class="fc" id="L382"> List<List<MtasCQLParserSentenceCondition>> newSequenceList = new ArrayList<List<MtasCQLParserSentenceCondition>>();</span>
<span class="fc bfc" id="L383" title="All 2 branches covered."> for (List<MtasCQLParserSentenceCondition> sequence : sequenceList) {</span>
<span class="pc bpc" id="L384" title="1 of 2 branches missed."> if (sequence.size() == 1) {</span>
<span class="fc" id="L385"> MtasCQLParserSentenceCondition subSentence = sequence.get(0);</span>
<span class="fc bfc" id="L386" title="All 2 branches covered."> if (subSentence.isBasic()) {</span>
<span class="fc" id="L387"> newSequenceList.add(sequence);</span>
} else {
<span class="fc" id="L389"> newSequenceList.addAll(subSentence.sequenceList);</span>
}
}
<span class="fc" id="L392"> }</span>
<span class="fc" id="L393"> sequenceList = newSequenceList;</span>
}
}
<span class="fc" id="L396"> simplified = true;</span>
}
<span class="fc" id="L398"> }</span>
/**
* Simplify sequence.
*
* @param sequence the sequence
* @throws ParseException the parse exception
*/
private void simplifySequence(List<MtasCQLParserSentenceCondition> sequence)
throws ParseException {
<span class="fc" id="L408"> List<MtasCQLParserSentenceCondition> newSequence = new ArrayList<MtasCQLParserSentenceCondition>();</span>
<span class="fc" id="L409"> MtasCQLParserSentenceCondition lastSentence = null;</span>
<span class="fc bfc" id="L410" title="All 2 branches covered."> for (MtasCQLParserSentenceCondition sentence : sequence) {</span>
<span class="fc" id="L411"> sentence.simplify();</span>
<span class="fc bfc" id="L412" title="All 2 branches covered."> if (lastSentence == null) {</span>
<span class="fc" id="L413"> lastSentence = sentence;</span>
<span class="fc bfc" id="L414" title="All 4 branches covered."> } else if (lastSentence.isBasic() && sentence.isBasic()) {</span>
<span class="fc bfc" id="L415" title="All 4 branches covered."> if (!lastSentence.isOptional() && !sentence.isOptional()</span>
<span class="pc bpc" id="L416" title="1 of 2 branches missed."> && sentence.getMaximumOccurence() == 1</span>
<span class="pc bpc" id="L417" title="1 of 2 branches missed."> && lastSentence.getMaximumOccurence() == 1) {</span>
<span class="fc" id="L418"> lastSentence.basicSentence.addBasicSentence(sentence.basicSentence);</span>
} else {
<span class="fc" id="L420"> newSequence.add(lastSentence);</span>
<span class="fc" id="L421"> lastSentence = sentence;</span>
}
<span class="pc bpc" id="L423" title="1 of 4 branches missed."> } else if (lastSentence.isBasic() && !sentence.isBasic()) {</span>
<span class="pc bpc" id="L424" title="1 of 4 branches missed."> if (sentence.isSingle() && !sentence.isOptional()</span>
<span class="pc bpc" id="L425" title="1 of 2 branches missed."> && sentence.getMaximumOccurence() == 1</span>
<span class="pc bpc" id="L426" title="1 of 2 branches missed."> && lastSentence.getMaximumOccurence() == 1) {</span>
// add all items from (first) sequenceList potentially to the new
// sequence
for (MtasCQLParserSentenceCondition subSentence : sentence.sequenceList
<span class="fc bfc" id="L430" title="All 2 branches covered."> .get(0)) {</span>
<span class="fc" id="L431"> newSequence.add(lastSentence);</span>
<span class="fc" id="L432"> lastSentence = subSentence;</span>
<span class="fc" id="L433"> }</span>
} else {
// add sentence potentially to the new sequence
<span class="fc" id="L436"> newSequence.add(lastSentence);</span>
<span class="fc" id="L437"> lastSentence = sentence;</span>
}
<span class="pc bpc" id="L439" title="2 of 4 branches missed."> } else if (!lastSentence.isBasic() && sentence.isBasic()) {</span>
<span class="pc bpc" id="L440" title="3 of 4 branches missed."> if (lastSentence.isSingle() && !lastSentence.isOptional()</span>
<span class="nc bnc" id="L441" title="All 2 branches missed."> && sentence.getMaximumOccurence() == 1</span>
<span class="nc bnc" id="L442" title="All 2 branches missed."> && lastSentence.getMaximumOccurence() == 1) {</span>
// add basic sentence to end latest sequence
<span class="nc" id="L444"> lastSentence</span>
<span class="nc" id="L445"> .addBasicSentenceToEndLatestSequence(sentence.basicSentence);</span>
} else {
// add sentence potentially to the new sequence
<span class="fc" id="L448"> newSequence.add(lastSentence);</span>
<span class="fc" id="L449"> lastSentence = sentence;</span>
}
} else {
<span class="nc bnc" id="L452" title="All 4 branches missed."> if (sentence.isSingle() && !sentence.isOptional()</span>
<span class="nc bnc" id="L453" title="All 4 branches missed."> && lastSentence.isSingle() && !lastSentence.isOptional()</span>
<span class="nc bnc" id="L454" title="All 2 branches missed."> && sentence.getMaximumOccurence() == 1</span>
<span class="nc bnc" id="L455" title="All 2 branches missed."> && lastSentence.getMaximumOccurence() == 1) {</span>
// combine sentences
for (MtasCQLParserSentenceCondition subSentence : sentence.sequenceList
<span class="nc bnc" id="L458" title="All 2 branches missed."> .get(0)) {</span>
<span class="nc" id="L459"> lastSentence.sequenceList.get(0).add(subSentence);</span>
<span class="nc" id="L460"> }</span>
} else {
// add sentence potentially to the new sequence (both not basic)
<span class="nc" id="L463"> newSequence.add(lastSentence);</span>
<span class="nc" id="L464"> lastSentence = sentence;</span>
}
}
<span class="fc" id="L467"> }</span>
// add last to newSequence
<span class="pc bpc" id="L469" title="1 of 2 branches missed."> if (lastSentence != null) {</span>
<span class="fc" id="L470"> newSequence.add(lastSentence);</span>
}
// replace content sequence with newSequence
<span class="fc" id="L473"> sequence.clear();</span>
<span class="fc" id="L474"> sequence.addAll(newSequence);</span>
<span class="fc" id="L475"> }</span>
/**
* Gets the minimum occurence.
*
* @return the minimum occurence
*/
public int getMinimumOccurence() {
<span class="nc" id="L483"> return minimumOccurence;</span>
}
/**
* Gets the maximum occurence.
*
* @return the maximum occurence
*/
public int getMaximumOccurence() {
<span class="fc" id="L492"> return maximumOccurence;</span>
}
/**
* Sets the occurence.
*
* @param min the min
* @param max the max
* @throws ParseException the parse exception
*/
public void setOccurence(int min, int max) throws ParseException {
<span class="pc bpc" id="L503" title="3 of 6 branches missed."> if ((min < 0) || (min > max) || (max < 1)) {</span>
<span class="nc" id="L504"> throw new ParseException("Illegal number {" + min + "," + max + "}");</span>
}
<span class="pc bpc" id="L506" title="1 of 2 branches missed."> if (min == 0) {</span>
<span class="nc" id="L507"> optional = true;</span>
}
<span class="fc" id="L509"> minimumOccurence = Math.max(1, min);</span>
<span class="fc" id="L510"> maximumOccurence = max;</span>
<span class="fc" id="L511"> }</span>
/**
* Checks if is optional.
*
* @return true, if is optional
*/
public boolean isOptional() {
<span class="fc" id="L519"> return optional;</span>
}
/**
* Sets the optional.
*
* @param status the new optional
*/
// public boolean hasOptionalParts() throws ParseException {
// if (simplified) {
// return optionalParts;
// } else {
// throw new ParseException("can't be called when not simplified");
// }
// }
/**
* Sets the optional.
*
* @param status
* the new optional
*/
public void setOptional(boolean status) {
<span class="fc" id="L542"> optional = status;</span>
<span class="fc" id="L543"> }</span>
/**
* Creates the query.
*
* @param sentenceSequence the sentence sequence
* @return the mtas span query
* @throws ParseException the parse exception
*/
private MtasSpanQuery createQuery(
List<MtasCQLParserSentenceCondition> sentenceSequence)
throws ParseException {
<span class="fc bfc" id="L555" title="All 2 branches covered."> if (sentenceSequence.size() == 1) {</span>
<span class="fc bfc" id="L556" title="All 2 branches covered."> if (maximumOccurence > 1) {</span>
<span class="fc" id="L557"> return new MtasSpanRecurrenceQuery(sentenceSequence.get(0).getQuery(),</span>
minimumOccurence, maximumOccurence, ignore, maximumIgnoreLength);
} else {
<span class="fc" id="L560"> return sentenceSequence.get(0).getQuery();</span>
}
} else {
<span class="fc" id="L563"> List<MtasSpanSequenceItem> clauses = new ArrayList<MtasSpanSequenceItem>();</span>
<span class="fc bfc" id="L564" title="All 2 branches covered."> for (MtasCQLParserSentenceCondition sentence : sentenceSequence) {</span>
<span class="fc" id="L565"> clauses.add(</span>
<span class="fc" id="L566"> new MtasSpanSequenceItem(sentence.getQuery(), sentence.optional));</span>
<span class="fc" id="L567"> }</span>
<span class="pc bpc" id="L568" title="1 of 2 branches missed."> if (maximumOccurence > 1) {</span>
<span class="nc" id="L569"> return new MtasSpanRecurrenceQuery(</span>
new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength),
minimumOccurence, maximumOccurence, ignore, maximumIgnoreLength);
} else {
<span class="fc" id="L573"> return new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength);</span>
}
}
}
/**
* Gets the query.
*
* @return the query
* @throws ParseException the parse exception
*/
public MtasSpanQuery getQuery() throws ParseException {
<span class="fc" id="L585"> simplify();</span>
<span class="fc bfc" id="L586" title="All 2 branches covered."> if (isBasic()) {</span>
MtasSpanQuery query;
<span class="pc bpc" id="L588" title="1 of 2 branches missed."> if (basicSentence == null) {</span>
<span class="nc" id="L589"> throw new ParseException("no condition");</span>
<span class="pc bpc" id="L590" title="1 of 2 branches missed."> } else if (basicSentence.isOptional()) {</span>
<span class="nc" id="L591"> List<MtasSpanSequenceItem> clauses = new ArrayList<MtasSpanSequenceItem>();</span>
<span class="nc" id="L592"> clauses.add(new MtasSpanSequenceItem(basicSentence.getQuery(),</span>
<span class="nc" id="L593"> basicSentence.isOptional()));</span>
<span class="nc" id="L594"> query = new MtasSpanSequenceQuery(clauses, ignore, maximumIgnoreLength);</span>
<span class="nc bnc" id="L595" title="All 2 branches missed."> if (maximumOccurence > 1) {</span>
<span class="nc" id="L596"> query = new MtasSpanRecurrenceQuery(query, minimumOccurence,</span>
maximumOccurence, ignore, maximumIgnoreLength);
}
<span class="nc" id="L599"> } else {</span>
<span class="fc" id="L600"> query = basicSentence.getQuery();</span>
<span class="fc bfc" id="L601" title="All 2 branches covered."> if (maximumOccurence > 1) {</span>
<span class="fc" id="L602"> query = new MtasSpanRecurrenceQuery(query, minimumOccurence,</span>
maximumOccurence, ignore, maximumIgnoreLength);
}
}
<span class="fc" id="L606"> return query;</span>
<span class="pc bpc" id="L607" title="1 of 2 branches missed."> } else if (sequenceList.isEmpty()) {</span>
<span class="nc" id="L608"> throw new ParseException("no condition");</span>
<span class="fc bfc" id="L609" title="All 2 branches covered."> } else if (isSingle()) {</span>
<span class="fc" id="L610"> return createQuery(sequenceList.get(0));</span>
} else {
<span class="fc" id="L612"> List<MtasSpanQuery> clauses = new ArrayList<MtasSpanQuery>();</span>
<span class="fc bfc" id="L613" title="All 2 branches covered."> for (List<MtasCQLParserSentenceCondition> sentenceSequence : sequenceList) {</span>
<span class="fc" id="L614"> clauses.add(createQuery(sentenceSequence));</span>
<span class="fc" id="L615"> }</span>
<span class="fc" id="L616"> return new MtasSpanOrQuery(</span>
<span class="fc" id="L617"> clauses.toArray(new MtasSpanQuery[clauses.size()]));</span>
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
<span class="nc" id="L628"> return toString("", "");</span>
}
/**
* To string.
*
* @param firstIndent the first indent
* @param indent the indent
* @return the string
*/
public String toString(String firstIndent, String indent) {
<span class="nc" id="L639"> String text = "";</span>
<span class="nc bnc" id="L640" title="All 2 branches missed."> if (isBasic()) {</span>
try {
<span class="nc bnc" id="L642" title="All 2 branches missed."> text += firstIndent + "BASIC SENTENCE" + (optional ? " OPTIONAL" : "")</span>
<span class="nc" id="L643"> + ": " + basicSentence.getQuery()</span>
<span class="nc bnc" id="L644" title="All 2 branches missed."> + (basicSentence.isOptional() ? " OPTIONAL" : "") + "\n";</span>
<span class="nc" id="L645"> } catch (ParseException e) {</span>
<span class="nc bnc" id="L646" title="All 2 branches missed."> text += firstIndent + "BASIC SENTENCE" + (optional ? " OPTIONAL" : "")</span>
<span class="nc" id="L647"> + ": " + e.getMessage() + "\n";</span>
<span class="nc" id="L648"> }</span>
} else {
<span class="nc bnc" id="L650" title="All 2 branches missed."> text += firstIndent + "SENTENCE" + (optional ? " OPTIONAL" : "") + "\n";</span>
<span class="nc bnc" id="L651" title="All 2 branches missed."> if (simplified) {</span>
try {
<span class="nc" id="L653"> text += indent + "- Query: "</span>
<span class="nc" id="L654"> + getQuery().toString(getQuery().getField());</span>
<span class="nc" id="L655"> } catch (ParseException e) {</span>
<span class="nc" id="L656"> text += indent + "- Query: " + e.getMessage();</span>
<span class="nc" id="L657"> }</span>
<span class="nc" id="L658"> text += "\n";</span>
} else {
<span class="nc bnc" id="L660" title="All 2 branches missed."> for (List<MtasCQLParserSentenceCondition> sentenceSequence : sequenceList) {</span>
<span class="nc" id="L661"> text += indent + "- Sequence :\n";</span>
<span class="nc bnc" id="L662" title="All 2 branches missed."> for (MtasCQLParserSentenceCondition sentence : sentenceSequence) {</span>
<span class="nc" id="L663"> text += sentence.toString(indent + " - ", indent + " ");</span>
<span class="nc" id="L664"> }</span>
<span class="nc" id="L665"> }</span>
<span class="nc" id="L666"> text += "\n";</span>
}
}
<span class="nc" id="L669"> return text;</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>