MtasCQLParserWordFullCondition.java.html 9.28 KB
<?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> &gt; <a href="index.source.html" class="el_package">mtas.parser.cql.util</a> &gt; <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(&quot;unknown type &quot; + 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(&quot;shouldn't be simple negative&quot;);</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(&quot;unknown type &quot; + 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>