MtasCQLParserSentencePartCondition.java.html 9.74 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="../.resources/report.css" type="text/css"/><link rel="shortcut icon" href="../.resources/report.gif" type="image/gif"/><title>MtasCQLParserSentencePartCondition.java</title><link rel="stylesheet" href="../.resources/prettify.css" type="text/css"/><script type="text/javascript" src="../.resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../.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">MtasCQLParserSentencePartCondition.java</span></div><h1>MtasCQLParserSentencePartCondition.java</h1><pre class="source lang-java linenums">package mtas.parser.cql.util;

import mtas.parser.cql.ParseException;
import mtas.search.spans.util.MtasSpanQuery;

/**
 * The Class MtasCQLParserSentencePartCondition.
 */
public class MtasCQLParserSentencePartCondition {

  /** The first sentence. */
<span class="fc" id="L12">  private MtasCQLParserSentenceCondition firstSentence = null;</span>

  /** The first basic sentence. */
<span class="fc" id="L15">  private MtasCQLParserBasicSentenceCondition firstBasicSentence = null;</span>

  /** The first maximum occurence. */
  private int firstMinimumOccurence, firstMaximumOccurence;

  /** The first optional. */
  private boolean firstOptional;

  /** The second sentence part. */
<span class="fc" id="L24">  MtasCQLParserSentencePartCondition secondSentencePart = null;</span>

  /** The or operator. */
<span class="fc" id="L27">  private boolean orOperator = false;</span>

  /** The full condition. */
<span class="fc" id="L30">  private MtasCQLParserSentenceCondition fullCondition = null;</span>

  private MtasSpanQuery ignoreClause;
  
  private Integer maximumIgnoreLength;
  
  /**
   * Instantiates a new mtas cql parser sentence part condition.
   *
   * @param bs
   *          the bs
   */
  public MtasCQLParserSentencePartCondition(
<span class="fc" id="L43">      MtasCQLParserBasicSentenceCondition bs, MtasSpanQuery ignore, Integer maximumIgnoreLength) {</span>
<span class="fc" id="L44">    firstMinimumOccurence = 1;</span>
<span class="fc" id="L45">    firstMaximumOccurence = 1;</span>
<span class="fc" id="L46">    firstOptional = false;</span>
<span class="fc" id="L47">    firstBasicSentence = bs;</span>
<span class="fc" id="L48">    this.ignoreClause = ignore;</span>
<span class="fc" id="L49">    this.maximumIgnoreLength = maximumIgnoreLength;</span>
<span class="fc" id="L50">  }</span>

  /**
   * Instantiates a new mtas cql parser sentence part condition.
   *
   * @param s
   *          the s
   */
<span class="fc" id="L58">  public MtasCQLParserSentencePartCondition(MtasCQLParserSentenceCondition s, MtasSpanQuery ignore, Integer maximumIgnoreLength) {</span>
<span class="fc" id="L59">    firstMinimumOccurence = 1;</span>
<span class="fc" id="L60">    firstMaximumOccurence = 1;</span>
<span class="fc" id="L61">    firstOptional = false;</span>
<span class="fc" id="L62">    firstSentence = s;</span>
<span class="fc" id="L63">    this.ignoreClause = ignore;</span>
<span class="fc" id="L64">    this.maximumIgnoreLength = maximumIgnoreLength;</span>
<span class="fc" id="L65">  }</span>

  

  /**
   * Sets the first occurence.
   *
   * @param min
   *          the min
   * @param max
   *          the max
   * @throws ParseException
   *           the parse exception
   */
  public void setFirstOccurence(int min, int max) throws ParseException {
<span class="pc bpc" id="L80" title="1 of 2 branches missed.">    if (fullCondition == null) {</span>
<span class="pc bpc" id="L81" title="3 of 6 branches missed.">      if ((min &lt; 0) || (min &gt; max) || (max &lt; 1)) {</span>
<span class="nc" id="L82">        throw new ParseException(&quot;Illegal number {&quot; + min + &quot;,&quot; + max + &quot;}&quot;);</span>
      }
<span class="fc bfc" id="L84" title="All 2 branches covered.">      if (min == 0) {</span>
<span class="fc" id="L85">        firstOptional = true;</span>
      }
<span class="fc" id="L87">      firstMinimumOccurence = Math.max(1, min);</span>
<span class="fc" id="L88">      firstMaximumOccurence = max;</span>
    } else {
<span class="nc" id="L90">      throw new ParseException(&quot;fullCondition already generated&quot;);</span>
    }
<span class="fc" id="L92">  }</span>

