MtasCQLParserWordFullCondition.java.html
9.28 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
<?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>MtasCQLParserWordFullCondition.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">MtasCQLParserWordFullCondition.java</span></div><h1>MtasCQLParserWordFullCondition.java</h1><pre class="source lang-java linenums">package mtas.parser.cql.util;
import mtas.parser.cql.ParseException;
import mtas.search.spans.MtasSpanMatchAllQuery;
import mtas.search.spans.MtasSpanNotQuery;
import mtas.search.spans.MtasSpanAndQuery;
import mtas.search.spans.MtasSpanOrQuery;
import mtas.search.spans.util.MtasSpanQuery;
/**
* The Class MtasCQLParserWordFullCondition.
*/
public class MtasCQLParserWordFullCondition
extends MtasCQLParserBasicSentencePartCondition {
/** The word condition. */
private MtasCQLParserWordCondition wordCondition;
/**
* Instantiates a new mtas CQL parser word full condition.
*
* @param condition the condition
*/
<span class="fc" id="L25"> public MtasCQLParserWordFullCondition(MtasCQLParserWordCondition condition) {</span>
<span class="fc" id="L26"> minimumOccurence = 1;</span>
<span class="fc" id="L27"> maximumOccurence = 1;</span>
<span class="fc" id="L28"> optional = false;</span>
<span class="fc" id="L29"> condition.simplify();</span>
<span class="pc bpc" id="L30" title="1 of 2 branches missed."> if (condition.not()) {</span>
<span class="nc" id="L31"> not = true;</span>
<span class="nc" id="L32"> condition.swapNot();</span>
} else {
<span class="fc" id="L34"> not = false;</span>
}
<span class="fc" id="L36"> wordCondition = condition;</span>
<span class="fc" id="L37"> }</span>
/**
* Gets the condition.
*
* @return the condition
*/
public MtasCQLParserWordCondition getCondition() {
<span class="fc" id="L45"> return wordCondition;</span>
}
/**
* Checks if is empty.
*
* @return true, if is empty
*/
public boolean isEmpty() {
<span class="nc" id="L54"> return wordCondition.isEmpty();</span>
}
/*
* (non-Javadoc)
*
* @see
* mtas.parser.cql.util.MtasCQLParserBasicSentencePartCondition#getQuery()
*/
@Override
public MtasSpanQuery getQuery() throws ParseException {
<span class="fc" id="L65"> MtasSpanQuery q = null;</span>
// match any word (try to avoid...)
<span class="fc bfc" id="L67" title="All 2 branches covered."> if (wordCondition.isEmpty()) {</span>
<span class="fc" id="L68"> q = new MtasSpanMatchAllQuery(wordCondition.field());</span>
// only positive queries
<span class="fc bfc" id="L70" title="All 2 branches covered."> } else if (wordCondition.isSimplePositive()) {</span>
<span class="fc bfc" id="L71" title="All 2 branches covered."> if (wordCondition.isSingle()) {</span>
<span class="fc" id="L72"> q = wordCondition.getPositiveQuery(0);</span>
} else {
<span class="fc bfc" id="L74" title="All 2 branches covered."> if (wordCondition.type().equals(MtasCQLParserWordCondition.TYPE_AND)) {</span>
<span class="fc" id="L75"> q = new MtasSpanAndQuery(wordCondition.getPositiveQuery()</span>
<span class="fc" id="L76"> .toArray(new MtasSpanQuery[wordCondition.getPositiveQuery().size()]));</span>
<span class="fc" id="L77"> } else if (wordCondition.type()</span>
<span class="pc bpc" id="L78" title="1 of 2 branches missed."> .equals(MtasCQLParserWordCondition.TYPE_OR)) {</span>
<span class="fc" id="L79"> q = new MtasSpanOrQuery(wordCondition.getPositiveQuery()</span>
<span class="fc" id="L80"> .toArray(new MtasSpanQuery[wordCondition.getPositiveQuery().size()]));</span>
} else {
<span class="nc" id="L82"> throw new ParseException("unknown type " + wordCondition.type());</span>
}
}
// only negative queries
<span class="pc bpc" id="L86" title="1 of 2 branches missed."> } else if (wordCondition.isSimpleNegative()) {</span>
<span class="nc" id="L87"> throw new ParseException("shouldn't be simple negative");</span>
// both positive and negative queries
} else {
<span class="pc bpc" id="L90" title="1 of 2 branches missed."> if (wordCondition.type().equals(MtasCQLParserWordCondition.TYPE_AND)) {</span>
MtasSpanQuery qPositive;
MtasSpanQuery qNegative;
<span class="pc bpc" id="L93" title="1 of 2 branches missed."> if (wordCondition.getPositiveQuery().size() == 1) {</span>
<span class="fc" id="L94"> qPositive = wordCondition.getPositiveQuery(0);</span>
} else {
<span class="nc" id="L96"> qPositive = new MtasSpanAndQuery(wordCondition.getPositiveQuery()</span>
<span class="nc" id="L97"> .toArray(new MtasSpanQuery[wordCondition.getPositiveQuery().size()]));</span>
}
<span class="fc bfc" id="L99" title="All 2 branches covered."> if (wordCondition.getNegativeQuery().size() == 1) {</span>
<span class="fc" id="L100"> qNegative = wordCondition.getNegativeQuery(0);</span>
} else {
<span class="fc" id="L102"> qNegative = new MtasSpanOrQuery(wordCondition.getNegativeQuery()</span>
<span class="fc" id="L103"> .toArray(new MtasSpanQuery[wordCondition.getNegativeQuery().size()]));</span>
}
<span class="fc" id="L105"> q = new MtasSpanNotQuery(qPositive, qNegative);</span>
<span class="pc" id="L106"> } else if (wordCondition.type()</span>
<span class="nc bnc" id="L107" title="All 2 branches missed."> .equals(MtasCQLParserWordCondition.TYPE_OR)) {</span>
MtasSpanQuery qPositive;
MtasSpanQuery qNegative;
<span class="nc bnc" id="L110" title="All 2 branches missed."> if (wordCondition.getPositiveQuery().size() == 1) {</span>
<span class="nc" id="L111"> qPositive = wordCondition.getPositiveQuery(0);</span>
} else {
<span class="nc" id="L113"> qPositive = new MtasSpanOrQuery(wordCondition.getPositiveQuery()</span>
<span class="nc" id="L114"> .toArray(new MtasSpanQuery[wordCondition.getPositiveQuery().size()]));</span>
}
<span class="nc bnc" id="L116" title="All 2 branches missed."> if (wordCondition.getNegativeQuery().size() == 1) {</span>
<span class="nc" id="L117"> qNegative = wordCondition.getNegativeQuery(0);</span>
} else {
<span class="nc" id="L119"> qNegative = new MtasSpanAndQuery(wordCondition.getNegativeQuery()</span>
<span class="nc" id="L120"> .toArray(new MtasSpanQuery[wordCondition.getNegativeQuery().size()]));</span>
}
<span class="nc" id="L122"> q = new MtasSpanNotQuery(qPositive, qNegative);</span>
<span class="nc" id="L123"> } else {</span>
<span class="nc" id="L124"> throw new ParseException("unknown type " + wordCondition.type());</span>
}
}
<span class="pc bpc" id="L127" title="1 of 2 branches missed."> if (not) {</span>
<span class="nc" id="L128"> MtasSpanQuery qPositive = new MtasSpanMatchAllQuery(wordCondition.field());</span>
<span class="nc" id="L129"> q = new MtasSpanNotQuery(qPositive, q);</span>
}
<span class="fc" id="L131"> return q;</span>
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object object) {
<span class="pc bpc" id="L141" title="1 of 2 branches missed."> if (object == null)</span>
<span class="nc" id="L142"> return false;</span>
<span class="fc bfc" id="L143" title="All 2 branches covered."> if (object instanceof MtasCQLParserWordFullCondition) {</span>
<span class="fc" id="L144"> MtasCQLParserWordFullCondition word = (MtasCQLParserWordFullCondition) object;</span>
<span class="fc bfc" id="L145" title="All 2 branches covered."> if (!wordCondition.equals(word.wordCondition))</span>
<span class="fc" id="L146"> return false;</span>
<span class="pc bpc" id="L147" title="1 of 2 branches missed."> if (not != word.not)</span>
<span class="nc" id="L148"> return false;</span>
<span class="fc" id="L149"> return true;</span>
} else {
<span class="fc" id="L151"> return false;</span>
}
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
<span class="nc" id="L160"> int h = this.getClass().getSimpleName().hashCode();</span>
<span class="nc" id="L161"> h = (h * 7) ^ wordCondition.hashCode();</span>
<span class="nc" id="L162"> return h;</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>