MtasCQLParserWordFullCondition.java.html 9.54 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="L24">  public MtasCQLParserWordFullCondition(MtasCQLParserWordCondition condition) {</span>
<span class="fc" id="L25">    minimumOccurence = 1;</span>
<span class="fc" id="L26">    maximumOccurence = 1;</span>
<span class="fc" id="L27">    optional = false;</span>
<span class="fc" id="L28">    condition.simplify();</span>
<span class="pc bpc" id="L29" title="1 of 2 branches missed.">    if (condition.not()) {</span>
<span class="nc" id="L30">      not = true;</span>
<span class="nc" id="L31">      condition.swapNot();</span>
    } else {
<span class="fc" id="L33">      not = false;</span>
    }
<span class="fc" id="L35">    wordCondition = condition;</span>
<span class="fc" id="L36">  }</span>

  /**
   * Gets the condition.
   *
   * @return the condition
   */
  public MtasCQLParserWordCondition getCondition() {
<span class="fc" id="L44">    return wordCondition;</span>
  }

  /**
   * Checks if is empty.
   *
   * @return true, if is empty
   */
  public boolean isEmpty() {
<span class="nc" id="L53">    return wordCondition.isEmpty();</span>
  }

  /*
   * (non-Javadoc)
   * 
   * @see
   * mtas.parser.cql.util.MtasCQLParserBasicSentencePartCondition#getQuery()
   */
  @Override
  public MtasSpanQuery getQuery() throws ParseException {
<span class="fc" id="L64">    MtasSpanQuery q = null;</span>
    // match any word (try to avoid...)
<span class="fc bfc" id="L66" title="All 2 branches covered.">    if (wordCondition.isEmpty()) {</span>
<span class="fc" id="L67">      q = new MtasSpanMatchAllQuery(wordCondition.field());</span>
      // only positive queries
<span class="fc bfc" id="L69" title="All 2 branches covered.">    } else if (wordCondition.isSimplePositive()) {</span>
<span class="fc bfc" id="L70" title="All 2 branches covered.">      if (wordCondition.isSingle()) {</span>
<span class="fc" id="L71">        q = wordCondition.getPositiveQuery(0);</span>
      } else {
<span class="fc bfc" id="L73" title="All 2 branches covered.">        if (wordCondition.type().equals(MtasCQLParserWordCondition.TYPE_AND)) {</span>
<span class="fc" id="L74">          q = new MtasSpanAndQuery(wordCondition.getPositiveQuery().toArray(</span>
<span class="fc" id="L75">              new MtasSpanQuery[wordCondition.getPositiveQuery().size()]));</span>
<span class="fc" id="L76">        } else if (wordCondition.type()</span>
<span class="pc bpc" id="L77" title="1 of 2 branches missed.">            .equals(MtasCQLParserWordCondition.TYPE_OR)) {</span>
<span class="fc" id="L78">          q = new MtasSpanOrQuery(wordCondition.getPositiveQuery().toArray(</span>
<span class="fc" id="L79">              new MtasSpanQuery[wordCondition.getPositiveQuery().size()]));</span>
        } else {
<span class="nc" id="L81">          throw new ParseException(&quot;unknown type &quot; + wordCondition.type());</span>
        }
      }
      // only negative queries
<span class="pc bpc" id="L85" title="1 of 2 branches missed.">    } else if (wordCondition.isSimpleNegative()) {</span>
<span class="nc" id="L86">      throw new ParseException(&quot;shouldn't be simple negative&quot;);</span>
      // both positive and negative queries
    } else {
<span class="pc bpc" id="L89" title="1 of 2 branches missed.">      if (wordCondition.type().equals(MtasCQLParserWordCondition.TYPE_AND)) {</span>
        MtasSpanQuery qPositive;
        MtasSpanQuery qNegative;
<span class="pc bpc" id="L92" title="1 of 2 branches missed.">        if (wordCondition.getPositiveQuery().size() == 1) {</span>
<span class="fc" id="L93">          qPositive = wordCondition.getPositiveQuery(0);</span>
        } else {
<span class="nc" id="L95">          qPositive = new MtasSpanAndQuery(</span>
<span class="nc" id="L96">              wordCondition.getPositiveQuery().toArray(</span>
<span class="nc" id="L97">                  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(</span>
<span class="fc" id="L103">              wordCondition.getNegativeQuery().toArray(</span>
<span class="fc" id="L104">                  new MtasSpanQuery[wordCondition.getNegativeQuery().size()]));</span>
        }
<span class="fc" id="L106">        q = new MtasSpanNotQuery(qPositive, qNegative);</span>
<span class="pc" id="L107">      } else if (wordCondition.type()</span>
<span class="nc bnc" id="L108" title="All 2 branches missed.">          .equals(MtasCQLParserWordCondition.TYPE_OR)) {</span>
        MtasSpanQuery qPositive;
        MtasSpanQuery qNegative;
<span class="nc bnc" id="L111" title="All 2 branches missed.">        if (wordCondition.getPositiveQuery().size() == 1) {</span>
<span class="nc" id="L112">          qPositive = wordCondition.getPositiveQuery(0);</span>
        } else {
<span class="nc" id="L114">          qPositive = new MtasSpanOrQuery(</span>
<span class="nc" id="L115">              wordCondition.getPositiveQuery().toArray(</span>
<span class="nc" id="L116">                  new MtasSpanQuery[wordCondition.getPositiveQuery().size()]));</span>
        }
<span class="nc bnc" id="L118" title="All 2 branches missed.">        if (wordCondition.getNegativeQuery().size() == 1) {</span>
<span class="nc" id="L119">          qNegative = wordCondition.getNegativeQuery(0);</span>
        } else {
<span class="nc" id="L121">          qNegative = new MtasSpanAndQuery(</span>
<span class="nc" id="L122">              wordCondition.getNegativeQuery().toArray(</span>
<span class="nc" id="L123">                  new MtasSpanQuery[wordCondition.getNegativeQuery().size()]));</span>
        }
<span class="nc" id="L125">        q = new MtasSpanNotQuery(qPositive, qNegative);</span>
<span class="nc" id="L126">      } else {</span>
<span class="nc" id="L127">        throw new ParseException(&quot;unknown type &quot; + wordCondition.type());</span>
      }
    }
<span class="pc bpc" id="L130" title="1 of 2 branches missed.">    if (not) {</span>
<span class="nc" id="L131">      MtasSpanQuery qPositive = new MtasSpanMatchAllQuery(</span>
<span class="nc" id="L132">          wordCondition.field());</span>
<span class="nc" id="L133">      q = new MtasSpanNotQuery(qPositive, q);</span>
    }
<span class="fc" id="L135">    return q;</span>
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object object) {
<span class="pc bpc" id="L145" title="1 of 2 branches missed.">    if (object == null)</span>
<span class="nc" id="L146">      return false;</span>
<span class="fc bfc" id="L147" title="All 2 branches covered.">    if (object instanceof MtasCQLParserWordFullCondition) {</span>
<span class="fc" id="L148">      MtasCQLParserWordFullCondition word = (MtasCQLParserWordFullCondition) object;</span>
<span class="fc bfc" id="L149" title="All 2 branches covered.">      if (!wordCondition.equals(word.wordCondition))</span>
<span class="fc" id="L150">        return false;</span>
<span class="pc bpc" id="L151" title="1 of 2 branches missed.">      if (not != word.not)</span>
<span class="nc" id="L152">        return false;</span>
<span class="fc" id="L153">      return true;</span>
    } else {
<span class="fc" id="L155">      return false;</span>
    }
  }

  /*
   * (non-Javadoc)
   * 
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode() {
<span class="nc" id="L166">    int h = this.getClass().getSimpleName().hashCode();</span>
<span class="nc" id="L167">    h = (h * 7) ^ wordCondition.hashCode();</span>
<span class="nc" id="L168">    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>