  /**
   * Sets the first optional.
   *
   * @param status
   *          the new first optional
   * @throws ParseException
   *           the parse exception
   */
  public void setFirstOptional(boolean status) throws ParseException {
<span class="nc bnc" id="L103" title="All 2 branches missed.">    if (fullCondition == null) {</span>
<span class="nc" id="L104">      firstOptional = status;      </span>
    } else {
<span class="nc" id="L106">      throw new ParseException(&quot;fullCondition already generated&quot;);</span>
    }
<span class="nc" id="L108">  }</span>

  /**
   * Sets the or.
   *
   * @param status
   *          the new or
   * @throws ParseException
   *           the parse exception
   */
  public void setOr(boolean status) throws ParseException {
<span class="pc bpc" id="L119" title="1 of 2 branches missed.">    if (fullCondition == null) {</span>
<span class="fc" id="L120">      orOperator = status;</span>
    } else {
<span class="nc" id="L122">      throw new ParseException(&quot;fullCondition already generated&quot;);</span>
    }
<span class="fc" id="L124">  }</span>

  /**
   * Sets the second part.
   *
   * @param sp
   *          the new second part
   * @throws ParseException
   *           the parse exception
   */
  public void setSecondPart(MtasCQLParserSentencePartCondition sp)
      throws ParseException {
<span class="pc bpc" id="L136" title="1 of 2 branches missed.">    if (fullCondition == null) {</span>
<span class="fc" id="L137">      secondSentencePart = sp;</span>
    } else {
<span class="nc" id="L139">      throw new ParseException(&quot;fullCondition already generated&quot;);</span>
    }
<span class="fc" id="L141">  }</span>

  /**
   * Creates the full sentence.
   *
   * @return the mtas cql parser sentence condition
   * @throws ParseException
   *           the parse exception
   */
  public MtasCQLParserSentenceCondition createFullSentence()
      throws ParseException {
<span class="pc bpc" id="L152" title="1 of 2 branches missed.">    if (fullCondition == null) {</span>
<span class="fc bfc" id="L153" title="All 2 branches covered.">      if (secondSentencePart == null) {</span>
<span class="fc bfc" id="L154" title="All 2 branches covered.">        if (firstBasicSentence != null) {</span>
<span class="fc" id="L155">          fullCondition = new MtasCQLParserSentenceCondition(</span>
              firstBasicSentence, ignoreClause, maximumIgnoreLength);
          
        } else {
<span class="fc" id="L159">          fullCondition = firstSentence;          </span>
        }
<span class="fc" id="L161">        fullCondition.setOccurence(firstMinimumOccurence,</span>
            firstMaximumOccurence);
<span class="fc bfc" id="L163" title="All 2 branches covered.">        if(firstOptional) {</span>
<span class="fc" id="L164">          fullCondition.setOptional(firstOptional);</span>
        }
<span class="fc" id="L166">        return fullCondition;</span>
      } else {
<span class="fc bfc" id="L168" title="All 2 branches covered.">        if (!orOperator) {</span>
<span class="fc bfc" id="L169" title="All 2 branches covered.">          if (firstBasicSentence != null) {</span>
<span class="fc" id="L170">            firstBasicSentence.setOccurence(firstMinimumOccurence,</span>
                firstMaximumOccurence);
<span class="fc" id="L172">            firstBasicSentence.setOptional(firstOptional);</span>
<span class="fc" id="L173">            fullCondition = new MtasCQLParserSentenceCondition(</span>
                firstBasicSentence, ignoreClause, maximumIgnoreLength);
          } else {
<span class="fc" id="L176">            firstSentence.setOccurence(firstMinimumOccurence,</span>
                firstMaximumOccurence);
<span class="fc" id="L178">            firstSentence.setOptional(firstOptional);</span>
<span class="fc" id="L179">            fullCondition = new MtasCQLParserSentenceCondition(firstSentence, ignoreClause, maximumIgnoreLength);</span>
          }
<span class="fc" id="L181">          fullCondition.addSentenceToEndLatestSequence(</span>
<span class="fc" id="L182">              secondSentencePart.createFullSentence());          </span>
        } else {
<span class="fc" id="L184">          MtasCQLParserSentenceCondition sentence = secondSentencePart</span>
<span class="fc" id="L185">              .createFullSentence();</span>
<span class="fc bfc" id="L186" title="All 2 branches covered.">          if (firstBasicSentence != null) {</span>
<span class="fc" id="L187">            sentence.addSentenceAsFirstOption(</span>
                new MtasCQLParserSentenceCondition(firstBasicSentence, ignoreClause, maximumIgnoreLength));
          } else {
<span class="fc" id="L190">            sentence.addSentenceAsFirstOption(firstSentence);</span>
          }
<span class="fc" id="L192">          fullCondition = sentence;</span>
        }        
<span class="fc" id="L194">        return fullCondition;</span>
      }
    } else {
<span class="nc" id="L197">      return fullCondition;</span>
    }
  }

}
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.5.201505241946</span></div></body></html>